|
@ -11,11 +11,12 @@ public class Game { |
|
|
public static void main(String[] args) throws InterruptedException { |
|
|
public static void main(String[] args) throws InterruptedException { |
|
|
Game g = new Game(); |
|
|
Game g = new Game(); |
|
|
Player winner; |
|
|
Player winner; |
|
|
|
|
|
clearScreen(); |
|
|
while(true){ |
|
|
while(true){ |
|
|
for (Player p : g.players) { |
|
|
for (Player p : g.players) { |
|
|
int c = 0; |
|
|
int c = 0; |
|
|
int dice; |
|
|
int dice; |
|
|
System.out.println("Spieler " + p.name + " an der Reihe."); |
|
|
|
|
|
|
|
|
System.out.println(g.printGameboard(g, p)); |
|
|
do { |
|
|
do { |
|
|
int figId; |
|
|
int figId; |
|
|
dice = p.rollDice(); |
|
|
dice = p.rollDice(); |
|
@ -28,6 +29,8 @@ public class Game { |
|
|
figId = p.choose(usableFigures); |
|
|
figId = p.choose(usableFigures); |
|
|
} while(figId == -1); |
|
|
} while(figId == -1); |
|
|
g.setFigure(figId, dice, p, g); |
|
|
g.setFigure(figId, dice, p, g); |
|
|
|
|
|
clearScreen(); |
|
|
|
|
|
System.out.println(g.printGameboard(g, p)); |
|
|
} |
|
|
} |
|
|
} while (g.checkDice(dice, p, c)); |
|
|
} while (g.checkDice(dice, p, c)); |
|
|
if(p.checkGameWin(p.figures)) { |
|
|
if(p.checkGameWin(p.figures)) { |
|
@ -35,6 +38,8 @@ public class Game { |
|
|
System.out.println("Spieler " + winner.name + " gewinnt!"); |
|
|
System.out.println("Spieler " + winner.name + " gewinnt!"); |
|
|
exit(42); |
|
|
exit(42); |
|
|
} |
|
|
} |
|
|
|
|
|
TimeUnit.SECONDS.sleep(1L); |
|
|
|
|
|
clearScreen(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@ -126,7 +131,7 @@ public class Game { |
|
|
|
|
|
|
|
|
if(p.checkFigureInBase(p.figures) > 0 && dice == 6){ |
|
|
if(p.checkFigureInBase(p.figures) > 0 && dice == 6){ |
|
|
if(g.checkFieldClear(p.startPos, p, g) == 2) { |
|
|
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; |
|
|
return f.getPosition() == -1; |
|
|
} else if (f.getPosition() <= p.jumpToHome && (f.getPosition() + dice) > p.jumpToHome) { |
|
|
} else if (f.getPosition() <= p.jumpToHome && (f.getPosition() + dice) > p.jumpToHome) { |
|
@ -135,7 +140,9 @@ public class Game { |
|
|
} else { |
|
|
} else { |
|
|
return false; |
|
|
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 g.checkFieldClear((f.getPosition() + dice) % 40, p, g) != 2; |
|
|
} |
|
|
} |
|
|
return false; |
|
|
return false; |
|
@ -153,19 +160,21 @@ public class Game { |
|
|
int preCalculated; |
|
|
int preCalculated; |
|
|
if (p.figures.get(figId).getPosition() == -1) { |
|
|
if (p.figures.get(figId).getPosition() == -1) { |
|
|
preCalculated = p.startPos; |
|
|
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 { |
|
|
}else { |
|
|
preCalculated = (p.figures.get(figId).getPosition() + dice) % 40; |
|
|
preCalculated = (p.figures.get(figId).getPosition() + dice) % 40; |
|
|
} |
|
|
} |
|
|
int kicked = 0; |
|
|
|
|
|
for(Player currentPlayer : g.players) { |
|
|
for(Player currentPlayer : g.players) { |
|
|
for(Figure currentFigure : currentPlayer.figures) { |
|
|
for(Figure currentFigure : currentPlayer.figures) { |
|
|
if(currentFigure.getPosition() == preCalculated) { |
|
|
if(currentFigure.getPosition() == preCalculated) { |
|
|
currentFigure.setPosition(-1); |
|
|
currentFigure.setPosition(-1); |
|
|
kicked = 1; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
p.figures.get(figId).setPosition(preCalculated); |
|
|
p.figures.get(figId).setPosition(preCalculated); |
|
|
return kicked; |
|
|
|
|
|
|
|
|
return preCalculated; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |