From e06cc3a7a3b9f70070d008ac63ce1241c644b7bd Mon Sep 17 00:00:00 2001 From: Jonas Wagner Date: Wed, 9 Feb 2022 11:19:12 +0100 Subject: [PATCH] Implement setFigure method --- src/main/java/Game.java | 15 +++++++++++++++ src/test/java/GameTest.java | 22 ++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/src/main/java/Game.java b/src/main/java/Game.java index 89ac454..7168661 100644 --- a/src/main/java/Game.java +++ b/src/main/java/Game.java @@ -87,4 +87,19 @@ public class Game { } return false; } + + public int setFigure(int figId, int dice, Player p, Game g) { + int 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; + } } \ No newline at end of file diff --git a/src/test/java/GameTest.java b/src/test/java/GameTest.java index c8523f1..e389c57 100644 --- a/src/test/java/GameTest.java +++ b/src/test/java/GameTest.java @@ -13,12 +13,20 @@ public class GameTest { private Game g; private Player p1; + private Game g2; + private Player p2; @BeforeEach void setup() { g = new Game(); p1 = g.players.get(0); + + 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 @@ -151,6 +159,20 @@ public class GameTest { ) ); } + + @ParameterizedTest + @MethodSource("setFigureData") + void setFigureTest(String testname, int figId, int dice, int expectedResult) { + int calculatedResult = g.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) + ); + } }