|
Ant Farm - Robert Glen Martin School for the Talented and Gifted Dallas I.S.D. |
|||||||
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
WorkerAnt
public class WorkerAnt
A WorkerAnt
is a critter who's mission is
to take food from Cake and Cookie
objects and to
deliver it to a QueenAnt
object.
Initially it looks for food. After it finds food, it looks for
a queen.
Worker ants share the location of food and the queen
with other ants they encounter.
Worker ants with food are red. If they don't have food,
they are black.
Field Summary | |
---|---|
private info.gridworld.grid.Location |
foodLoc
Location of a Food object |
private int |
foodQuantity
Current amount of food being carried |
private info.gridworld.grid.Location |
queenLoc
Location of a QueenAnt object |
Constructor Summary | |
---|---|
WorkerAnt()
Constructs a WorkerAnt critter. |
Method Summary | |
---|---|
private int |
getDesiredDirecton()
Returns the direction that the ant wants to go. |
java.util.ArrayList<info.gridworld.grid.Location> |
getMoveLocations()
Gets the possible locations for the next move. |
int |
giveFood()
Gives food to the calling QueenAnt . |
void |
makeMove(info.gridworld.grid.Location loc)
Moves this critter to the given location, sets its direction, and sets its color (red = has food, black = does not have food). |
void |
process(WorkerAnt ant)
Gives current food and queen locations to ant . |
void |
processActors(java.util.ArrayList<info.gridworld.actor.Actor> actors)
Processes each of the neighboring Ant Farm actors. |
void |
shareFoodLocation(info.gridworld.grid.Location fLoc)
Receives the fLoc food location from a
Food object. |
void |
shareQueenLocation(info.gridworld.grid.Location qLoc)
Receives the qLoc queen location from a
QueenAnt object. |
void |
takeFood(int fQty)
Takes fQty amount of food from the
calling Food . |
java.lang.String |
toString()
Creates a string that describes this actor. |
Methods inherited from class info.gridworld.actor.Critter |
---|
act, getActors, selectMoveLocation |
Methods inherited from class info.gridworld.actor.Actor |
---|
getColor, getDirection, getGrid, getLocation, moveTo, putSelfInGrid, removeSelfFromGrid, setColor, setDirection |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
private int foodQuantity
private info.gridworld.grid.Location foodLoc
Food
object
private info.gridworld.grid.Location queenLoc
QueenAnt
object
Constructor Detail |
---|
public WorkerAnt()
WorkerAnt
critter.
It is originally black (no food) and
its direction is chosen randomly from the
eight normal cardinal directions.
Method Detail |
---|
public void process(WorkerAnt ant)
ant
.
process
in interface Processable
ant
- the calling WorkerAnt
public void takeFood(int fQty)
fQty
amount of food from the
calling Food
.
fQty
- the amount of food to take.public int giveFood()
QueenAnt
.
public void shareFoodLocation(info.gridworld.grid.Location fLoc)
fLoc
food location from a
Food
object. Saves this location if
it doesn't already have one.
fLoc
- the location of the food.public void shareQueenLocation(info.gridworld.grid.Location qLoc)
qLoc
queen location from a
QueenAnt
object. Saves this location if
it doesn't already have one.
qLoc
- the location of the queen.public void processActors(java.util.ArrayList<info.gridworld.actor.Actor> actors)
Cake and Cookie
actors,
give food to QueenAnt
actors, and to share locations
with other WorkerAnt
actors.actors
are contained in the same grid as this critter.
processActors
in class info.gridworld.actor.Critter
actors
- the actors to be processedpublic java.util.ArrayList<info.gridworld.grid.Location> getMoveLocations()
getMoveLocations
in class info.gridworld.actor.Critter
public void makeMove(info.gridworld.grid.Location loc)
loc
is valid in the grid of this critter
makeMove
in class info.gridworld.actor.Critter
loc
- the location to move to (must be valid)private int getDesiredDirecton()
public java.lang.String toString()
toString
in class info.gridworld.actor.Actor
Actor
information
plus the current amount of food and any known
Food
and QueenAnt
locations.
|
© 2007 Robert Glen Martin. All rights reserved. |
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |