diff --git a/src/main/java/pacmanGame/GameManager.java b/src/main/java/pacmanGame/GameManager.java index 2c6db7d..bebc234 100644 --- a/src/main/java/pacmanGame/GameManager.java +++ b/src/main/java/pacmanGame/GameManager.java @@ -38,4 +38,23 @@ public class GameManager { System.out.println("Unprocessed Input: " + inputChar + " (" + (int)inputChar + ")"); } } + public boolean GostPlayerColisionTest() + { + + for(int i = 0; i < ghosts.length; i++) { + + for(int x = 0; x < map.size.x; x++) { + for(int y = 0; y < map.size.y; y++) { + if(player.position.equals(ghosts[i].position)) + { + return true; + } + + } + + } + + } + return false; + } } diff --git a/src/test/java/pacmanTests/GameManagerTest.java b/src/test/java/pacmanTests/GameManagerTest.java index f895647..9495c45 100644 --- a/src/test/java/pacmanTests/GameManagerTest.java +++ b/src/test/java/pacmanTests/GameManagerTest.java @@ -5,9 +5,7 @@ import static org.junit.jupiter.api.Assertions.*; import org.junit.jupiter.api.Test; -import pacmanGame.GameManager; -import pacmanGame.Map; -import pacmanGame.VisualizerPlainText; +import pacmanGame.*; class GameManagerTest { @@ -48,4 +46,33 @@ class GameManagerTest { // assert assertThat(initialVptOutput).isNotEqualTo(updatedVptOutput); } + @Test + void GameManager_GostPlayerColisionTest_DetectsColosion() { + + // arrange + + GameManager gameManager = new GameManager(); + gameManager.player.position = gameManager.ghosts[0].position.Clone(); + //act + boolean colision = gameManager.GostPlayerColisionTest(); + boolean expected = true; + + // assert + assertThat(colision).isEqualTo(expected); + } + @Test + void GameManager_GostPlayerColisionTest_DoesntDetectColosion() { + + // arrange + + GameManager gameManager = new GameManager(); + gameManager.player.position = new Vector2(2,3); + gameManager.ghosts[0].position = new Vector2(4,5); + //act + boolean colision = gameManager.GostPlayerColisionTest(); + boolean expected = false; + + // assert + assertThat(colision).isEqualTo(expected); + } }