|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectinfo.gridworld.actor.Actor
info.gridworld.actor.Critter
public class Critter
A Critter
is an actor that moves through its world, processing
other actors in some way and then picking a new location.
The implementation of this class is testable on the AP CS A and AB exams.
Constructor Summary | |
---|---|
Critter()
|
Method Summary | |
---|---|
void |
act()
A critter acts by getting a list of its neighbors, processing them, getting locations to move to, selecting one of them, and moving to the selected location. |
ArrayList<Actor> |
getActors()
Gets the actors for processing. |
ArrayList<Location> |
getMoveLocations()
Gets the possible locations for the next move. |
void |
makeMove(Location loc)
Moves this critter to the given location. |
void |
processActors(ArrayList<Actor> actors)
Processes selected actors. |
Location |
selectMoveLocation(ArrayList<Location> locs)
Selects the location for the next move. |
Methods inherited from class info.gridworld.actor.Actor |
---|
getColor, getDirection, getGrid, getLocation, moveTo, putSelfInGrid, removeSelfFromGrid, setColor, setDirection, toString |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public Critter()
Method Detail |
---|
public void act()
act
in class Actor
public ArrayList<Actor> getActors()
public void processActors(ArrayList<Actor> actors)
actors
are contained in the
same grid as this critter. actors
is unchanged. (2) The location of
this critter is unchanged.
actors
- the actors to be processedpublic ArrayList<Location> getMoveLocations()
public Location selectMoveLocation(ArrayList<Location> locs)
locs
has size 0. Override this method in subclasses that
have another mechanism for selecting the next move location. locs
are valid in the grid
of this critter. loc
is an element of locs
,
this Critter's current location, or null
. (2) The state
of all actors is unchanged.
locs
- the possible locations for the next move
public void makeMove(Location loc)
loc
is null
, and
to move to loc
otherwise. Override this method in
subclasses that want to carry out other actions (for example, turning
this critter or adding occupants in empty locations). loc
is valid in the grid of this critter or
null
.loc
. (2) The
state of all other actors is unchanged.
loc
- the location to move to
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |