From 81fb0fda4e8e2f4a118f114f3953263279fde467 Mon Sep 17 00:00:00 2001 From: FelixKrull Date: Tue, 15 Feb 2022 12:35:51 +0100 Subject: [PATCH] Fix moving in the house --- src/main/java/Game.java | 7 +++++-- src/test/java/GameTest.java | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/Game.java b/src/main/java/Game.java index 8461484..5f7a1b1 100644 --- a/src/main/java/Game.java +++ b/src/main/java/Game.java @@ -38,6 +38,7 @@ public class Game { System.out.println("Spieler " + winner.name + " gewinnt!"); exit(42); } + TimeUnit.SECONDS.sleep(1L); clearScreen(); } } @@ -157,14 +158,16 @@ public class Game { */ public int setFigure(int figId, int dice, Player p, Game g) { int preCalculated; - if(p.figures.get(figId).getPosition() == -1) { + if (p.figures.get(figId).getPosition() == -1) { preCalculated = p.startPos; } else if (p.figures.get(figId).getPosition() <= p.jumpToHome && (p.figures.get(figId).getPosition() + dice) > p.jumpToHome) { System.out.println(p.startHome); System.out.println(dice); System.out.println(p.jumpToHome); preCalculated = p.startHome + (dice - (p.jumpToHome - p.figures.get(figId).getPosition()) - 1); - } else { + } else if (p.figures.get(figId).getPosition() >= p.startHome) { + preCalculated = p.figures.get(figId).getPosition() + dice; + }else { preCalculated = (p.figures.get(figId).getPosition() + dice) % 40; } for(Player currentPlayer : g.players) { diff --git a/src/test/java/GameTest.java b/src/test/java/GameTest.java index 2b0c43d..bf1f02b 100644 --- a/src/test/java/GameTest.java +++ b/src/test/java/GameTest.java @@ -181,7 +181,8 @@ public class GameTest { return Stream.of( Arguments.of("Figur wird auf Feld gesetzt - Niemand gekicked", 0, 4, 5, 9), Arguments.of("Figur wird auf Feld gesetzt - Jemand gekicked", 1, 4, 10, 14), - Arguments.of("Figur wird ins Haus gesetzt", 3, 4, 38, 42) + Arguments.of("Figur wird ins Haus gesetzt", 3, 4, 38, 42), + Arguments.of("Figur wird im Haus gesetzt", 3, 3, 41, 44) ); } }