|
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 | +--SquareEnvironment
AP® Computer Science Marine Biology Simulation:
SquareEnvironment
is an abstract class that implements
only the navigational methods in the Environment
interface.
It considers the cells in the environment to be square, with sides
to the north, south, east, and west, and navigates accordingly.
The SquareEnvironment
class is
copyright© 2002 College Entrance Examination Board
(www.collegeboard.com).
Direction
,
Location
Constructor Summary | |
SquareEnvironment()
Constructs a SquareEnvironment object in which cells
have four adjacent neighbors -- those with which they share sides. |
|
SquareEnvironment(boolean includeDiagonalNeighbors)
Constructs a SquareEnvironment object in which cells
have four or eight adjacent neighbors, depending on the value
of the includeDiagonalNeighbors parameter. |
Method Summary | |
Direction |
getDirection(Location fromLoc,
Location toLoc)
Returns the direction from one location to another. |
Location |
getNeighbor(Location fromLoc,
Direction compassDir)
Returns the adjacent neighbor (whether valid or invalid) of a location in the specified direction. |
java.util.ArrayList |
neighborsOf(Location ofLoc)
Returns the adjacent neighbors of a specified location. |
int |
numAdjacentNeighbors()
Returns the number of adjacent neighbors around each cell. |
int |
numCellSides()
Returns the number of sides around each cell. |
Direction |
randomDirection()
Generates a random direction. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface Environment |
add, allObjects, isEmpty, isValid, numCols, numObjects, numRows, objectAt, recordMove, remove |
Constructor Detail |
public SquareEnvironment()
SquareEnvironment
object in which cells
have four adjacent neighbors -- those with which they share sides.
These neighbors are in the four cardinal directions.public SquareEnvironment(boolean includeDiagonalNeighbors)
SquareEnvironment
object in which cells
have four or eight adjacent neighbors, depending on the value
of the includeDiagonalNeighbors
parameter. If
includeDiagonalNeighbors
is true
, cells
have eight adjacent neighbors -- the immediately adjacent neighbors
on all four sides and the four neighbors on the diagonals.
If includeDiagonalNeighbors
is false
,
cells have only the four neighbors they would have in an environment
created with the default SquareEnvironment
constructor.includedDiagonalNeighbors
- whether to include the four
diagonal locations as neighborsMethod Detail |
public int numCellSides()
numCellSides
in interface Environment
public int numAdjacentNeighbors()
numAdjacentNeighbors
in interface Environment
public Direction randomDirection()
randomDirection
reflects the direction from
a cell in the environment to one of its adjacent neighbors.randomDirection
in interface Environment
public Direction getDirection(Location fromLoc, Location toLoc)
fromLoc
and toLoc
are the same,
getDirection
arbitrarily returns Direction.NORTH
.getDirection
in interface Environment
fromLoc
- starting location for searchtoLoc
- destination locationfromLoc
to toLoc
public Location getNeighbor(Location fromLoc, Direction compassDir)
getNeighbor
in interface Environment
fromLoc
- starting location for searchcompassDir
- direction in which to look for adjacent neighborfromLoc
in given direction
(whether valid or not)public java.util.ArrayList neighborsOf(Location ofLoc)
neighborsOf
in interface Environment
ofLoc
- location whose neighbors to getofLoc
|
AP® Computer Science Marine Biology Simulation | |||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |