public class Maze
extends java.lang.Object
Maze
is the main public class through which methods
clients can explore a maze.
A Maze
object represents a connected graphs that can
be explored incrementally. Every node in the graph represents a
cell, which can be thought as a room in the maze. Every
node has an identifier — an integer whose value is unique
within the maze. Node identifiers are generated randomly at every
object creation, and thus they are not persistent or deterministic.
Exploration of a maze begins at the start node, whose identifier
is returned by method start
. Given the identifier
of a node, method neighbors
returns the set of
identifiers of all nodes adjacent to it. Method
hasGoal
determines if a given node contains a goal.
Finally, methods spawn
and move
animate
icons of players that move around the maze in its graphical
representation.
Modifier and Type | Method and Description |
---|---|
boolean |
hasGoal(int id)
Tests whether a given node contains a goal.
|
void |
move(int playerId,
int id)
Moves an existing animated player to a given node.
|
java.util.Set<java.lang.Integer> |
neighbors(int id)
Returns the set of the identifiers of all nodes directly
adjacent to a given node, and accessible from it.
|
int |
newPlayer(int id)
Creates a new animated player, and place it on a given node.
|
int |
start()
Returns the unique identifier of the start node, corresponding
to the top-left cell in the maze.
|
public int start()
public java.util.Set<java.lang.Integer> neighbors(int id)
id
- the identifier of a node in the mazeid
's neighborhoodpublic boolean hasGoal(int id)
id
- the identifier of a node in the mazetrue
if the node with identifier id
is a goal;
false
otherwisepublic int newPlayer(int id)
id
- the identifier of a node in the maze where the new player is placedpublic void move(int playerId, int id)
playerId
- the identifier of an existing playerid
- a node in the maze where the player is moved