Class Maze
java.lang.Object
|
+--Maze
- public class Maze
- extends Object
Don't panic! You don't have to understand the implementation of
this class.
Class Maze
describes a maze of
height * width rooms. The implementation of the class is
rather complicated. Class Maze
is only used in the
main programs Main1-Main4
and you don't have to create
any new mazes, nor use any methods of the class.
Constructor Summary |
Maze(int width,
int height)
Constructs a height*width maze. |
Method Summary |
boolean |
connectRooms(int x1,
int y1,
int x2,
int y2)
This is a rather complicated method that connects several rooms
simultaneously by making several doors. |
Room |
getRoom(int x,
int y)
Retrieves a room of the maze at coordinates (x, y). |
boolean |
makeDoor(int x,
int y,
int direction)
Makes a door to the given direction in room (x, y). |
void |
print()
Prints the maze on the terminal. |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
Maze
public Maze(int width,
int height)
- Constructs a height*width maze. Initially, the rooms
of the maze have no doors to other rooms.
- Parameters:
width
- the width of the mazeheight
- the height of the maze
getRoom
public Room getRoom(int x,
int y)
- Retrieves a room of the maze at coordinates (x, y).
- Parameters:
x
- the x coordinate of the room; 0 <= x < width.y
- the y coordinate of the room; 0 <= y < height.- Returns:
- the room at position (x, y).
makeDoor
public boolean makeDoor(int x,
int y,
int direction)
- Makes a door to the given direction in room (x, y). Note
that all doors are not possible in the border of the maze.
- Parameters:
x
- the x coordinate of the room; 0 <= x < width.y
- the y coordinate of the room; 0 <= y < height.direction
- the direction of the new door.- Returns:
true
if the door could be made and
false
if the door was not possible.
connectRooms
public boolean connectRooms(int x1,
int y1,
int x2,
int y2)
- This is a rather complicated method that connects several rooms
simultaneously by making several doors. The coordinates
(x1, y1) and (x2, y2) define a rectangle.
All rooms inside the rectangle are connected to their neighbors
inside the rectangle by doors.
- Parameters:
x1
- the x1 coordinate of the room; 0 <= x1 <
width.y1
- the y1 coordinate of the room; 0 <= y1 <
height.x2
- the x2 coordinate of the room; 0 <= x2 <
width.y2
- the y2 coordinate of the room; 0 <= y2 <
height.- Returns:
true
if all doors could be made and
false
if some doors were not possible.
print
public void print()
- Prints the maze on the terminal. We use simple ASCII graphics.
The walls of the rooms are drawn by using letters '-', '|', and
'+'. The objects that the rooms contain are drawn by using the
labels of the objects.