From 267a021778ff76d9f6200ec0865e3b20c7b4e871 Mon Sep 17 00:00:00 2001 From: fdai7917 Date: Tue, 23 Jan 2024 16:25:11 +0100 Subject: [PATCH] added Colision Test Function to Game Manager --- src/main/java/pacmanGame/GameManager.java | 19 +++++++++++ .../java/pacmanTests/GameManagerTest.java | 33 +++++++++++++++++-- 2 files changed, 49 insertions(+), 3 deletions(-) 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); + } }