From 8f317456a28859e773d586b047fb35854cc527c0 Mon Sep 17 00:00:00 2001 From: FelixKrull Date: Tue, 18 Jan 2022 09:15:51 +0100 Subject: [PATCH 1/6] Init Game Class --- src/main/java/Game.java | 7 +++++++ src/test/java/GameTest.java | 11 +++++++++++ 2 files changed, 18 insertions(+) create mode 100644 src/main/java/Game.java create mode 100644 src/test/java/GameTest.java diff --git a/src/main/java/Game.java b/src/main/java/Game.java new file mode 100644 index 0000000..03be2ad --- /dev/null +++ b/src/main/java/Game.java @@ -0,0 +1,7 @@ +public class Game { + + public static void main(String[] args) { + Gameboard gb = new Gameboard(); + gb.initGameboard(); + } +} diff --git a/src/test/java/GameTest.java b/src/test/java/GameTest.java new file mode 100644 index 0000000..f389fff --- /dev/null +++ b/src/test/java/GameTest.java @@ -0,0 +1,11 @@ +import static org.assertj.core.api.Assertions.*; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +public class GameTest { + +} From 13f8e09b28aaa5a62e90f1c4b173a112c0002faa Mon Sep 17 00:00:00 2001 From: FelixKrull Date: Tue, 18 Jan 2022 09:30:49 +0100 Subject: [PATCH 2/6] Add rollDice --- src/main/java/Player.java | 5 +++++ src/test/java/PlayerTest.java | 28 ++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 src/main/java/Player.java create mode 100644 src/test/java/PlayerTest.java diff --git a/src/main/java/Player.java b/src/main/java/Player.java new file mode 100644 index 0000000..57920b0 --- /dev/null +++ b/src/main/java/Player.java @@ -0,0 +1,5 @@ +public class Player { + public int rollDice() { + return (int) (Math.random() * 6); + } +} diff --git a/src/test/java/PlayerTest.java b/src/test/java/PlayerTest.java new file mode 100644 index 0000000..1dfa925 --- /dev/null +++ b/src/test/java/PlayerTest.java @@ -0,0 +1,28 @@ +import static org.assertj.core.api.Assertions.*; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +public class PlayerTest { + + private Player p; + + @BeforeEach + void setup() { + p = new Player(); + } + + @Test + void testDice() { + int calculatedResult = p.rollDice(); + assertThat(calculatedResult).describedAs("Dice result").isBetween(1,6); + } + + + + +} From c6298b001b3f38b716e0b4223a99cdcee1d948bc Mon Sep 17 00:00:00 2001 From: FelixKrull Date: Tue, 18 Jan 2022 09:41:28 +0100 Subject: [PATCH 3/6] Add toString --- src/main/java/Player.java | 12 ++++++++++++ src/test/java/PlayerTest.java | 9 +++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/main/java/Player.java b/src/main/java/Player.java index 57920b0..6cba702 100644 --- a/src/main/java/Player.java +++ b/src/main/java/Player.java @@ -1,4 +1,16 @@ public class Player { + + String name; + + public Player (String name) { + this.name = name; + } + + @Override + public String toString() { + return name; + } + public int rollDice() { return (int) (Math.random() * 6); } diff --git a/src/test/java/PlayerTest.java b/src/test/java/PlayerTest.java index 1dfa925..86faf07 100644 --- a/src/test/java/PlayerTest.java +++ b/src/test/java/PlayerTest.java @@ -13,7 +13,7 @@ public class PlayerTest { @BeforeEach void setup() { - p = new Player(); + p = new Player("Rot"); } @Test @@ -22,7 +22,12 @@ public class PlayerTest { assertThat(calculatedResult).describedAs("Dice result").isBetween(1,6); } - + @Test + void testToString() { + String expectedResult = "Rot"; + String calculatedResult = p.toString(); + assertThat(calculatedResult).describedAs("Player Name").isEqualTo(expectedResult); + } } From 2e08539e68397b558764c424e559d89044bc06cc Mon Sep 17 00:00:00 2001 From: Jonas Wagner Date: Tue, 18 Jan 2022 09:57:48 +0100 Subject: [PATCH 4/6] 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 5/6] 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); + } } From beeaf8540bd0fca5ec3c4e051e06c5807f4144af Mon Sep 17 00:00:00 2001 From: Jonas Wagner Date: Tue, 18 Jan 2022 10:33:37 +0100 Subject: [PATCH 6/6] Fix rollDice Method --- src/main/java/Player.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/Player.java b/src/main/java/Player.java index 6cba702..bd5496c 100644 --- a/src/main/java/Player.java +++ b/src/main/java/Player.java @@ -12,6 +12,6 @@ public class Player { } public int rollDice() { - return (int) (Math.random() * 6); + return (int) (Math.random() * 6 + 1); } }