diff --git a/src/main/java/de/tims/fleetstorm/GameManager.java b/src/main/java/de/tims/fleetstorm/GameManager.java index 8f682cc..9a8a59d 100644 --- a/src/main/java/de/tims/fleetstorm/GameManager.java +++ b/src/main/java/de/tims/fleetstorm/GameManager.java @@ -1,8 +1,13 @@ package de.tims.fleetstorm; +import de.tims.fleetstorm.matchfield.Matchfield; + public class GameManager { private int gameState; + private Matchfield matchfield; + private int matchfieldSize = 10; + private boolean playerMove = true; public static final int PREPARATION = 1; public static final int RUNNING = 2; @@ -10,10 +15,20 @@ public class GameManager { public void start() { this.gameState = GameManager.PREPARATION; + + this.matchfield = new Matchfield(matchfieldSize); + } + + public void nextMove() { + this.playerMove = !this.playerMove; } public int getGameState() { return gameState; } + public boolean isPlayerMove() { + return playerMove; + } + } diff --git a/src/test/java/de/tims/fleetstorm/GameManagerTest.java b/src/test/java/de/tims/fleetstorm/GameManagerTest.java index d90e85f..5c329c7 100644 --- a/src/test/java/de/tims/fleetstorm/GameManagerTest.java +++ b/src/test/java/de/tims/fleetstorm/GameManagerTest.java @@ -1,16 +1,23 @@ package de.tims.fleetstorm; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertEquals; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; class GameManagerTest { GameManager gameManager = new GameManager(); + @BeforeEach + void setup() { + gameManager.start(); + } + @Test void testIfGameStateIsPreparationAfterStart() { - gameManager.start(); int expectedState = GameManager.PREPARATION; int calculatedState = gameManager.getGameState(); @@ -18,4 +25,19 @@ class GameManagerTest { assertEquals(expectedState, calculatedState); } + @Test + void testNextMoveIsNotPlayer() { + + // 20 tries => every even move is a player move + for (int i = 0; i < 20; i++) { + gameManager.nextMove(); + boolean calculatedResult = gameManager.isPlayerMove(); + if (i % 2 == 0) { + assertFalse(calculatedResult); + } else { + assertTrue(calculatedResult); + } + } + } + }