From cc3c752612a4130fa628664304e3af00d56fc365 Mon Sep 17 00:00:00 2001 From: Jonas Wagner Date: Tue, 11 Jan 2022 09:18:54 +0100 Subject: [PATCH 1/8] Add Gameboard.java and GameboardTest.java --- src/main/java/Gameboard.java | 8 +++++++ src/test/java/GameboardTest.java | 36 ++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 src/main/java/Gameboard.java create mode 100644 src/test/java/GameboardTest.java diff --git a/src/main/java/Gameboard.java b/src/main/java/Gameboard.java new file mode 100644 index 0000000..9dc4cd4 --- /dev/null +++ b/src/main/java/Gameboard.java @@ -0,0 +1,8 @@ +public class Gameboard { + int[][] board; + + public Gameboard() { + board = new int[11][11]; + } + +} diff --git a/src/test/java/GameboardTest.java b/src/test/java/GameboardTest.java new file mode 100644 index 0000000..f5b38ac --- /dev/null +++ b/src/test/java/GameboardTest.java @@ -0,0 +1,36 @@ +import static org.assertj.core.api.Assertions.*; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class GameboardTest { + + private Gameboard gb; + + @BeforeEach + void setup() { + gb = new Gameboard(); + } + + @Test + void checkGameboardSize() { + String expectedResult = "11, 11"; + String currentResult = "" + gb.board.length + ", " + gb.board[0].length; + + assertThat(currentResult).describedAs("Dimensions").isEqualTo(expectedResult); + } + + @Test + void checkGameboardFilled() { + int[][] expectedGameboard = new int[11][11]; + for(int i = 0; i < expectedGameboard.length; i++) { + for(int j = 0; j < expectedGameboard[0].length; j++) { + expectedGameboard[i][j] = 0; + } + } + int [][] givenGameboard = gb.board; + + assertThat(givenGameboard).describedAs("Initial Gameboard").isEqualTo(expectedGameboard); + } + +} From aa521559f6f7c8b51dbab6ec7b71d5eee285cf31 Mon Sep 17 00:00:00 2001 From: Felix Krull Date: Tue, 11 Jan 2022 09:52:56 +0100 Subject: [PATCH 2/8] Refactor 2-D board array to 1-D array --- src/main/java/Gameboard.java | 4 ++-- src/test/java/GameboardTest.java | 18 +++++++++++------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/main/java/Gameboard.java b/src/main/java/Gameboard.java index 9dc4cd4..8ffdcd0 100644 --- a/src/main/java/Gameboard.java +++ b/src/main/java/Gameboard.java @@ -1,8 +1,8 @@ public class Gameboard { - int[][] board; + int[] board; public Gameboard() { - board = new int[11][11]; + board = new int[11]; } } diff --git a/src/test/java/GameboardTest.java b/src/test/java/GameboardTest.java index f5b38ac..052c9b4 100644 --- a/src/test/java/GameboardTest.java +++ b/src/test/java/GameboardTest.java @@ -2,6 +2,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; + +import java.util.stream.Stream; public class GameboardTest { @@ -14,23 +19,22 @@ public class GameboardTest { @Test void checkGameboardSize() { - String expectedResult = "11, 11"; - String currentResult = "" + gb.board.length + ", " + gb.board[0].length; + String expectedResult = "11"; + String currentResult = "" + gb.board.length; assertThat(currentResult).describedAs("Dimensions").isEqualTo(expectedResult); } @Test void checkGameboardFilled() { - int[][] expectedGameboard = new int[11][11]; + int[] expectedGameboard = new int[11]; for(int i = 0; i < expectedGameboard.length; i++) { - for(int j = 0; j < expectedGameboard[0].length; j++) { - expectedGameboard[i][j] = 0; - } + expectedGameboard[i] = 0; } - int [][] givenGameboard = gb.board; + int [] givenGameboard = gb.board; assertThat(givenGameboard).describedAs("Initial Gameboard").isEqualTo(expectedGameboard); } + } From 036c0dccdd5b14773da07a10e44d06426dd7b1b5 Mon Sep 17 00:00:00 2001 From: Felix Krull Date: Tue, 11 Jan 2022 10:15:06 +0100 Subject: [PATCH 3/8] Add FieldTypes to Gameboard --- src/main/java/Gameboard.java | 16 +++++++++++++++- src/test/java/GameboardTest.java | 27 +++++++++++++++++++++++++-- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/src/main/java/Gameboard.java b/src/main/java/Gameboard.java index 8ffdcd0..c4c6212 100644 --- a/src/main/java/Gameboard.java +++ b/src/main/java/Gameboard.java @@ -2,7 +2,21 @@ public class Gameboard { int[] board; public Gameboard() { - board = new int[11]; + board = new int[56]; + } + + public void initGameboard (){ + board[0] = 1; + board[10] = 1; + board[20] = 1; + board[30] = 1; + board[9] = 2; + board[19] = 2; + board[29] = 2; + board[39] = 2; + for (int i = 40; i < board.length; i++) { + board[i] = 3; + } } } diff --git a/src/test/java/GameboardTest.java b/src/test/java/GameboardTest.java index 052c9b4..df0d89c 100644 --- a/src/test/java/GameboardTest.java +++ b/src/test/java/GameboardTest.java @@ -19,7 +19,7 @@ public class GameboardTest { @Test void checkGameboardSize() { - String expectedResult = "11"; + String expectedResult = "56"; String currentResult = "" + gb.board.length; assertThat(currentResult).describedAs("Dimensions").isEqualTo(expectedResult); @@ -27,7 +27,7 @@ public class GameboardTest { @Test void checkGameboardFilled() { - int[] expectedGameboard = new int[11]; + int[] expectedGameboard = new int[56]; for(int i = 0; i < expectedGameboard.length; i++) { expectedGameboard[i] = 0; } @@ -36,5 +36,28 @@ public class GameboardTest { assertThat(givenGameboard).describedAs("Initial Gameboard").isEqualTo(expectedGameboard); } + @ParameterizedTest + @MethodSource("FieldStream") + void checkGameboardFieldType(String testname, int Pos, int expectedResult) { + gb.initGameboard(); + int currentType = gb.board[Pos]; + assertThat(currentType).describedAs("Field Type").isEqualTo(expectedResult); + } + + static Stream FieldStream () { + return Stream.of( + Arguments.of("Normal Path", 1, 0), + Arguments.of("Starting Field", 0, 1), + Arguments.of("Starting Field", 10, 1), + Arguments.of("Starting Field", 20, 1), + Arguments.of("Starting Field", 30, 1), + Arguments.of("Doorway Field", 9, 2), + Arguments.of("Doorway Field", 19, 2), + Arguments.of("Doorway Field", 29, 2), + Arguments.of("Doorway Field", 39, 2), + Arguments.of("House Field", 40, 3), + Arguments.of("House Field", 55, 3) + ); + } } From 42e004f0a92e1f42370fd6a553db2b6aff9fc017 Mon Sep 17 00:00:00 2001 From: Felix Krull Date: Tue, 11 Jan 2022 10:18:58 +0100 Subject: [PATCH 4/8] Refactor Fieldtype declarations --- src/main/java/Gameboard.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/Gameboard.java b/src/main/java/Gameboard.java index c4c6212..81f54f6 100644 --- a/src/main/java/Gameboard.java +++ b/src/main/java/Gameboard.java @@ -6,14 +6,14 @@ public class Gameboard { } public void initGameboard (){ - board[0] = 1; - board[10] = 1; - board[20] = 1; - board[30] = 1; - board[9] = 2; - board[19] = 2; - board[29] = 2; - board[39] = 2; + for(int i = 0; i < 40; i++) { + if ( i % 10 == 0) { + board[i] = 1; + } + if( i % 10 == 9) { + board[i] = 2; + } + } for (int i = 40; i < board.length; i++) { board[i] = 3; } From e2b795e8a29b5b2ae71a23251b5bd15c67e6c05d Mon Sep 17 00:00:00 2001 From: Felix Krull Date: Tue, 11 Jan 2022 10:30:21 +0100 Subject: [PATCH 5/8] Edit Readme --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 46e35b7..61bf62a 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,7 @@ # CIiP-WiSe-2021-Projektarbeit-Mensch_Aerger_Dich_Nicht +## Beschreibung Projekt + +## Aufbau Spiel + +## Struktur Code \ No newline at end of file From 8da651f0ede8cf3a2f028c0771a77b553b033d37 Mon Sep 17 00:00:00 2001 From: FelixKrull Date: Tue, 11 Jan 2022 10:35:18 +0100 Subject: [PATCH 6/8] Edit Readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 61bf62a..12ecb7d 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # CIiP-WiSe-2021-Projektarbeit-Mensch_Aerger_Dich_Nicht +by Jonas Wagner und Felix Krull ## Beschreibung Projekt From e0b1106d0b32f9ad175dbb610b2a40083aa71d0a Mon Sep 17 00:00:00 2001 From: Jonas Wagner Date: Tue, 18 Jan 2022 08:48:03 +0100 Subject: [PATCH 7/8] Add printGameboard method --- README.md | 8 -------- src/main/java/Gameboard.java | 8 ++++++++ src/test/java/GameboardTest.java | 12 ++++++++++++ 3 files changed, 20 insertions(+), 8 deletions(-) delete mode 100644 README.md diff --git a/README.md b/README.md deleted file mode 100644 index 12ecb7d..0000000 --- a/README.md +++ /dev/null @@ -1,8 +0,0 @@ -# CIiP-WiSe-2021-Projektarbeit-Mensch_Aerger_Dich_Nicht -by Jonas Wagner und Felix Krull - -## Beschreibung Projekt - -## Aufbau Spiel - -## Struktur Code \ No newline at end of file diff --git a/src/main/java/Gameboard.java b/src/main/java/Gameboard.java index 81f54f6..03d5fdb 100644 --- a/src/main/java/Gameboard.java +++ b/src/main/java/Gameboard.java @@ -1,3 +1,6 @@ +import java.lang.reflect.Array; +import java.util.Arrays; + public class Gameboard { int[] board; @@ -19,4 +22,9 @@ public class Gameboard { } } + @Override + public String toString() { + return Arrays.toString(board); + } + } diff --git a/src/test/java/GameboardTest.java b/src/test/java/GameboardTest.java index df0d89c..8d53fdb 100644 --- a/src/test/java/GameboardTest.java +++ b/src/test/java/GameboardTest.java @@ -60,4 +60,16 @@ public class GameboardTest { ); } + @Test + void checkPrintGameboard() { + String expectedResult = "[1, 0, 0, 0, 0, 0, 0, 0, 0, 2, " + + "1, 0, 0, 0, 0, 0, 0, 0, 0, 2, " + + "1, 0, 0, 0, 0, 0, 0, 0, 0, 2, " + + "1, 0, 0, 0, 0, 0, 0, 0, 0, 2, " + + "3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]"; + gb.initGameboard(); + String calculatedResult = gb.toString(); + assertThat(calculatedResult).describedAs("Print Gameboard").isEqualTo(expectedResult); + } + } From 9c95c661f8327e9304667648d212d7146643faa6 Mon Sep 17 00:00:00 2001 From: Jonas Wagner Date: Tue, 18 Jan 2022 08:49:59 +0100 Subject: [PATCH 8/8] Restore README.md --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..12ecb7d --- /dev/null +++ b/README.md @@ -0,0 +1,8 @@ +# CIiP-WiSe-2021-Projektarbeit-Mensch_Aerger_Dich_Nicht +by Jonas Wagner und Felix Krull + +## Beschreibung Projekt + +## Aufbau Spiel + +## Struktur Code \ No newline at end of file