public class Critter extends Actor
Critter
is an actor that moves through its world, processing
other actors in some way and then moving to a new location. Define your own
critters by extending this class and overriding any methods of this class
except for act
. When you override these methods, be sure to
preserve the postconditions. Constructor and Description |
---|
Critter() |
Modifier and Type | Method and Description |
---|---|
void |
act()
A critter acts by getting a list of other actors, processing that list,
getting locations to move to, selecting one of them, and moving to the
selected location.
|
java.util.ArrayList<Actor> |
getActors()
Gets the actors for processing.
|
java.util.ArrayList<Location> |
getMoveLocations()
Gets a list of possible locations for the next move.
|
void |
makeMove(Location loc)
Moves this critter to the given location
loc , or removes
this critter from its grid if loc is null . |
void |
processActors(java.util.ArrayList<Actor> actors)
Processes the elements of
actors . |
Location |
selectMoveLocation(java.util.ArrayList<Location> locs)
Selects the location for the next move.
|
getColor, getDirection, getGrid, getLocation, moveTo, putSelfInGrid, removeSelfFromGrid, setColor, setDirection, toString
public void act()
public java.util.ArrayList<Actor> getActors()
public void processActors(java.util.ArrayList<Actor> actors)
actors
. New actors may be added
to empty locations. Implemented to "eat" (i.e. remove) selected actors
that are not rocks or critters. Override this method in subclasses to
process actors in a different way. actors
is unchanged. (2) The
location of this critter is unchanged.actors
- the actors to be processedpublic java.util.ArrayList<Location> getMoveLocations()
public Location selectMoveLocation(java.util.ArrayList<Location> locs)
locs
has size 0. Override this method in subclasses that
have another mechanism for selecting the next move location. locs
, this critter's current location, or
null
. (2) The state of all actors is unchanged.locs
- the possible locations for the next movepublic void makeMove(Location loc)
loc
, or removes
this critter from its grid if loc
is null
.
An actor may be added to the old location. If there is a different actor
at location loc
, that actor is removed from the grid.
Override this method in subclasses that want to carry out other actions
(for example, turning this critter or adding an occupant in its previous
location). getLocation() == loc
. (2) The state of
all actors other than those at the old and new locations is unchanged.loc
- the location to move to