Marine Biology Simulation Quick Reference Sheet
BoundedGrid (Grid Package)
BoundedGrid
Constructors | |
---|---|
public BoundedGrid(int rows, int cols)
| Constructs an empty grid with the specified dimensions; each cell has 4 neighbors. |
public BoundedGrid(boolean includeDiagonals, int rows,
int cols)
| Constructs an empty grid with the specified dimensions;
if includeDiagonals is true , each
cell has 8 neighbrs.
|
Accessor methods dealing with grid dimensions, locations, and navigation | |
public int numRows()
| Returns number of rows in grid. |
public int numCols()
| Returns number of columns in grid. |
public boolean isEmpty(Location loc)
| Returns true if loc is a
valid location in this grid and is empty; otherwise returns
false .
|
public boolean isValid(Location loc)
| Returns true if loc is a
valid location in this grid; otherwise returns
false .
|
public Direction randomDirection()
| Generates a random direction. |
public Direction getDirection(Location fromLoc, Location
toLoc)
| Returns the direction from one location to another. |
public Location getNeighbor(Location fromLoc, Direction
compassDir)
| Returns the adjacent neighbor of a location in the specified direction. |
public ArrayList
| Returns a list of the neighbors to the north, south, east, and west of the given location |
Methods to add/retrieve/remove objects | |
public void add(GridObject obj, Location loc)
| Adds the specified object to the grid at the specified location. |
public GridObject objectAt(Location loc)
| Returns the object at location loc
|
public void remove(Location loc)
| Removes whatever object is at the specified location in this grid. |
Location and Direction (Grid Package)
Location
public Location(int row, int col)
| Constructs a location object with the specified row and column. |
public int row()
| Returns the row associated with this location. |
public int col()
| Returns the column associated with this location. |
Direction
Useful named constants | |
---|---|
Direction.NORTH, Direction.SOUTH, Direction.EAST,
Direction.WEST
| |
Direction.NORTHEAST, Direction.NORTHWEST,
Direction.SOUTHEAST, Direction.SOUTHWEST
|
Fish (MBS; highlighted methods are inherited from GridObject)
Fish
Constructors | |
---|---|
public Fish(Grid env, Location loc)
| Constructs a fish at the specified location in a given environment. |
public Fish(Grid env, Location loc, Direction dir)
| Constructs a fish at the specified location and direction in a given environment. |
public Fish(Grid env, Location loc, Direction dir, Color col)
| Constructs a fish of the specified color at the specified location and direction. |
Accessor methods | |
public int id()
| Returns this fish's ID. |
public Color color()
| Returns this fish's color. |
public boolean isInAGrid()
| Checks whether this object is in a grid. (inherited from GridObject) |
public Grid grid()
| Returns the grid in which this grid object exists. (inherited from GridObject) |
public Location location()
| Returns this fish's location. (inherited from GridObject) |
public Direction direction()
| Returns this fish's direction. |
public String toString()
| Returns a string representing key information about
this fish.
(redefines behavior in
GridObject )
|
Action and modifier methods | |
public void act()
| Acts for one step in the simulation.
(redefines behavior in
GridObject )
|
Protected helper methods used by public methods | |
protected void addToGrid(Grid grid, Location loc)
| Adds this object to the specified grid at the specified location. (used indirectly by constructor) (inherited from GridObject) |
protected void move()
| Moves this fish in its environment.
(used by act method)
|
protected Location nextLocation()
| Returns the row associated with this location.
(used by move method)
|
protected ArrayList
| Finds empty locations adjacent to this fish.
(used indirectly by move method)
|
protected void changeLocation(Location newLoc)
| Modifies this fish's location and
notifies the grid. (used by move method)
(inherited from GridObject)
|
protected void changeDirection(Direction newDir)
| Modifies this fish's direction.
(used by move method)
|