Beispiel #1
0
  /**
   * Show the current status of the field.
   *
   * @param step Which iteration step it is.
   * @param field Which field to display
   */
  public void showStatus(int step, Field field) {
    if (!isVisible()) setVisible(true);

    stepLabel.setText(STEP_PREFIX + step);

    stats.reset();
    fieldView.preparePaint();

    for (int row = 0; row < field.getDepth(); row++) {
      for (int col = 0; col < field.getWidth(); col++) {
        Object creature;
        creature = field.getObjectAt(row, col);
        if (creature != null) {
          stats.incrementCount(creature.getClass());
          fieldView.drawMark(col, row, getColor(creature.getClass()));
        } else {
          fieldView.drawMark(col, row, EMPTY_COLOR);
        }
      }
    }
    stats.countFinished();

    population.setText(POPULATION_PREFIX + stats.getPopulationDetails(field));
    fieldView.repaint();
  }
Beispiel #2
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 #3
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.
     }
   }
 }