- /**
- * A class that symbolizes a spy in search for the "top secret file" object. It will fight with the other spy if encountered. It will also become hurt if it touches with traps.
- *
- * @author Juan Alvarez
- * @version 3/18/2010
- */
- import info.gridworld.actor.Actor;
- import info.gridworld.actor.Critter;
- import info.gridworld.grid.Location;
- import info.gridworld.grid.Grid;
- import info.gridworld.actor.Bug;
- import java.awt.Color;
- import java.util.ArrayList;
- import java.util.*;
- public class WhiteSpy extends Critter
- {
- public int wHealth;
- public WhiteSpy()
- {
- wHealth = 100;
- setColor(Color.WHITE);
- }
- /**
- * A spy gets the actors in front of it
- * Removes health if it is in front and adds 10 to wHealth
- * - 5 wHealth if Trap is in front
- * - 15 wHealth if superTrap is in front
- * -20 wHealth if BlackSpy is in front
- * @return a list of actors occupying these locations
- */
- public ArrayList<Actor> getActor()
- {
- ArrayList<Actor> actors = new ArrayList<Actor>();
- int[] dirs =
- { Location.AHEAD};
- for (Location loc : getLocationsInDirections(dirs))
- {
- Actor a = getGrid().get(loc);
- if (a instanceof Health){
- Health.removeSelfFromGrid();
- wHealth = wHealth + 10;}
- if (a instanceof BlackSpy)
- bHealth = bHealth - 20;
- if (a instanceof Trap)
- wHealth = wHealth - 5;
- if (a instanceof SuperTrap)
- wHealth = wHealth - 15;
- if (a instanceof TopSecretFile)
- System.out.println("THE WHITE SPY WINS!");
- }
- return actors;
- }
- /**
- * Finds the valid adjacent locations of this critter in different
- * directions.
- * @param directions - an array of directions (which are relative to the
- * current direction)
- * @return a set of valid locations that are neighbors of the current
- * location in the given directions
- */
- public ArrayList<Location> getLocationsInDirections(int[] directions)
- {
- ArrayList<Location> locs = new ArrayList<Location>();
- Grid gr = getGrid();
- Location loc = getLocation();
- for (int d : directions)
- {
- Location neighborLoc = loc.getAdjacentLocation(getDirection() + d);
- if (gr.isValid(neighborLoc))
- locs.add(neighborLoc);
- }
- return locs;
- }
