diff --git a/src/main/java/pacmanGame/GameManager.java b/src/main/java/pacmanGame/GameManager.java index fbf7c78..96a0953 100644 --- a/src/main/java/pacmanGame/GameManager.java +++ b/src/main/java/pacmanGame/GameManager.java @@ -73,7 +73,6 @@ public class GameManager { if(time == timeStopPillEffect) ghostIsEdible = false; } - } public void spawnFruit() { diff --git a/src/main/java/pacmanGame/GhostBehaviorRandom.java b/src/main/java/pacmanGame/GhostBehaviorRandom.java index d461501..a60db09 100644 --- a/src/main/java/pacmanGame/GhostBehaviorRandom.java +++ b/src/main/java/pacmanGame/GhostBehaviorRandom.java @@ -1,7 +1,9 @@ package pacmanGame; import java.util.Random; public class GhostBehaviorRandom implements GhostBehavior { - +public int player; +public int ghost; +public boolean isPlayerAlive = true; @Override public Vector2 GetDirection(Ghost ghost) { Random random = new Random(); @@ -20,5 +22,9 @@ public class GhostBehaviorRandom implements GhostBehavior { } return null; } - + public void checkCollision() { + if (player == ghost) { + isPlayerAlive = false; + } + } } diff --git a/src/test/java/pacmanTests/GameManagerTest.java b/src/test/java/pacmanTests/GameManagerTest.java index b6a7c65..c3b095c 100644 --- a/src/test/java/pacmanTests/GameManagerTest.java +++ b/src/test/java/pacmanTests/GameManagerTest.java @@ -1,6 +1,8 @@ package pacmanTests; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import org.junit.jupiter.api.Test; @@ -47,6 +49,22 @@ class GameManagerTest { assertThat(collision).isEqualTo(expected); } + @Test + void testResumeGame() { + GameManager game = new GameManager(); + game.Unpause(); + assertFalse(game.isPaused); + } + + @Test + void testPauseGame() { + GameManager game = new GameManager(); + + assertFalse(game.isPaused); + game.Pause(); + assertTrue(game.isPaused); + } + @Test void GameManager_GostPlayerCollisionTest_DoesntDetectColliosion() { // arrange diff --git a/src/test/java/pacmanTests/MapTest.java b/src/test/java/pacmanTests/MapTest.java index c87c70f..a0431ce 100644 --- a/src/test/java/pacmanTests/MapTest.java +++ b/src/test/java/pacmanTests/MapTest.java @@ -2,6 +2,8 @@ package pacmanTests; import static org.assertj.core.api.Assertions.assertThat; +import java.util.function.IntPredicate; + import org.junit.jupiter.api.Test; import pacmanGame.*; @@ -33,6 +35,31 @@ class MapTest { assertThat(expectedBottomRight).isEqualTo(bottomRight); } + @Test + void Map_getCell_returnsExceptionCells() { + // arrange + String[] mapTest = { + "eew", + "e..", + "ww." + }; + GameManager gameManager = new GameManager(); + gameManager.map = new Map(mapTest, gameManager); + Map testMap = gameManager.map; + Cell expectedTopLeft = testMap.cells[2][0]; + Cell expectedMiddle = testMap.cells[1][1]; + Cell expectedBottomRight = testMap.cells[0][2]; + // act + Cell topLeft = testMap.getCell(new Vector2(2, 0)); + Cell middle = testMap.getCell(new Vector2(1, 1)); + Cell bottomRight = testMap.getCell(new Vector2(0, 2)); + IntPredicate expectedTopRight; + // assert + assertThat(expectedTopLeft).isEqualTo(topLeft); + assertThat(expectedMiddle).isEqualTo(middle); + assertThat(expectedBottomRight).isEqualTo(bottomRight); + } + @Test void Map_getCell_returnsCorrectCells() { // arrange @@ -56,7 +83,7 @@ class MapTest { assertThat(expectedMiddle).isEqualTo(middle); assertThat(expectedBottomRight).isEqualTo(bottomRight); } - + @Test void Map_getPath_returnCorrectPathSimple() { // arrange diff --git a/src/test/java/pacmanTests/Vector2Test.java b/src/test/java/pacmanTests/Vector2Test.java index 868e436..6854507 100644 --- a/src/test/java/pacmanTests/Vector2Test.java +++ b/src/test/java/pacmanTests/Vector2Test.java @@ -92,4 +92,16 @@ class Vector2Test { // assert assertThat(isWithin).isEqualTo(expectedWithin); } + + @Test + void Vector2_isWithin_returnsFalseWhenWithin() { + // arrange + Vector2 area = new Vector2(25, 30); + Vector2 point = new Vector2(7, 12); + // act + boolean isWithin = point.isWithin(area); + boolean expectedWithin = true; + // assert + assertThat(isWithin).isEqualTo(expectedWithin); + } }