Ejemplo n.º 1
0
  /** Move Pac-man according to the direction */
  @Override
  public void move() {
    if (isEatAbility()) {
      KeyboardObserver.isTimeWrite = true;
      timeLeft = Math.abs(new Date().getTime() - time);
      if (timeLeft > 10000) {
        KeyboardObserver.isTimeWrite = false;
        eatAbility = false;
      }
    }

    Bonus b;
    if ((b = isHereBonus()) != null) {
      gamePoint += 50;
      Game.bonuses.remove(b);
    }

    Life l;
    if ((l = isHereLife()) != null) {
      Game.lives.remove(l);
      life++;
    }

    Ghost g;
    if ((g = isHereGhost()) != null) {
      Game.ghosts.remove(g);
      if (!isEatAbility()) {
        life--;
        try {
          Game.ghosts.add(new Ghost(Game.points.get(0).getX(), Game.points.get(0).getY()));
        } catch (Exception e) {
        }
        if (life == 0) {
          pacManKiller = g;
          Game.isGameOver = true;
          return;
        }
      }
    }

    if (isHerePoint()) {
      gamePoint++;
      Point t = null;
      for (Point point : Game.points) {
        if (point.getX() == x && point.getY() == y) {
          t = point;
          break;
        }
      }
      Game.points.remove(t);
    }

    previousX = x;
    previousY = y;

    switch (direction) {
      case 1:
        x--;
        ImagePane.direction = 1;
        break;
      case 2:
        x++;
        ImagePane.direction = 2;
        break;
      case 3:
        y--;
        ImagePane.direction = 3;
        break;
      case 4:
        y++;
        ImagePane.direction = 4;
        break;
    }
    checkBorders();

    if (isHereBrick()) {
      x = previousX;
      y = previousY;
      ImagePane.direction = previousDirection;
      direction = previousDirection;
    }
  }
Ejemplo n.º 2
0
 /**
  * Check at the intersection of Pac-man with Point
  *
  * @return
  */
 public boolean isHerePoint() {
   for (Point point : Game.points) {
     if (point.getX() == x && point.getY() == y) return true;
   }
   return false;
 }