Class DarterFish
java.lang.Object
|
+--Fish
|
+--DarterFish
- All Implemented Interfaces:
- Locatable
- public class DarterFish
- extends Fish
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.
| Methods inherited from class Fish |
act, changeDirection, changeLocation, color, 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 |
DarterFish
public DarterFish(Environment env,
Location loc)
- Constructs a darter fish at the specified location in a
given environment. This darter is colored yellow.
(Precondition: parameters are non-null;
loc is valid
for env.)
- Parameters:
env - environment in which fish will liveloc - location of the new fish in env
DarterFish
public DarterFish(Environment env,
Location loc,
Direction dir)
- Constructs a darter fish at the specified location and direction in a
given environment. This darter is colored yellow.
(Precondition: parameters are non-null;
loc and
dir are valid for env.)
- Parameters:
env - environment in which fish will liveloc - location of the new fish in envdir - direction the new fish is facing
DarterFish
public 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.
(Precondition: parameters are non-null;
loc and
dir are valid for env.)
- Parameters:
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
generateChild
protected void generateChild(Location loc)
- Creates a new darter fish.
- Parameters:
loc - location of the new fish
move
protected void move()
- Moves this fish in its environment.
A darter fish darts forward (as specified in nextLocation) if
possible, or reverses direction (without moving) if it cannot move
forward.
- Overrides:
move in class Fish
nextLocation
protected Location nextLocation()
- Finds this fish's next location.
A darter fish darts forward two spaces if it can, otherwise it
tries to move forward one space. A darter fish can only move
to empty locations, and it can only move two spaces forward if
the intervening space is empty. If the darter fish cannot move
forward,
nextLocation returns the fish's current
location.
- Overrides:
nextLocation in class Fish
- Returns:
- the next location for this fish