Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.45 KB | None | 0 0
  1. import java.awt.Color;
  2. import java.util.ArrayList;
  3. import info.gridworld.grid.Grid;
  4. import info.gridworld.grid.Location;
  5. import info.gridworld.actor.Actor;
  6. import info.gridworld.actor.Critter;
  7. import info.gridworld.actor.Rock;
  8.  
  9. /**
  10.  * ZombieCritter:an infected critter that can spread the infection to a healthyCritter().
  11.  * @author Kevin Hopkins
  12.  * @version February 3rd, 2011
  13.  */
  14.  
  15.  
  16. public class ZombieCritter extends Critter
  17. {
  18.    
  19.     /**
  20.      * Creates a red ZombieCritter.
  21.      */
  22.     public ZombieCritter()
  23.     {
  24.         setColor(Color.RED);
  25.     }
  26.    
  27.     /**
  28.      *
  29.      */
  30.     public void processActors(ArrayList<Actor> actors)
  31.     {
  32.         int n = actors.size();
  33.         if(n == 0)
  34.         {
  35.             removeSelfFromGrid();
  36.         }    
  37.  
  38.         for (Actor a : actors)
  39.         {
  40.             if (a instanceof Rock)
  41.                 a.removeSelfFromGrid();
  42.         }
  43.        
  44.     }
  45.    
  46.     /**
  47.      *
  48.      */
  49.     public ArrayList<HealthyCritter> getHealthyCritters()
  50.     {
  51.         Grid<Actor> gr = getGrid();
  52.         Actor a;
  53.         ArrayList<Location> occ = gr.getOccupiedLocations();
  54.         ArrayList<Actor> healthyCritters = new ArrayList<HealthyCritter>();
  55.         for (Location loc : occ)
  56.         {
  57.             a = gr.get(loc);
  58.             if (a instanceof HealthyCritter)
  59.             {
  60.                 healthyCritters.add(a);
  61.             }
  62.         }
  63.        
  64.         return healthyCritters;
  65.     }
  66.  
  67.     /**
  68.      *
  69.      */
  70.     public Location selectHealthyCritter()
  71.     {
  72.         int n = getHealthyCritters().size();
  73.         int r = (int)(Math.random() * n);
  74.         return healthyCritters.getLocation(r);
  75.     }
  76.    
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement