Example #1
0
 /**
  * Look for grass adjacent to the current location. Only the first live grass is eaten.
  *
  * @return Where food was found, or null if it wasn't.
  */
 public Location findFood(Location location) {
   Field field = getField();
   List<Location> adjacent = field.adjacentLocations(getLocation());
   Iterator<Location> it = adjacent.iterator();
   while (it.hasNext()) {
     Location where = it.next();
     Object actor = field.getObjectAt(where);
     if (actor instanceof Grass) {
       Grass grass = (Grass) actor;
       if (grass.isActive()) {
         grass.setDead();
         BarView.incrementEaten();
         foodLevel = foodValue;
         return where;
       }
     }
   }
   return null;
 }
Example #2
0
 /** spreads the sickness of the rabbits */
 public void spreadSickness() {
   Random rand = Randomizer.getRandom();
   if ((rand.nextInt(100 - 0) + 1) < ziekteKansPercentage) {
     if (this.ziekteGen) {
       Field field = getField();
       Location location = getLocation();
       if (location != null) {
         List<Location> adjacent = field.adjacentLocations(location);
         Iterator<Location> it = adjacent.iterator();
         while (it.hasNext()) {
           Location where = it.next();
           Object actor = field.getObjectAt(where);
           if (actor instanceof Rabbit) {
             Rabbit r = (Rabbit) actor;
             if (r.isActive()) {
               r.setZiekte();
             }
           }
         }
       }
     }
   }
 }