Browse Source

Improve GameLoop

AIPlayer
Jonas Wagner 3 years ago
parent
commit
80c8a8c0f7
  1. 25
      src/main/java/Game.java

25
src/main/java/Game.java

@ -1,25 +1,40 @@
import java.util.ArrayList;
import java.util.concurrent.TimeUnit;
import static java.lang.System.exit;
public class Game {
Gameboard gb;
ArrayList<Player> players;
public static void main(String[] args) {
public static void main(String[] args) throws InterruptedException {
Game g = new Game();
Player winner;
while(true){
for (Player p : g.players) {
int c = 0;
int dice;
System.out.println("Spieler " + p.toString() + " an der Reihe.");
do {
int figId;
dice = p.rollDice();
TimeUnit.SECONDS.sleep(1L);
System.out.println("Würfel: " + dice);
c++;
ArrayList<Integer> usableFigures = g.getUsableFigures(dice, p, g);
int figId = p.choose(usableFigures);
if(usableFigures.size() > 0) {
do {
figId = p.choose(usableFigures);
} while(figId == -1);
g.setFigure(figId, dice, p, g);
}
} while (g.checkDice(dice, p, c));
p.checkGameWin(p.figures);
if(p.checkGameWin(p.figures)) {
winner = p;
System.out.println("Spieler " + winner.toString() + " gewinnt!");
exit(42);
}
}
}
}

Loading…
Cancel
Save