From 7175a51eda8ab5052cf644daed17a96f005d2179 Mon Sep 17 00:00:00 2001 From: Jonas Wagner Date: Tue, 15 Feb 2022 11:58:30 +0100 Subject: [PATCH 1/8] Fix getUsableFigures for Home --- src/main/java/Game.java | 15 ++++++++++----- src/test/java/GameTest.java | 19 ++++++++++++------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/main/java/Game.java b/src/main/java/Game.java index 9e3704a..2b4b4b7 100644 --- a/src/main/java/Game.java +++ b/src/main/java/Game.java @@ -126,7 +126,7 @@ public class Game { if(p.checkFigureInBase(p.figures) > 0 && dice == 6){ if(g.checkFieldClear(p.startPos, p, g) == 2) { - return f.getPosition() == p.startPos; //TODO Wenn Figur auf Startpos von anderer Figur blockiert ist + return f.getPosition() == p.startPos; } return f.getPosition() == -1; } else if (f.getPosition() <= p.jumpToHome && (f.getPosition() + dice) > p.jumpToHome) { @@ -135,7 +135,9 @@ public class Game { } else { return false; } - } else if(f.getPosition() != -1) { + } else if(f.getPosition() >= p.startHome && (f.getPosition() + dice) < p.startHome + 4) { + return g.checkFieldClear(f.getPosition() + dice, p, g) == 0; + } else if(f.getPosition() != -1 && f.getPosition() < 40) { return g.checkFieldClear((f.getPosition() + dice) % 40, p, g) != 2; } return false; @@ -153,19 +155,22 @@ public class Game { int preCalculated; 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 { preCalculated = (p.figures.get(figId).getPosition() + dice) % 40; } - int kicked = 0; for(Player currentPlayer : g.players) { for(Figure currentFigure : currentPlayer.figures) { if(currentFigure.getPosition() == preCalculated) { currentFigure.setPosition(-1); - kicked = 1; } } } p.figures.get(figId).setPosition(preCalculated); - return kicked; + return preCalculated; } } \ No newline at end of file diff --git a/src/test/java/GameTest.java b/src/test/java/GameTest.java index 27d63dc..2b0c43d 100644 --- a/src/test/java/GameTest.java +++ b/src/test/java/GameTest.java @@ -24,9 +24,6 @@ public class GameTest { g2 = new Game(); p2 = g2.players.get(0); - p2.figures.get(0).setPosition(5); - p2.figures.get(1).setPosition(10); - g2.players.get(3).figures.get(1).setPosition(14); } @ParameterizedTest @@ -162,21 +159,29 @@ public class GameTest { 6, Arrays.asList(-1, -1, -1, 0), new ArrayList<>(List.of(3)) + ), + Arguments.of( //Würfel 6 - 1 Figur auf dem Spielfeld - StartFeld besetzt + "Figur auf Startfeld", + 5, + Arrays.asList(-1, 41, -1, 0), + new ArrayList<>(List.of(3)) ) ); } @ParameterizedTest @MethodSource("setFigureData") - void setFigureTest(String testname, int figId, int dice, int expectedResult) { - int calculatedResult = g.setFigure(figId, dice, p2, g2); + void setFigureTest(String testname, int figId, int dice, int currentPosition, int expectedResult) { + p2.figures.get(figId).setPosition(currentPosition); + int calculatedResult = g2.setFigure(figId, dice, p2, g2); assertThat(calculatedResult).describedAs(testname).isEqualTo(expectedResult); } static Stream setFigureData () { return Stream.of( - Arguments.of("Figur wird auf Feld gesetzt - Niemand gekicked", 0, 4, 0), - Arguments.of("Figur wird auf Feld gesetzt - Jemand gekicked", 1, 4, 1) + 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) ); } } From 404260a23391f4d1ad8a1ac4b8405e93f4e93073 Mon Sep 17 00:00:00 2001 From: Jonas Wagner Date: Tue, 15 Feb 2022 12:05:19 +0100 Subject: [PATCH 2/8] Fix Gameboard in Gameloop --- src/main/java/Game.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/Game.java b/src/main/java/Game.java index 2b4b4b7..b9615d1 100644 --- a/src/main/java/Game.java +++ b/src/main/java/Game.java @@ -15,7 +15,7 @@ public class Game { for (Player p : g.players) { 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(); @@ -28,6 +28,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)) { @@ -35,6 +37,7 @@ public class Game { System.out.println("Spieler " + winner.name + " gewinnt!"); exit(42); } + clearScreen(); } } } From 975909dacba9efcac10e942372e059ec2fd08fc4 Mon Sep 17 00:00:00 2001 From: Jonas Wagner Date: Tue, 15 Feb 2022 12:06:37 +0100 Subject: [PATCH 3/8] Add clearScreen at beginning --- src/main/java/Game.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/Game.java b/src/main/java/Game.java index b9615d1..8461484 100644 --- a/src/main/java/Game.java +++ b/src/main/java/Game.java @@ -11,6 +11,7 @@ public class Game { public static void main(String[] args) throws InterruptedException { Game g = new Game(); Player winner; + clearScreen(); while(true){ for (Player p : g.players) { int c = 0; From cc248b514ac464762dddf8b6a551cf28d64fb64d Mon Sep 17 00:00:00 2001 From: Jonas Wagner Date: Tue, 15 Feb 2022 12:23:00 +0100 Subject: [PATCH 4/8] Add 1 Second Delay when Player swap --- src/main/java/Game.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/Game.java b/src/main/java/Game.java index 8461484..55f103b 100644 --- a/src/main/java/Game.java +++ b/src/main/java/Game.java @@ -39,6 +39,7 @@ public class Game { exit(42); } clearScreen(); + TimeUnit.SECONDS.sleep(1L); } } } From 81fb0fda4e8e2f4a118f114f3953263279fde467 Mon Sep 17 00:00:00 2001 From: FelixKrull Date: Tue, 15 Feb 2022 12:35:51 +0100 Subject: [PATCH 5/8] 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) ); } } From f8c9d023e021769912f095ba0b7e82e8b79bc40f Mon Sep 17 00:00:00 2001 From: FelixKrull Date: Tue, 15 Feb 2022 12:36:41 +0100 Subject: [PATCH 6/8] Fix Gametest for only 3 dice rolls --- src/test/java/GameTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/GameTest.java b/src/test/java/GameTest.java index bf1f02b..2ccc2e4 100644 --- a/src/test/java/GameTest.java +++ b/src/test/java/GameTest.java @@ -56,7 +56,7 @@ public class GameTest { Arrays.asList(-1, -1, -1, -1), 1, 3, - true + false ), Arguments.of("No figures on Field - d: 1 - c: 4", Arrays.asList(-1, -1, -1, -1), From 54b65e717e21ac8a0847a38e0c90fb88dfbb21fa Mon Sep 17 00:00:00 2001 From: FelixKrull Date: Tue, 15 Feb 2022 12:39:45 +0100 Subject: [PATCH 7/8] Remove sout's --- src/main/java/Game.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/java/Game.java b/src/main/java/Game.java index 07267a3..c920527 100644 --- a/src/main/java/Game.java +++ b/src/main/java/Game.java @@ -162,9 +162,6 @@ public class Game { 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 if (p.figures.get(figId).getPosition() >= p.startHome) { preCalculated = p.figures.get(figId).getPosition() + dice; From 8aceb8574cf75258271781d66af15c2f0f5976a5 Mon Sep 17 00:00:00 2001 From: FelixKrull Date: Tue, 15 Feb 2022 12:41:04 +0100 Subject: [PATCH 8/8] Remove double sleep --- src/main/java/Game.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/Game.java b/src/main/java/Game.java index c920527..67b85a8 100644 --- a/src/main/java/Game.java +++ b/src/main/java/Game.java @@ -40,7 +40,6 @@ public class Game { } TimeUnit.SECONDS.sleep(1L); clearScreen(); - TimeUnit.SECONDS.sleep(1L); } } }