Package org.jpacman.framework.model

Examples of org.jpacman.framework.model.Game


   *
   * @throws FactoryException If parsing fails. Should not happen.
   */
  @Test
  public void testFullMap() throws FactoryException {
    Game g = parser.parseMap(map);
    Board b = g.getBoard();

    // did we recognize the right sprites?
    assertEquals(SpriteType.EMPTY, b.spriteTypeAt(1, 3));
    assertEquals(SpriteType.PLAYER, b.spriteTypeAt(2, 2));
    assertEquals(SpriteType.GHOST, b.spriteTypeAt(1, 2));
    assertEquals(SpriteType.WALL, b.spriteTypeAt(0, 0));
    assertEquals(SpriteType.FOOD, b.spriteTypeAt(1, 1));

    // did we properly set the player?
    assertEquals(g.getPlayer(), b.spriteAt(2, 2));

    // were all ghosts added?
    assertEquals(2, g.getGhosts().size());

    // was the food actually added?
    final int cellsWithFoodCount = 3;
    assertEquals(cellsWithFoodCount * Food.DEFAULT_POINTS,
           g.getPointManager().totalFoodInGame());
  }
View Full Code Here


   * @throws FactoryException If singleRow contains illegal chars.
   * @return The game created while parsing the row.
   */
  protected Game makePlay(String singleRow) throws FactoryException {
    MapParser p = new MapParser(makeFactory());
    Game theGame = p.parseMap(new String[]{singleRow});
    return theGame;
  }
View Full Code Here

   *
   * @throws FactoryException Never.
   */
  @Test
  public void testInitialSetting() throws FactoryException {
    Game g = makePlay("P");
    assertEquals(g.getPlayer(), g.getBoard().spriteAt(0, 0));
    assertThat(tileAt(g, 0, 0), equalTo(g.getPlayer().getTile()));
    assertEquals(SpriteType.PLAYER, g.getBoard().spriteTypeAt(0, 0));
    assertEquals(0, g.getPlayer().getPoints());
    assertTrue(g.getPlayer().isAlive());
    assertEquals(Direction.LEFT, g.getPlayer().getDirection());
  }
View Full Code Here

   *
   * @throws FactoryException Can't happen.
   */
  @Test
  public void testC1a_PlayerMovesToEmpty() throws FactoryException {   
    Game g = makePlay("P #");
    g.movePlayer(Direction.RIGHT);
   
    assertEquals("Player moved", tileAt(g, 1, 0), g.getPlayer().getTile());
    assertEquals("No food eaten.", 0, g.getPlayer().getPoints());
    assertEquals(Direction.RIGHT, g.getPlayer().getDirection());
  }
View Full Code Here

   *
   * @throws FactoryException Can't happen.
   */
  @Test
  public void testC1b_GhostMovesToEmpty() throws FactoryException {
    Game g = makePlay("G #");
    Ghost theGhost = (Ghost) g.getBoard().spriteAt(0, 0);

    g.moveGhost(theGhost, Direction.RIGHT);
   
    assertEquals("Ghost moved", tileAt(g, 1, 0), theGhost.getTile());
  }
View Full Code Here

   *
   * @throws FactoryException Can't happen.
   */
  @Test
  public void testC2a_PlayerMovesToWall() throws FactoryException {   
    Game g = makePlay("#P.");
    g.movePlayer(Direction.LEFT);
    assertThat("Still at the start",
        tileAt(g, 1, 0), equalTo(g.getPlayer().getTile()));
  }
View Full Code Here

   *
   * @throws FactoryException Can't happen.
   */
  @Test
  public void testC2b_GhostMovesToWall() throws FactoryException {
    Game g = makePlay(" G#");
    Ghost theGhost = (Ghost) g.getBoard().spriteAt(1, 0);

    g.moveGhost(theGhost, Direction.RIGHT);
   
    assertEquals("Ghost not moved", tileAt(g, 1, 0), theGhost.getTile());
  }
View Full Code Here

   *
   * @throws FactoryException Never.
   */
  @Test
  public void testC3_PlayerMovesToGhost() throws FactoryException {   
    Game g = makePlay("PG#");
    Player p = g.getPlayer();
   
    g.movePlayer(Direction.RIGHT);
   
    assertFalse("Move kills player", p.isAlive());   
    assertThat(tileAt(g, 1, 0), equalTo(p.getTile()));
  }
View Full Code Here

   *
   * @throws FactoryException Never.
   */
  @Test
  public void testC5_PlayerMovesToFood() throws FactoryException {   
    Game game = makePlay("P.#");
    Food food = (Food) game.getBoard().spriteAt(1, 0);
    Player player = game.getPlayer();

    game.movePlayer(Direction.RIGHT);
   
    Tile newTile = tileAt(game, 1, 0);
    assertEquals("Food added", food.getPoints(), player.getPoints());
    assertEquals("Player moved", newTile.topSprite(), player);
    assertFalse("Food gone", newTile.containsSprite(food));
View Full Code Here

   *
   * @throws FactoryException Never.
   */
  @Test
  public void testC4_GhostMovesToPlayer() throws FactoryException {   
    Game game = makePlay("PG#");
    Ghost theGhost = (Ghost) game.getBoard().spriteAt(1, 0);

    game.moveGhost(theGhost, Direction.LEFT);
    assertFalse("Move kills player", game.getPlayer().isAlive());
   
    Tile newTile = theGhost.getTile();
    assertThat(tileAt(game, 0, 0), equalTo(newTile));
  }
View Full Code Here

TOP

Related Classes of org.jpacman.framework.model.Game

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.