Package se.lth.cs.pt.maze
Class Maze
java.lang.Object
se.lth.cs.pt.maze.Maze
Describes a maze. The maze definition is read from a file.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
atExit
(int x, int y) Checks if the point x,y is at (or near) the exit.void
draw
(SimpleWindow w) Draws the maze in a window.int
Returns the x coordinate of the entry point.int
Returns the y coordinate of the entry point.boolean
wallAtLeft
(int direction, int x, int y) Check if you, when you're in x,y and heading in a given direction, have a wall directly to the left.boolean
wallInFront
(int direction, int x, int y) Check if you, when you're in x,y and heading in a given direction, have a wall directly in front.
-
Constructor Details
-
Maze
public Maze(int nbr) Creates a maze with number nbr. The maze definition is read from the file mazeN.maze (N: 1..6), which must be in cs_pt.jar, which must be on the class path.- Parameters:
nbr
- the number of the maze
-
Maze
Creates a maze based on an image file (.png or .jpg).- Parameters:
filename
- name of image filexEntry
- x coordinate of the maze's entry pointyEntry
- y coordinate of the maze's entry point
-
-
Method Details
-
draw
Draws the maze in a window.- Parameters:
w
- the SimpleWindow to draw in
-
getXEntry
public int getXEntry()Returns the x coordinate of the entry point.- Returns:
- the x coordinate
-
getYEntry
public int getYEntry()Returns the y coordinate of the entry point.- Returns:
- the y coordinate
-
atExit
public boolean atExit(int x, int y) Checks if the point x,y is at (or near) the exit.- Parameters:
x
- the x coordinatey
- the y coordinate- Returns:
- true if the point is at the exit, false otherwise
-
wallAtLeft
public boolean wallAtLeft(int direction, int x, int y) Check if you, when you're in x,y and heading in a given direction, have a wall directly to the left.- Parameters:
direction
- the direction (0, 90, 180, 270 degrees)x
- the x coordinatey
- the y coordinate- Returns:
- true if there's a wall directly to the left, false otherwise
-
wallInFront
public boolean wallInFront(int direction, int x, int y) Check if you, when you're in x,y and heading in a given direction, have a wall directly in front.- Parameters:
direction
- the direction (0, 90, 180, 270 degrees)x
- the x coordinatey
- the y coordinate- Returns:
- true if there's a wall directly in front, false otherwise
-