From a9337af708a2b74a9b2e9cba5c053a79881524e8 Mon Sep 17 00:00:00 2001 From: Julius Dewender Date: Sun, 31 Jan 2021 11:50:34 +0100 Subject: [PATCH] initial figure placement on field --- .../src/main/java/de/fd/fh/Game.java | 12 +++++++++++ .../src/test/java/de/fd/fh/GameTest.java | 20 +++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/fh.fd.ci.client/src/main/java/de/fd/fh/Game.java b/fh.fd.ci.client/src/main/java/de/fd/fh/Game.java index 5a0aa5e..cb0606a 100644 --- a/fh.fd.ci.client/src/main/java/de/fd/fh/Game.java +++ b/fh.fd.ci.client/src/main/java/de/fd/fh/Game.java @@ -7,5 +7,17 @@ public class Game public void initNewGame() { mField = new Figure[Figure.fieldLength * Figure.fieldLength]; + + // Figuren platzieren + for (int i = 0; i < 8; i++) // row + { + if (i == 0 || i == 1 || i == 6 || i == 7) + { + for (int j = 0; j < 8; j++) // col + { + mField[i * 8 + j] = new Figure(); + } + } + } } } diff --git a/fh.fd.ci.client/src/test/java/de/fd/fh/GameTest.java b/fh.fd.ci.client/src/test/java/de/fd/fh/GameTest.java index 49e8668..59fa60e 100644 --- a/fh.fd.ci.client/src/test/java/de/fd/fh/GameTest.java +++ b/fh.fd.ci.client/src/test/java/de/fd/fh/GameTest.java @@ -15,4 +15,24 @@ class GameTest assertEquals(Figure.fieldLength * Figure.fieldLength, g.mField.length); } + + // prüft, ob Figuren nach Initialisierung nur an vorgesehenden Positionen stehen + @Test + void newGameInitializationFigurePositions() + { + Game g = new Game(); + g.initNewGame(); + + for (int i = 0; i < 8; i++) // row + { + if (i == 0 || i == 1 || i == 6 || i == 7) + { + for (int j = 0; j < 8; j++) // col + { + assertNotEquals(null, g.mField[i * 8 + j]); + } + } + } + assertEquals(Figure.fieldLength * Figure.fieldLength, g.mField.length); + } } \ No newline at end of file