示例#1
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--;
         }
       }
     }
   }
 }
示例#2
0
 public void dropObject() {
   Random rand = new Random();
   Random rand2 = new Random();
   List<Location> free = field.getFreeLocations();
   for (Location next : free) {
     if (rand.nextInt(50) < 4) {
       switch (rand2.nextInt(4)) {
         case 0:
           new Food(field, next);
           break;
         case 1:
           new Ammo(field, next, 5);
           break;
         case 2:
           new ShotGun(5, 100, field, next);
           break;
         case 3:
           break;
       }
     }
   }
 }