protected static class BoundedGrid.Array2DGridRep extends java.lang.Object implements Grid.InternalRepresentation
Array2DGridRep class represents an internal bounded
grid using a two-dimensional array.| Constructor and Description |
|---|
Array2DGridRep(int rows,
int cols)
Constructs an empty Array2DGridRep representation with the given
dimensions.
|
| Modifier and Type | Method and Description |
|---|---|
void |
add(GridObject obj)
Adds a new object to this internal grid representation at the
location it specifies.
|
GridObject[] |
allObjects()
Returns all the objects in this grid.
|
boolean |
isValid(Location loc)
Verifies whether a location is valid in this grid.
|
int |
numCols()
Returns number of columns in this grid.
|
int |
numObjects()
Returns the number of objects in this grid.
|
int |
numRows()
Returns number of rows in this grid.
|
GridObject |
objectAt(Location loc)
Returns the object at a specific location in this grid.
|
void |
remove(GridObject obj)
Removes the object from this internal grid representation.
|
public Array2DGridRep(int rows,
int cols)
rows > 0 and cols > 0.)rows - number of rows in the gridcols - number of columns in the gridpublic int numRows()
public int numCols()
public boolean isValid(Location loc)
isValid in interface Grid.InternalRepresentationloc - location to checktrue if loc is valid;
false otherwisepublic int numObjects()
numObjects in interface Grid.InternalRepresentationpublic GridObject[] allObjects()
allObjects in interface Grid.InternalRepresentationpublic GridObject objectAt(Location loc)
objectAt in interface Grid.InternalRepresentationloc - the location in which to lookloc;
null if loc is not
in the grid or is emptypublic void add(GridObject obj)
obj.grid() is this grid and
obj.location() is a valid empty location;
verified by the Grid object.)add in interface Grid.InternalRepresentationobj - the new object to be addedpublic void remove(GridObject obj)
obj is in this grid; verified
by the Grid object.)remove in interface Grid.InternalRepresentationobj - the object to be removed