Пример #1
0
  /** _init ghosts. */
  private void _initGhosts() {
    fantasmas = new EnumMap<GHOST, Ghost>(GHOST.class);

    for (GHOST ghostType : GHOST.values())
      fantasmas.put(
          ghostType,
          new Ghost(
              ghostType,
              laberintoActua.lairNodeIndex,
              0,
              (int)
                  (ghostType.initialLairTime
                      * (Math.pow(LAIR_REDUCTION, cuentaElLvl % LEVEL_RESET_REDUCTION))),
              MOVE.NEUTRAL));
  }
Пример #2
0
  private boolean _reverseGhosts(EnumMap<GHOST, MOVE> moves, boolean force) {
    boolean reversed = false;
    boolean globalReverse = false;

    if (Math.random() < GHOST_REVERSAL) globalReverse = true;

    for (Entry<GHOST, MOVE> entry : moves.entrySet()) {
      Ghost ghost = fantasmas.get(entry.getKey());

      if (tiempoLvlActual > 1 && ghost.lairTime == 0 && ghost.lastMoveMade != MOVE.NEUTRAL) {
        if (force || (pildoraPoderFueComida || globalReverse)) {
          ghost.lastMoveMade = ghost.lastMoveMade.opposite();
          ghost.currentNodeIndex =
              laberintoActua.graph[ghost.currentNodeIndex].neighbourhood.get(ghost.lastMoveMade);
          reversed = true;
          timeOfLastGlobalReversal = tiempoTotal;
        }
      }
    }

    return reversed;
  }
Пример #3
0
  /** _eat power pill. */
  private void _eatPowerPill() {
    pildoraPoderFueComida = false;

    int powerPillIndex = laberintoActua.graph[pacman.currentNodeIndex].powerPillIndex;

    if (powerPillIndex >= 0 && powerPills.get(powerPillIndex)) {
      score += POWER_PILL;
      fastamasComerMultiplicador = 1;
      powerPills.clear(powerPillIndex);

      int newEdibleTime =
          (int)
              (EDIBLE_TIME
                  * (Math.pow(EDIBLE_TIME_REDUCTION, cuentaElLvl % LEVEL_RESET_REDUCTION)));

      for (Ghost ghost : fantasmas.values())
        if (ghost.lairTime == 0) ghost.edibleTime = newEdibleTime;
        else ghost.edibleTime = 0;

      pildoraPoderFueComida = true;
    }
  }
Пример #4
0
  /** _feast. */
  private void _feast() {
    pacmanFueComido = false;

    for (GHOST ghost : GHOST.values()) fantasmaComido.put(ghost, false);

    for (Ghost ghost : fantasmas.values()) {
      int distance = getShortestPathDistance(pacman.currentNodeIndex, ghost.currentNodeIndex);

      if (distance <= EAT_DISTANCE && distance != -1) {
        if (ghost.edibleTime > 0) // pac-man eats ghost
        {
          score += GHOST_EAT_SCORE * fastamasComerMultiplicador;
          fastamasComerMultiplicador *= 2;
          ghost.edibleTime = 0;
          ghost.lairTime =
              (int)
                  (COMMON_LAIR_TIME
                      * (Math.pow(LAIR_REDUCTION, cuentaElLvl % LEVEL_RESET_REDUCTION)));
          ghost.currentNodeIndex = laberintoActua.lairNodeIndex;
          ghost.lastMoveMade = MOVE.NEUTRAL;

          fantasmaComido.put(ghost.type, true);
        } else // ghost eats pac-man
        {
          pacman.numberOfLivesRemaining--;
          pacmanFueComido = true;

          if (pacman.numberOfLivesRemaining <= 0) juegoTerminado = true;
          else _levelReset();

          return;
        }
      }
    }

    for (Ghost ghost : fantasmas.values()) if (ghost.edibleTime > 0) ghost.edibleTime--;
  }
Пример #5
0
 /**
  * Returns the MANHATTAN distance between two nodes in the current mazes[gs.curMaze].
  *
  * @param fromNodeIndex the from node index
  * @param toNodeIndex the to node index
  * @return the manhattan distance
  */
 public int getManhattanDistance(int fromNodeIndex, int toNodeIndex) {
   return (int)
       (Math.abs(laberintoActua.graph[fromNodeIndex].x - laberintoActua.graph[toNodeIndex].x)
           + Math.abs(
               laberintoActua.graph[fromNodeIndex].y - laberintoActua.graph[toNodeIndex].y));
 }
Пример #6
0
 /**
  * Returns the EUCLEDIAN distance between two nodes in the current mazes[gs.curMaze].
  *
  * @param fromNodeIndex the from node index
  * @param toNodeIndex the to node index
  * @return the euclidean distance
  */
 public double getEuclideanDistance(int fromNodeIndex, int toNodeIndex) {
   return Math.sqrt(
       Math.pow(laberintoActua.graph[fromNodeIndex].x - laberintoActua.graph[toNodeIndex].x, 2)
           + Math.pow(
               laberintoActua.graph[fromNodeIndex].y - laberintoActua.graph[toNodeIndex].y, 2));
 }