Browse Source

Implement printGameboard into Gameloop

AIPlayer
FelixKrull 2 years ago
parent
commit
2f8f41b04b
  1. 19
      src/main/java/Game.java

19
src/main/java/Game.java

@ -1,8 +1,10 @@
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import static java.lang.System.exit; import static java.lang.System.exit;
public class Game { public class Game {
Gameboard gb; Gameboard gb;
@ -13,10 +15,9 @@ public class Game {
Player winner; Player winner;
while(true){ while(true){
for (Player p : g.players) { for (Player p : g.players) {
System.out.println(g.toString());
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();
@ -29,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));
} }
} while (g.checkDice(dice, p, c)); } while (g.checkDice(dice, p, c));
if(p.checkGameWin(p.figures)) { if(p.checkGameWin(p.figures)) {
@ -36,7 +39,7 @@ public class Game {
System.out.println("Spieler " + winner.name + " gewinnt!"); System.out.println("Spieler " + winner.name + " gewinnt!");
exit(42); exit(42);
} }
//clear;
clearScreen();
} }
} }
} }
@ -51,9 +54,13 @@ public class Game {
players.add(new Player("Grün",30, 52, 29)); players.add(new Player("Grün",30, 52, 29));
} }
@Override
public String toString() {
return gb.toString();
public String printGameboard(Game g, Player p) {
return gb.printBoard(g, p);
}
public static void clearScreen() {
System.out.print("\033[H\033[2J");
System.out.flush();
} }
public boolean checkDice(int dice, Player p, int countRolls) { public boolean checkDice(int dice, Player p, int countRolls) {

Loading…
Cancel
Save