Android Open Source - Apocalypse-Defense Survivor Manager






From Project

Back to project page Apocalypse-Defense.

License

The source code is released under:

MIT License

If you think the Android project Apocalypse-Defense listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.apocalypsedefense.core;
/*  w w w .  j  ava 2 s  .c  o  m*/
public class SurvivorManager {
  Game game;

  public SurvivorManager(Game game) {
    this.game = game;

    // TODO Auto-generated constructor stub
  }

  public void buySurvivorAt(int x, int y) throws Exception {
    if (!canBuySurvivorAt(x, y)) {
      throw new Exception(
          "CANNOT BUY SURVIVOR, DID YOU CHECK canBuySurvivorAt()?"); // TODO:
                                        // PUT
                                        // A
                                        // REAL
                                        // ERROR
                                        // HERE
    }
    game.survivors.add(new Survivor(new Point(x, y))); // Add that survivor
                              // to our current
                              // list //TODO
                              // FInish logic here
  }

  public Boolean canBuySurvivorAt(int x, int y) {
    return !game.map.isBlocked(new Point(x, y)); // false if blocked, true
                            // if not blocked
  }

  public void update() {

    // For each survivor in the list of survivors:
    for (int s = 0; s < game.survivors.size(); s++) {
      // If the survivor has a target and the target is still alive:
      Survivor survivor = game.survivors.get(s);
      if (survivor.target != null
          && game.zombies.contains(survivor.target)) {
        // Shoot the target:
        survivor.target.takeDamage(survivor.attack());
        // If the target is killed:
        if (!survivor.target.isAlive) {
          // Remove the zombie:
          System.out.print(survivor.target.name + " killed!");
          game.zombies.remove(survivor.target);
          game.zombieKillCount++; // Add kill to zombie kill list
          System.out.print("Zombie Killer Counter: "
              + game.zombieKillCount);
          game.gold += survivor.target.worth; // Add gold from kill
          System.out.print("Gold: " + game.gold);
          // Reset survivor's target:
          survivor.target = null;
        }
      }
      // Otherwise, if the survivor doesn't have a target or the target
      // died and there are still zombies:
      else if ((survivor.target == null || !game.zombies
          .contains(survivor.target)) && game.zombies.size() != 0) {
        // Set the survivor's target to null to skip checking next loop:
        survivor.target = null;
        // Find the closest zombie:
        float minDist = 99999;
        Zombie closestTarget = null;
        for (int z = 0; z < game.zombies.size(); z++) {
          float dist = survivor.position.getDistance(game.zombies
              .get(z).position);
          // If we found a new minimum distance AND the zombie is
          // within attack range:
          if (dist < minDist && dist < survivor.weapon.range) {
            minDist = dist;
            closestTarget = game.zombies.get(z);
          }
        }
        if (closestTarget != null) {

          // Set the survivor's target to the closest zombie:
          survivor.target = closestTarget;
          // If the survivor targets the zombie, the zombie will
          // automatically target the survivor:
          closestTarget.target = survivor;

        }
      }
    }

  }
}




Java Source Code List

com.apocalypsedefense.app.AchievementsActivity.java
com.apocalypsedefense.app.ApocalypseDefenseActivity.java
com.apocalypsedefense.app.EndOfGameDialog.java
com.apocalypsedefense.app.ExitConfirmationDialog.java
com.apocalypsedefense.app.InGameActivity.java
com.apocalypsedefense.app.InstructionsDialog.java
com.apocalypsedefense.app.NewGameSettingsActivity.java
com.apocalypsedefense.app.OverwriteExistingGameDialog.java
com.apocalypsedefense.app.gameplay_visuals.AndroidLogAdapter.java
com.apocalypsedefense.app.gameplay_visuals.GameFacade.java
com.apocalypsedefense.app.gameplay_visuals.GameObject.java
com.apocalypsedefense.app.gameplay_visuals.GameSurfaceView.java
com.apocalypsedefense.app.gameplay_visuals.GameThread.java
com.apocalypsedefense.app.gameplay_visuals.OnGameEndListener.java
com.apocalypsedefense.app.gameplay_visuals.OnStatsChangedListener.java
com.apocalypsedefense.app.gameplay_visuals.Sprite.java
com.apocalypsedefense.core.ActorType.java
com.apocalypsedefense.core.Armor.java
com.apocalypsedefense.core.GameData.java
com.apocalypsedefense.core.GameState.java
com.apocalypsedefense.core.Game.java
com.apocalypsedefense.core.Gun.java
com.apocalypsedefense.core.LogAdapter.java
com.apocalypsedefense.core.MapElement.java
com.apocalypsedefense.core.Map.java
com.apocalypsedefense.core.Movement.java
com.apocalypsedefense.core.Person.java
com.apocalypsedefense.core.Point.java
com.apocalypsedefense.core.PrintLogAdapter.java
com.apocalypsedefense.core.Shared.java
com.apocalypsedefense.core.SurvivorManager.java
com.apocalypsedefense.core.Survivor.java
com.apocalypsedefense.core.Weapon.java
com.apocalypsedefense.core.ZombieManager.java
com.apocalypsedefense.core.Zombie.java
com.apocalypsedefense.core.testDriver.java