/** * Place the grass at the new location in the given field. * * @param newLocation The grass' new location. */ public void setLocation(Location newLocation) { if (location != null) { field.clear(location); } location = newLocation; field.place(this, newLocation); }
/** * Grows new grass on the free locations * * @param newGrass The list of new grass */ public void grow(List<Actor> newGrass) { Field field = getField(); List<Location> free = field.getFreeAdjacentLocations(getLocation()); for (int b = 0; b < growGrass() && free.size() > 0; b++) { Location loc = free.remove(0); newGrass.add(new Grass(field, loc)); } }
/** * Check whether or not this rabbit is to give birth at this step. New births will be made into * free adjacent locations. * * @param newRabbits A list to return newly born rabbits. */ public void giveBirth(List<Actor> newRabbits) { Field field = getField(); List<Location> free = field.getFreeAdjacentLocations(getLocation()); int births = breed(); for (int b = 0; b < births && free.size() > 0; b++) { Location loc = free.remove(0); Rabbit young = new Rabbit(false, field, loc); newRabbits.add(young); } }
/** Kills the grass */ public void setDead() { alive = false; if (location != null) { field.clear(location); location = null; field = null; } }
/** * 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; }
/** 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(); } } } } } } }
@Override public void markField(Field firstField, Field secondField, Field thirdField, Player player) { thirdField.mark(player); }