/**
  * Place the animal at the new location in the given field.
  *
  * @param newLocation The animal's new location.
  */
 protected void setLocation(Location newLocation) {
   if (location != null) {
     field.clear(location);
   }
   location = newLocation;
   field.place(this, newLocation);
 }
 /** Indicate that the animal is no longer alive. It is removed from the field. */
 protected void setDead() {
   alive = false;
   if (location != null) {
     field.clear(location);
     location = null;
     field = null;
   }
 }
Beispiel #3
0
 /** Randomly populate the field with foxes and rabbits. */
 private void populate() {
   Random rand = new Random();
   field.clear();
   for (int row = 0; row < field.getDepth(); row++) {
     for (int col = 0; col < field.getWidth(); col++) {
       if (rand.nextInt(120) <= HUMAN_CREATION_PROBABILITY) {
         if (nbHumans > 0) {
           Location location = new Location(row, col);
           Human h = new Human("Human" + row + col, HP_HUMANS, location, field);
           characterList.add(h);
           nbHumans--;
           switch (rand.nextInt(4)) {
             case 0:
               ShotGun weapon = new ShotGun(5, 2, field, location);
               h.setWeapon(weapon);
               break;
             case 1:
               LiquidNitrogen weapon1 = new LiquidNitrogen(2, field, location);
               h.setWeapon(weapon1);
               break;
             case 2:
               WoodenStake weapon2 = new WoodenStake(field, location);
               h.setWeapon(weapon2);
               break;
             default:
               break;
           }
         }
       } else if (rand.nextInt(120) <= ZOMBIE_CREATION_PROBABILITY) {
         if (nbZombies > 0) {
           Location location = new Location(row, col);
           Zombie z = new Zombie("Zombie" + row + col, HP_ZOMBIES, location, field);
           characterList.add(z);
           nbZombies--;
         }
       } else if (rand.nextInt(120) <= VAMPIRE_CREATION_PROBABILITY) {
         Location location = new Location(row, col);
         Vampire v = new Vampire("Vampire", HP_VAMPIRES, location, field);
         characterList.add(v);
       } else if (rand.nextInt(1000) <= MADZOMBIE_CREATION_PROBABILITY) {
         if (nbMadZombies > 0) {
           Location location = new Location(row, col);
           MadZombie mz = new MadZombie("Mad Zombie" + row + col, HP_ZOMBIES, location, field);
           characterList.add(mz);
           nbMadZombies--;
         }
       }
     }
   }
 }
Beispiel #4
0
 /** Randomly populate the field with foxes and rabbits. */
 private void populate() {
   Random rand = Randomizer.getRandom();
   field.clear();
   for (int row = 0; row < field.getDepth(); row++) {
     for (int col = 0; col < field.getWidth(); col++) {
       if (rand.nextDouble() <= FOX_CREATION_PROBABILITY) {
         Location location = new Location(row, col);
         Fox fox = new Fox(true, field, location);
         foxes.add(fox);
       } else if (rand.nextDouble() <= RABBIT_CREATION_PROBABILITY) {
         Location location = new Location(row, col);
         Rabbit rabbit = new Rabbit(true, field, location);
         rabbits.add(rabbit);
       }
       // else leave the location empty.
     }
   }
 }