Browse Source

Merge branch 'ghostsbehaviour'

main
fdai7012 11 months ago
parent
commit
f0f4db2109
  1. 1
      src/main/java/pacmanGame/GameManager.java
  2. 10
      src/main/java/pacmanGame/GhostBehaviorRandom.java
  3. 18
      src/test/java/pacmanTests/GameManagerTest.java
  4. 27
      src/test/java/pacmanTests/MapTest.java
  5. 12
      src/test/java/pacmanTests/Vector2Test.java

1
src/main/java/pacmanGame/GameManager.java

@ -73,7 +73,6 @@ public class GameManager {
if(time == timeStopPillEffect)
ghostIsEdible = false;
}
}
public void spawnFruit() {

10
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;
}
}
}

18
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

27
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

12
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);
}
}
Loading…
Cancel
Save