From 80c8a8c0f79d22b42c7d6b1daf831930f81cf6b6 Mon Sep 17 00:00:00 2001 From: Jonas Wagner Date: Wed, 9 Feb 2022 11:37:54 +0100 Subject: [PATCH] Improve GameLoop --- src/main/java/Game.java | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/main/java/Game.java b/src/main/java/Game.java index 7168661..11069c7 100644 --- a/src/main/java/Game.java +++ b/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 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 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); + } } } }