Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Color;
- import java.util.ArrayList;
- import info.gridworld.grid.Grid;
- import info.gridworld.grid.Location;
- import info.gridworld.actor.Actor;
- import info.gridworld.actor.Critter;
- import info.gridworld.actor.Rock;
- /**
- * ZombieCritter:an infected critter that can spread the infection to a healthyCritter().
- * @author Kevin Hopkins
- * @version February 3rd, 2011
- */
- public class ZombieCritter extends Critter
- {
- /**
- * Creates a red ZombieCritter.
- */
- public ZombieCritter()
- {
- setColor(Color.RED);
- }
- /**
- *
- */
- public void processActors(ArrayList<Actor> actors)
- {
- int n = actors.size();
- if(n == 0)
- {
- removeSelfFromGrid();
- }
- for (Actor a : actors)
- {
- if (a instanceof Rock)
- a.removeSelfFromGrid();
- }
- }
- /**
- *
- */
- public ArrayList<HealthyCritter> getHealthyCritters()
- {
- Grid<Actor> gr = getGrid();
- Actor a;
- ArrayList<Location> occ = gr.getOccupiedLocations();
- ArrayList<Actor> healthyCritters = new ArrayList<HealthyCritter>();
- for (Location loc : occ)
- {
- a = gr.get(loc);
- if (a instanceof HealthyCritter)
- {
- healthyCritters.add(a);
- }
- }
- return healthyCritters;
- }
- /**
- *
- */
- public Location selectHealthyCritter()
- {
- int n = getHealthyCritters().size();
- int r = (int)(Math.random() * n);
- return healthyCritters.getLocation(r);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement