From 2f8f41b04b230d327ec7caf65c88335579f9110b Mon Sep 17 00:00:00 2001 From: FelixKrull Date: Tue, 15 Feb 2022 10:41:45 +0100 Subject: [PATCH] Implement printGameboard into Gameloop --- src/main/java/Game.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/main/java/Game.java b/src/main/java/Game.java index 80abd17..3ebb4cb 100644 --- a/src/main/java/Game.java +++ b/src/main/java/Game.java @@ -1,8 +1,10 @@ +import java.io.IOException; import java.util.ArrayList; import java.util.concurrent.TimeUnit; import static java.lang.System.exit; + public class Game { Gameboard gb; @@ -13,10 +15,9 @@ public class Game { Player winner; while(true){ for (Player p : g.players) { - System.out.println(g.toString()); int c = 0; int dice; - System.out.println("Spieler " + p.name + " an der Reihe."); + System.out.println(g.printGameboard(g,p)); do { int figId; dice = p.rollDice(); @@ -29,6 +30,8 @@ public class Game { figId = p.choose(usableFigures); } while(figId == -1); g.setFigure(figId, dice, p, g); + clearScreen(); + System.out.println(g.printGameboard(g,p)); } } while (g.checkDice(dice, p, c)); if(p.checkGameWin(p.figures)) { @@ -36,7 +39,7 @@ public class Game { System.out.println("Spieler " + winner.name + " gewinnt!"); exit(42); } - //clear; + clearScreen(); } } } @@ -51,9 +54,13 @@ public class Game { 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) {