|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectvitro.Model
vitro.grid.Grid
public class Grid
Grid is a Model implementation representing space as a two-dimensional rectangular grid. Multiple Actors can exist in the same grid cell at once by default, but this behavior can be modified by overriding the passable() predicates.
Field Summary | |
---|---|
static int[][] |
ADJACENT
A set of x/y deltas for vertically, horizontally and diagonally adjacent cells. |
static int[][] |
DIAGONAL
A set of x/y deltas for diagonally adjacent cells. |
int |
height
The height of the Grid in cells. |
Map<Actor,Location> |
locations
A mapping from Actors in this Model to the Grid cell in which they are currently located. |
protected Grid |
model
A reference to the current Model. |
static int[][] |
ORTHOGONAL
A set of x/y deltas for vertically or horizontally adjacent cells. |
int |
width
The width of the Grid in cells. |
Fields inherited from class vitro.Model |
---|
actors |
Constructor Summary | |
---|---|
Grid(int width,
int height)
Create a new Grid with a specified size. |
Method Summary | |
---|---|
Actor |
actorAt(Location location)
Find the first Actor at a given Location. |
Set<Actor> |
actorsAt(Location location)
Find all Actors at a given Location. |
Set<Actor> |
actorsAt(Set<Location> locations)
Find all Actors in a group of Locations. |
Set<Location> |
allCells()
Obtain references to all cells on the Grid. |
Set<Location> |
emptyCells()
Obtain references to all cells on the Grid which contain no Actors. |
Set<Location> |
neighbors(Location location,
int[][] deltas)
Obtain references to Location objects representing neighboring cells. |
boolean |
passable(Actor actor,
Location location)
Check the passability of a given Location with respect to a given Actor. |
Set<Location> |
passable(Actor actor,
Set<Location> locations)
Find the Locations that a given Actor could move to. |
Set<Location> |
passableNeighbors(Actor actor,
int[][] deltas)
Performs the same function as neighbors(), but only returns Locations which would be passable to a specified Actor. |
Set<Location> |
passableNeighbors(Location location,
int[][] deltas)
Performs the same function as neighbors(), but only returns Locations which would be passable to any Actor. |
void |
put(Actor actor,
int x,
int y)
Place a new Actor at a specified Location. |
Methods inherited from class vitro.Model |
---|
cleanup, done |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected final Grid model
public final int width
public final int height
public final Map<Actor,Location> locations
public static final int[][] ORTHOGONAL
public static final int[][] DIAGONAL
public static final int[][] ADJACENT
Constructor Detail |
---|
public Grid(int width, int height)
width
- the width of the Grid in cells.height
- the height of the Grid in cells.Method Detail |
---|
public void put(Actor actor, int x, int y)
actor
- the Actor to place in the grid.x
- the column in which to place the Actor.y
- the row in which to place the Actor.public Set<Location> neighbors(Location location, int[][] deltas)
location
- the origin Location.deltas
- a collection of x and y offsets to neighboring cells.
public Set<Location> passableNeighbors(Actor actor, int[][] deltas)
actor
- the actor to consider movingdeltas
- a collection of x and y offsets to neighboring cells.
public Set<Location> passableNeighbors(Location location, int[][] deltas)
location
- the origin Location.deltas
- a collection of x and y offsets to neighboring cells.
public Actor actorAt(Location location)
location
- the Location to check for Actors.
public Set<Actor> actorsAt(Location location)
location
- the Location to check for Actors.
public Set<Actor> actorsAt(Set<Location> locations)
locations
- a set of Locations to check for Actors.
public Set<Location> allCells()
public Set<Location> emptyCells()
public boolean passable(Actor actor, Location location)
actor
- the Actor to consider.location
- the Location to consider.
public Set<Location> passable(Actor actor, Set<Location> locations)
actor
- the Actor to consider.locations
- a set of Locations to consider.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |