Browse Source

added Colision Test Function to Game Manager

remotes/origin/menu
fdai7917 11 months ago
parent
commit
267a021778
  1. 19
      src/main/java/pacmanGame/GameManager.java
  2. 33
      src/test/java/pacmanTests/GameManagerTest.java

19
src/main/java/pacmanGame/GameManager.java

@ -38,4 +38,23 @@ public class GameManager {
System.out.println("Unprocessed Input: " + inputChar + " (" + (int)inputChar + ")"); 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;
}
} }

33
src/test/java/pacmanTests/GameManagerTest.java

@ -5,9 +5,7 @@ import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import pacmanGame.GameManager;
import pacmanGame.Map;
import pacmanGame.VisualizerPlainText;
import pacmanGame.*;
class GameManagerTest { class GameManagerTest {
@ -48,4 +46,33 @@ class GameManagerTest {
// assert // assert
assertThat(initialVptOutput).isNotEqualTo(updatedVptOutput); 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);
}
} }
Loading…
Cancel
Save