Ejemplo n.º 1
0
  /** Reset the simulation to a starting position. */
  public void reset() {
    step = 0;
    populate();

    // Show the starting state in the view.
    view.showStatus(step, field);
  }
Ejemplo n.º 2
0
  /** Initialize game. */
  public void init() {
    //		// Create characters
    //		Human h1 = new Human("Human 1", HP_HUMANS);
    //		Human h2 = new Human("Human 2", HP_HUMANS);
    //		Vampire v1 = new Vampire("Vampire 1", HP_VAMPIRES);
    //		Vampire v2 = new Vampire("Vampire 2", HP_VAMPIRES);
    //		Zombie z1 = new Zombie("Zombie 1", HP_ZOMBIES);
    //		MadZombie mz1 = new MadZombie("MadZombie 1", HP_ZOMBIES);
    // Add characters to the list
    characterList = new ArrayList<Character>();
    //		characterList.add(h1);
    //		characterList.add(h2);
    //		characterList.add(v1);
    //		characterList.add(v2);
    //		characterList.add(z1);
    //		characterList.add(mz1);
    /*humans = new ArrayList<Human>();
    zombies = new ArrayList<Zombie>();
    vampires = new ArrayList<Vampire>();
    madZombies = new ArrayList<MadZombie>();*/
    //	    humans.add(h1);
    //	    humans.add(h2);
    //	    vampires.add(v1);
    //	    vampires.add(v2);
    //	    zombies.add(z1);
    //	    madZombies.add(mz1);

    shotguns = new ArrayList<ShotGun>();
    nitrogens = new ArrayList<LiquidNitrogen>();
    stakes = new ArrayList<WoodenStake>();

    field = new Field(DEFAULT_DEPTH, DEFAULT_WIDTH);

    // Create a view of the state of each location in the field.
    view = new SimulatorView(DEFAULT_DEPTH, DEFAULT_WIDTH);
    view.setColor(Human.class, Color.orange);
    view.setColor(Zombie.class, Color.green);
    view.setColor(Vampire.class, Color.black);
    view.setColor(MadZombie.class, Color.red);
    view.setColor(BaseObject.class, Color.cyan);

    // Setup a valid starting point.
    reset();
  }
Ejemplo n.º 3
0
  /**
   * Run the simulation from its current state for a single step. Iterate over the whole field
   * updating the state of each fox and rabbit.
   */
  public void simulateOneStep() {
    step++;

    // Provide space for newborn humans.
    List<Human> newHumans = new ArrayList<Human>();
    // Provide space for newborn vampires.
    List<Vampire> newVampires = new ArrayList<Vampire>();
    // Provide space for newborn wolfs.
    List<Zombie> newZombies = new ArrayList<Zombie>();
    // Let all characters act.
    for (Iterator<Character> it = characterList.iterator(); it.hasNext(); ) {
      Character c = it.next();
      if (c.getCharacter() == TypeCharacter.HUMAN) {
        Human h = (Human) c;
        h.run(newHumans);
      }
      if (c.getCharacter() == TypeCharacter.VAMPIRE) {
        Vampire v = (Vampire) c;
        v.hunt(newVampires);
      }
      if (c.getCharacter() == TypeCharacter.ZOMBIE) {
        Zombie z = (Zombie) c;
        z.hunt(newZombies);
      }

      if (c.getCharacter() == TypeCharacter.MADZOMBIE) {
        MadZombie mz = (MadZombie) c;
        mz.hunt(newZombies);
      }
    }

    // Add the newly born humans, vampires and zombies to the main lists.
    characterList.addAll(newHumans);
    characterList.addAll(newVampires);
    characterList.addAll(newZombies);

    view.showStatus(step, field);
  }
Ejemplo n.º 4
0
 /**
  * Run the simulation from its current state for the given number of steps. Stop before the given
  * number of steps if it ceases to be viable.
  *
  * @param numSteps The number of steps to run for.
  */
 public void simulate(int numSteps) {
   for (int step = 1; step <= numSteps && view.isViable(field); step++) {
     simulateOneStep();
   }
 }