From 2e08539e68397b558764c424e559d89044bc06cc Mon Sep 17 00:00:00 2001 From: Jonas Wagner Date: Tue, 18 Jan 2022 09:57:48 +0100 Subject: [PATCH 1/2] Refactor startGame Method --- src/main/java/Game.java | 17 ++++++++++++++++- src/test/java/GameTest.java | 16 ++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/main/java/Game.java b/src/main/java/Game.java index 03be2ad..da68c76 100644 --- a/src/main/java/Game.java +++ b/src/main/java/Game.java @@ -1,7 +1,22 @@ public class Game { + Gameboard gb; + Player p1; + Player p2; + Player p3; + Player p4; + public static void main(String[] args) { - Gameboard gb = new Gameboard(); + Game g = new Game(); + g.startGame(); + } + + public void startGame() { + this.gb = new Gameboard(); gb.initGameboard(); + p1 = new Player("Rot"); + p2 = new Player("Blau"); + p3 = new Player("Gelb"); + p4 = new Player("Grün"); } } diff --git a/src/test/java/GameTest.java b/src/test/java/GameTest.java index f389fff..122fbe6 100644 --- a/src/test/java/GameTest.java +++ b/src/test/java/GameTest.java @@ -8,4 +8,20 @@ import org.junit.jupiter.params.provider.MethodSource; public class GameTest { + private Gameboard gb; + private Player p1; + private Player p2; + private Player p3; + private Player p4; + + @BeforeEach + void setup() { + this.gb = new Gameboard(); + gb.initGameboard(); + p1 = new Player("Rot"); + p2 = new Player("Blau"); + p3 = new Player("Gelb"); + p4 = new Player("Grün"); + } + } From 3ff0419cbf2b26616966abdea3f3e9a3d9a40bcf Mon Sep 17 00:00:00 2001 From: Jonas Wagner Date: Tue, 18 Jan 2022 10:20:08 +0100 Subject: [PATCH 2/2] Add Figure.java and implement it in Player.java --- src/main/java/Figure.java | 9 +++++++++ src/main/java/Player.java | 8 ++++++++ src/test/java/PlayerTest.java | 13 +++++++++++++ 3 files changed, 30 insertions(+) create mode 100644 src/main/java/Figure.java diff --git a/src/main/java/Figure.java b/src/main/java/Figure.java new file mode 100644 index 0000000..8cf72b9 --- /dev/null +++ b/src/main/java/Figure.java @@ -0,0 +1,9 @@ +public class Figure { + + int position; + + public Figure() { + this.position = -1; + } + +} diff --git a/src/main/java/Player.java b/src/main/java/Player.java index 6cba702..1a15314 100644 --- a/src/main/java/Player.java +++ b/src/main/java/Player.java @@ -1,9 +1,17 @@ +import javax.sound.midi.Soundbank; +import java.util.Arrays; + public class Player { String name; + Figure[] figures; public Player (String name) { this.name = name; + figures = new Figure[4]; + for(int i = 0; i < 4; i++) { + this.figures[i] = new Figure(); + } } @Override diff --git a/src/test/java/PlayerTest.java b/src/test/java/PlayerTest.java index 86faf07..5000e0b 100644 --- a/src/test/java/PlayerTest.java +++ b/src/test/java/PlayerTest.java @@ -29,5 +29,18 @@ public class PlayerTest { assertThat(calculatedResult).describedAs("Player Name").isEqualTo(expectedResult); } + @Test + void checkStartPositionOfFigures() { + int expectedResult = -1; + int calculatedResult = p.figures[0].position; + for(int i = 0; i < 4; i++) { + calculatedResult = p.figures[i].position; + if(expectedResult != calculatedResult) { + calculatedResult = 1; + break; + } + } + assertThat(calculatedResult).describedAs("Starting postion of Figures").isEqualTo(expectedResult); + } }