80 lines
2.6 KiB
Java
80 lines
2.6 KiB
Java
package nl.tudelft.jpacman.level;
|
|
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
import com.google.common.collect.Lists;
|
|
|
|
import nl.tudelft.jpacman.board.Board;
|
|
import nl.tudelft.jpacman.board.BoardFactory;
|
|
import nl.tudelft.jpacman.board.Direction;
|
|
import nl.tudelft.jpacman.board.Square;
|
|
import nl.tudelft.jpacman.game.Game;
|
|
import nl.tudelft.jpacman.game.GameFactory;
|
|
import nl.tudelft.jpacman.npc.ghost.GhostFactory;
|
|
import nl.tudelft.jpacman.sprite.PacManSprites;
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
/**
|
|
* Test suite to confirm the correct behaviour of pellet consumtion as
|
|
* described in Scenario S2.1.
|
|
*
|
|
* @author Michael Chen
|
|
*/
|
|
class PlayerTest {
|
|
private MapParser parser;
|
|
private GameFactory gameFact;
|
|
|
|
/**
|
|
* Prepare the game factory
|
|
*/
|
|
@BeforeEach
|
|
void setUpTest() {
|
|
PacManSprites sprites = new PacManSprites();
|
|
parser = new MapParser(new LevelFactory(sprites,
|
|
new GhostFactory(sprites)), new BoardFactory(sprites));
|
|
gameFact = new GameFactory(new PlayerFactory(sprites));
|
|
}
|
|
|
|
/**
|
|
* Scenario S2.1: The player consumes
|
|
*/
|
|
@Test
|
|
void playerConsumeTest() {
|
|
Level level = parser.parseMap(
|
|
Lists.newArrayList("####", "#P.#", "####"));
|
|
Board board = level.getBoard();
|
|
Game game = gameFact.createSinglePlayerGame(level);
|
|
Player player = game.getPlayers().get(0);
|
|
Square playerStart = board.squareAt(1, 1);
|
|
Square pelletPos = board.squareAt(2, 1);
|
|
|
|
// Given the game has started,
|
|
game.start();
|
|
assertThat(game.isInProgress()).isTrue();
|
|
assertThat(player.getScore()).isZero();
|
|
|
|
// and my Pacman is next to a square containing a pellet;
|
|
assertThat(pelletPos.getOccupants())
|
|
.hasAtLeastOneElementOfType(Pellet.class);
|
|
assertThat(pelletPos.getOccupants()).hasSize(1);
|
|
Pellet pellet = (Pellet) pelletPos.getOccupants().get(0);
|
|
assertThat(playerStart.getOccupants()).contains(player);
|
|
|
|
// When I press an arrow key towards that square;
|
|
game.move(player, Direction.EAST);
|
|
|
|
// Then my Pacman can move to that square,
|
|
assertThat(pelletPos.getOccupants()).contains(player);
|
|
|
|
// and I earn the points for the pellet,
|
|
assertThat(player.getScore()).isEqualTo(pellet.getValue());
|
|
|
|
// and the pellet disappears from that square.
|
|
assertThat(pelletPos.getOccupants()).doesNotContain(pellet);
|
|
|
|
game.stop();
|
|
}
|
|
}
|