Beispiel #1
0
  /**
   * Updates the game state to the next tick. First applies the messages past in as arguments, then
   * updates the nodes, then the lanes, then checks for a winning player.
   *
   * @param messages the messages to apply for this game state tick
   */
  public void update(Message[] messages) {
    this.validateLock();

    for (Message m : messages) m.apply(this);

    this.validateLock();

    for (Node n : map.getNodes()) n.update();

    this.validateLock();

    for (Lane l : map.getLanes()) l.update();

    this.validateLock();

    double energyToAdd = ENERGY_INCREMENT_RATE * this.getLastLoopTime();
    for (Player p : players.values()) {
      p.setPlayerEnergy(p.getPlayerEnergy() + energyToAdd);
      if (p.getPlayerEnergy() > MAX_PLAYER_ENERGY) p.setPlayerEnergy(MAX_PLAYER_ENERGY);
    }

    timerTick++;

    lastLoopTime = this.getTime() - timeAtEndOfLastLoop;
    timeAtEndOfLastLoop = this.getTime();

    this.validateLock();

    // check for win
    Node n1 = map.getNodes()[0];
    for (Node n : map.getNodes())
      if (n1.getOwner() == null || !n1.getOwner().equals(n.getOwner())) return;
    winningPlayer = n1.getOwner();
  }