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.ArrayList;
import java.util.concurrent.TimeUnit;
import static java.lang.System.exit;
public class Game { public class Game {
Gameboard gb; Gameboard gb;
ArrayList<Player> players; ArrayList<Player> players;
public static void main(String[] args) {
public static void main(String[] args) throws InterruptedException {
Game g = new Game(); Game g = new Game();
Player winner;
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.toString() + " an der Reihe.");
do { do {
int figId;
dice = p.rollDice(); dice = p.rollDice();
TimeUnit.SECONDS.sleep(1L);
System.out.println("Würfel: " + dice);
c++; c++;
ArrayList<Integer> usableFigures = g.getUsableFigures(dice, p, g); 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)); } 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