From 9ffc4af8dffa349c6319921063db0d041dcc78ab Mon Sep 17 00:00:00 2001 From: fdai2751 Date: Thu, 8 Feb 2024 02:46:18 +0100 Subject: [PATCH 1/6] added the collision function player vs Ghosts --- src/main/java/pacmanGame/GhostBehaviorRandom.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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; + } + } } From e8a6b32276953e0ed1fd54292146c5b180a530fb Mon Sep 17 00:00:00 2001 From: fdai2751 Date: Thu, 8 Feb 2024 14:29:15 +0100 Subject: [PATCH 2/6] Refactoring: update function in GameManager --- src/main/java/pacmanGame/GameManager.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/java/pacmanGame/GameManager.java b/src/main/java/pacmanGame/GameManager.java index 0063ad3..96160ca 100644 --- a/src/main/java/pacmanGame/GameManager.java +++ b/src/main/java/pacmanGame/GameManager.java @@ -37,13 +37,23 @@ public class GameManager { ghosts[i].move(); } } + switch (time) { + case 300: + spawnCherry(); + case 600: + destroyCherry(); + default: + break; + } + time++; + /* if(time == 300) { spawnCherry(); } if (time == 600) { destroyCherry(); - } - time++; + }*/ + } public void spawnCherry() { From c5f46f59d66b48ac805e5345db22542bbdc00be7 Mon Sep 17 00:00:00 2001 From: fdai2751 Date: Thu, 8 Feb 2024 15:21:27 +0100 Subject: [PATCH 3/6] Test: JunitTest verified correct cell --- src/main/java/pacmanGame/GameManager.java | 10 +------- src/test/java/pacmanTests/MapTest.java | 29 ++++++++++++++++++++++- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/src/main/java/pacmanGame/GameManager.java b/src/main/java/pacmanGame/GameManager.java index 96160ca..be98221 100644 --- a/src/main/java/pacmanGame/GameManager.java +++ b/src/main/java/pacmanGame/GameManager.java @@ -45,15 +45,7 @@ public class GameManager { default: break; } - time++; - /* - if(time == 300) { - spawnCherry(); - } - if (time == 600) { - destroyCherry(); - }*/ - + time++; } public void spawnCherry() { diff --git a/src/test/java/pacmanTests/MapTest.java b/src/test/java/pacmanTests/MapTest.java index 723fa63..571d8eb 100644 --- a/src/test/java/pacmanTests/MapTest.java +++ b/src/test/java/pacmanTests/MapTest.java @@ -3,6 +3,8 @@ package pacmanTests; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.*; +import java.util.function.IntPredicate; + import org.junit.jupiter.api.Test; import pacmanGame.*; @@ -34,6 +36,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 @@ -57,7 +84,7 @@ class MapTest { assertThat(expectedMiddle).isEqualTo(middle); assertThat(expectedBottomRight).isEqualTo(bottomRight); } - + @Test void Map_getPath_returnCorrectPathSimple() { // arrange From e23fc6dce748c7f32bdd9e7df7b352f4369bbf46 Mon Sep 17 00:00:00 2001 From: fdai2751 Date: Thu, 8 Feb 2024 16:59:42 +0100 Subject: [PATCH 4/6] Test: junitTest vector2 iswithin --- src/test/java/pacmanTests/Vector2Test.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/test/java/pacmanTests/Vector2Test.java b/src/test/java/pacmanTests/Vector2Test.java index 2613f2f..c8fbe87 100644 --- a/src/test/java/pacmanTests/Vector2Test.java +++ b/src/test/java/pacmanTests/Vector2Test.java @@ -93,4 +93,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); + } } From b90ccb83b5a773db0aedf8f537f8b30cf05d4d3d Mon Sep 17 00:00:00 2001 From: fdai2751 Date: Thu, 8 Feb 2024 19:35:52 +0100 Subject: [PATCH 5/6] =?UTF-8?q?Test:=20JunitTest=20f=C3=BCr=20pause=20func?= =?UTF-8?q?tion=20in=20GameManager?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/java/pacmanTests/GameManagerTest.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/test/java/pacmanTests/GameManagerTest.java b/src/test/java/pacmanTests/GameManagerTest.java index eb24fed..fff3574 100644 --- a/src/test/java/pacmanTests/GameManagerTest.java +++ b/src/test/java/pacmanTests/GameManagerTest.java @@ -46,6 +46,7 @@ class GameManagerTest { // assert assertThat(initialVptOutput).isNotEqualTo(updatedVptOutput); } + @Test void GameManager_GostPlayerColisionTest_DetectsColosion() { @@ -60,6 +61,16 @@ class GameManagerTest { // assert assertThat(collision).isEqualTo(expected); } + @Test + void testPauseGame() { + GameManager game = new GameManager(); + + assertFalse(game.isPaused); + game.Pause(); + assertTrue(game.isPaused); + } + + @Test void GameManager_GostPlayerCollisionTest_DoesntDetectColliosion() { From 6cb31fa16a0a1394f7ef003a588faad6b6ce3dd5 Mon Sep 17 00:00:00 2001 From: fdai2751 Date: Thu, 8 Feb 2024 19:50:53 +0100 Subject: [PATCH 6/6] Test: JunitTest Gameresumed to test --- src/test/java/pacmanTests/GameManagerTest.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/test/java/pacmanTests/GameManagerTest.java b/src/test/java/pacmanTests/GameManagerTest.java index fff3574..d82d9e2 100644 --- a/src/test/java/pacmanTests/GameManagerTest.java +++ b/src/test/java/pacmanTests/GameManagerTest.java @@ -61,6 +61,14 @@ class GameManagerTest { // assert assertThat(collision).isEqualTo(expected); } + + @Test + void testResumeGame() { + GameManager game = new GameManager(); + game.Unpause(); + assertFalse(game.isPaused); + } + @Test void testPauseGame() { GameManager game = new GameManager(); @@ -69,7 +77,6 @@ class GameManagerTest { game.Pause(); assertTrue(game.isPaused); } - @Test void GameManager_GostPlayerCollisionTest_DoesntDetectColliosion() {