|
@ -15,12 +15,14 @@ public class Game { |
|
|
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."); |
|
|
|
|
|
do { |
|
|
do { |
|
|
|
|
|
clearScreen(); |
|
|
int figId; |
|
|
int figId; |
|
|
dice = p.rollDice(); |
|
|
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); |
|
|
System.out.println("Würfel: "+ dice); |
|
|
|
|
|
TimeUnit.MILLISECONDS.sleep(600L); |
|
|
c++; |
|
|
c++; |
|
|
ArrayList<Integer> usableFigures = g.getUsableFigures(dice, p, g); |
|
|
ArrayList<Integer> usableFigures = g.getUsableFigures(dice, p, g); |
|
|
if(usableFigures.size() > 0) { |
|
|
if(usableFigures.size() > 0) { |
|
@ -28,6 +30,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,dice)); |
|
|
} |
|
|
} |
|
|
} while (g.checkDice(dice, p, c)); |
|
|
} while (g.checkDice(dice, p, c)); |
|
|
if(p.checkGameWin(p.figures)) { |
|
|
if(p.checkGameWin(p.figures)) { |
|
@ -49,8 +53,8 @@ public class Game { |
|
|
players.add(new Player("Grün",30, 52, 29)); |
|
|
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() { |
|
|
public static void clearScreen() { |
|
@ -66,8 +70,14 @@ public class Game { |
|
|
* @return true if Player can roll the dice another time |
|
|
* @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) { |
|
|
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; |
|
|
return countRolls < 3; |
|
|
} else return dice == 6; |
|
|
} else return dice == 6; |
|
|
} |
|
|
} |
|
@ -126,7 +136,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 +145,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 +165,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; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |