|
AP® Computer Science Marine Biology Simulation | |||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||
java.lang.Object
|
+--Fish
|
+--DarterFish
AP® Computer Science Marine Biology Simulation:
The DarterFish class represents a fish in the Marine
Biology Simulation that darts forward two spaces if it can, moves
forward one space if it can't move two, and reverses direction
(without moving) if it cannot move forward. It can only "see" an
empty location two cells away if the cell in between is empty also.
In other words, if both the cell in front of the darter and the cell
in front of that cell are empty, the darter fish will move forward
two spaces. If only the cell in front of the darter is empty, it
will move there. If neither forward cell is empty, the fish will turn
around, changing its direction but not its location.
DarterFish objects inherit instance variables and much
of their behavior from the Fish class.
The DarterFish class is
copyright© 2002 College Entrance Examination Board
(www.collegeboard.com).
| Constructor Summary | |
DarterFish(Environment env,
Location loc)
Constructs a darter fish at the specified location in a given environment. |
|
DarterFish(Environment env,
Location loc,
Direction dir)
Constructs a darter fish at the specified location and direction in a given environment. |
|
DarterFish(Environment env,
Location loc,
Direction dir,
java.awt.Color col)
Constructs a darter fish of the specified color at the specified location and direction. |
|
| Method Summary | |
protected void |
generateChild(Location loc)
Creates a new darter fish. |
protected void |
move()
Moves this fish in its environment. |
protected Location |
nextLocation()
Finds this fish's next location. |
| Methods inherited from class Fish |
act, breed, changeDirection, changeLocation, color, die, direction, emptyNeighbors, environment, id, isInEnv, location, randomColor, toString |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
public DarterFish(Environment env,
Location loc)
loc is valid
for env.)env - environment in which fish will liveloc - location of the new fish in env
public DarterFish(Environment env,
Location loc,
Direction dir)
loc
is valid for env.)env - environment in which fish will liveloc - location of the new fish in envdir - direction the new fish is facing
public DarterFish(Environment env,
Location loc,
Direction dir,
java.awt.Color col)
loc is valid
for env.)env - environment in which fish will liveloc - location of the new fish in envdir - direction the new fish is facingcol - color of the new fish| Method Detail |
protected void generateChild(Location loc)
generateChild in class Fishloc - location of the new fishprotected void move()
nextLocation)
if possible, or reverses direction (without moving) if it cannot move
forward.move in class Fishprotected Location nextLocation()
nextLocation returns the fish's current
location.nextLocation in class Fish
|
AP® Computer Science Marine Biology Simulation | |||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||