Package org.jpacman.framework.model

Examples of org.jpacman.framework.model.Ghost


     * Return a randomly chosen ghost, or null if there
     * are no ghosts in this game.
     * @return Random ghost or null;
     */
    protected Ghost getRandomGhost() {
        Ghost theGhost = null;
        if (!ghosts.isEmpty()) {
            final int ghostIndex = randomizer.nextInt(ghosts.size());
            theGhost = ghosts.get(ghostIndex);
        }
        return theGhost;
View Full Code Here


    /**
     * Actually conduct a random move in the underlying engine.
     */
    public void doTick() {
        synchronized (gameInteraction()) {
            Ghost theGhost = getRandomGhost();
            if (theGhost == null) {
                return;
            }
            int dirIndex = getRandomizer().nextInt(Direction.values().length);
            final Direction dir = Direction.values()[dirIndex];
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 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 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

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

    game.moveGhost(theGhost, Direction.RIGHT);   
    assertEquals("Ghost moved", tileAt(game, 1, 0), theGhost.getTile());

    game.moveGhost(theGhost, Direction.LEFT);
    assertEquals(SpriteType.FOOD, game.getBoard().spriteTypeAt(1, 0));
  }
View Full Code Here

  public void testObserverAfterGhostMove() throws FactoryException {
    // given
    Observer anObserver = mock(Observer.class);
    Game game = makePlay("G #");
    game.addObserver(anObserver);
    Ghost ghost = (Ghost) game.getBoard().spriteAt(0, 0);
    // when
    game.moveGhost(ghost, Direction.RIGHT);
    // then
    verify(anObserver).update(any(Observable.class), anyObject());
  }
View Full Code Here

  }

  @Override
  public Ghost makeGhost() {
    assert getGame() != null;
    Ghost g = new Ghost();
    getGame().addGhost(g);
    return g;
  }
View Full Code Here

TOP

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

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.