|
|
@ -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,8 +30,10 @@ 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)); |
|
|
|
} while (g.checkDice(dice, p, c, g)); |
|
|
|
if(p.checkGameWin(p.figures)) { |
|
|
|
winner = p; |
|
|
|
System.out.println("Spieler " + winner.name + " gewinnt!"); |
|
|
@ -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() { |
|
|
@ -63,12 +67,21 @@ public class Game { |
|
|
|
* @param dice Value of dice got from rolldice() |
|
|
|
* @param p active Player |
|
|
|
* @param countRolls Counter how often the Player already rolled the dice |
|
|
|
* @param g game instance |
|
|
|
* @return true if Player can roll the dice another time |
|
|
|
*/ |
|
|
|
public boolean checkDice(int dice, Player p, int countRolls) { |
|
|
|
public boolean checkDice(int dice, Player p, int countRolls, Game g) { |
|
|
|
int figuresInBase = p.checkFigureInBase(p.figures); |
|
|
|
if(countRolls >= 3) return dice == 6; |
|
|
|
if(figuresInBase == 4) { |
|
|
|
return countRolls < 3; |
|
|
|
return true; |
|
|
|
} else if (figuresInBase < 4) { |
|
|
|
for(int i = 0; i < 4 - figuresInBase; i++) { |
|
|
|
if(checkFieldClear(p.startHome+3-i,p,g) == 0) { |
|
|
|
return dice == 6; |
|
|
|
} |
|
|
|
} |
|
|
|
return true; |
|
|
|
} else return dice == 6; |
|
|
|
} |
|
|
|
|
|
|
@ -126,7 +139,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 +148,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 +168,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; |
|
|
|
} |
|
|
|
} |