|
|
@ -15,12 +15,14 @@ public class Game { |
|
|
|
for (Player p : g.players) { |
|
|
|
int c = 0; |
|
|
|
int dice; |
|
|
|
System.out.println("Spieler " + p.name + " an der Reihe."); |
|
|
|
do { |
|
|
|
clearScreen(); |
|
|
|
int figId; |
|
|
|
dice = p.rollDice(); |
|
|
|
TimeUnit.SECONDS.sleep(1L); |
|
|
|
System.out.println(g.printGameboard(g,p,dice)); |
|
|
|
TimeUnit.MILLISECONDS.sleep(600L); |
|
|
|
System.out.println("Würfel: "+ dice); |
|
|
|
TimeUnit.MILLISECONDS.sleep(600L); |
|
|
|
c++; |
|
|
|
ArrayList<Integer> usableFigures = g.getUsableFigures(dice, p, g); |
|
|
|
if(usableFigures.size() > 0) { |
|
|
@ -28,6 +30,8 @@ public class Game { |
|
|
|
figId = p.choose(usableFigures); |
|
|
|
} while(figId == -1); |
|
|
|
g.setFigure(figId, dice, p, g); |
|
|
|
clearScreen(); |
|
|
|
System.out.println(g.printGameboard(g,p,dice)); |
|
|
|
} |
|
|
|
} while (g.checkDice(dice, p, c)); |
|
|
|
if(p.checkGameWin(p.figures)) { |
|
|
@ -49,8 +53,8 @@ public class Game { |
|
|
|
players.add(new Player("Grün",30, 52, 29)); |
|
|
|
} |
|
|
|
|
|
|
|
public String printGameboard(Game g, Player p) { |
|
|
|
return gb.printBoard(g, p); |
|
|
|
public String printGameboard(Game g, Player p, int dice) { |
|
|
|
return gb.printBoard(g, p, dice); |
|
|
|
} |
|
|
|
|
|
|
|
public static void clearScreen() { |
|
|
@ -66,8 +70,14 @@ public class Game { |
|
|
|
* @return true if Player can roll the dice another time |
|
|
|
*/ |
|
|
|
public boolean checkDice(int dice, Player p, int countRolls) { |
|
|
|
int figuresInBase = p.checkFigureInBase(p.figures); |
|
|
|
if(figuresInBase == 4) { |
|
|
|
boolean figuresOnBoard = false; |
|
|
|
for(Figure f : p.figures) { |
|
|
|
if (f.getPosition() > -1 && f.getPosition() < 40) { |
|
|
|
figuresOnBoard = true; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
if(!figuresOnBoard) { |
|
|
|
return countRolls < 3; |
|
|
|
} else return dice == 6; |
|
|
|
} |
|
|
@ -126,7 +136,7 @@ public class Game { |
|
|
|
|
|
|
|
if(p.checkFigureInBase(p.figures) > 0 && dice == 6){ |
|
|
|
if(g.checkFieldClear(p.startPos, p, g) == 2) { |
|
|
|
return f.getPosition() == p.startPos; //TODO Wenn Figur auf Startpos von anderer Figur blockiert ist |
|
|
|
return f.getPosition() == p.startPos; |
|
|
|
} |
|
|
|
return f.getPosition() == -1; |
|
|
|
} else if (f.getPosition() <= p.jumpToHome && (f.getPosition() + dice) > p.jumpToHome) { |
|
|
@ -135,7 +145,9 @@ public class Game { |
|
|
|
} else { |
|
|
|
return false; |
|
|
|
} |
|
|
|
} else if(f.getPosition() != -1) { |
|
|
|
} else if(f.getPosition() >= p.startHome && (f.getPosition() + dice) < p.startHome + 4) { |
|
|
|
return g.checkFieldClear(f.getPosition() + dice, p, g) == 0; |
|
|
|
} else if(f.getPosition() != -1 && f.getPosition() < 40) { |
|
|
|
return g.checkFieldClear((f.getPosition() + dice) % 40, p, g) != 2; |
|
|
|
} |
|
|
|
return false; |
|
|
@ -153,19 +165,21 @@ public class Game { |
|
|
|
int preCalculated; |
|
|
|
if (p.figures.get(figId).getPosition() == -1) { |
|
|
|
preCalculated = p.startPos; |
|
|
|
} else if (p.figures.get(figId).getPosition() <= p.jumpToHome && (p.figures.get(figId).getPosition() + dice) > p.jumpToHome) { |
|
|
|
preCalculated = p.startHome + (dice - (p.jumpToHome - p.figures.get(figId).getPosition()) - 1); |
|
|
|
} else if (p.figures.get(figId).getPosition() >= p.startHome) { |
|
|
|
preCalculated = p.figures.get(figId).getPosition() + dice; |
|
|
|
}else { |
|
|
|
preCalculated = (p.figures.get(figId).getPosition() + dice) % 40; |
|
|
|
} |
|
|
|
int kicked = 0; |
|
|
|
for(Player currentPlayer : g.players) { |
|
|
|
for(Figure currentFigure : currentPlayer.figures) { |
|
|
|
if(currentFigure.getPosition() == preCalculated) { |
|
|
|
currentFigure.setPosition(-1); |
|
|
|
kicked = 1; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
p.figures.get(figId).setPosition(preCalculated); |
|
|
|
return kicked; |
|
|
|
return preCalculated; |
|
|
|
} |
|
|
|
} |