Class Maze

java.lang.Object
se.lth.cs.pt.maze.Maze

public class Maze extends Object
Describes a maze. The maze definition is read from a file.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Maze(int nbr)
    Creates a maze with number nbr.
    Maze(String filename, int xEntry, int yEntry)
    Creates a maze based on an image file (.png or .jpg).
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    atExit(int x, int y)
    Checks if the point x,y is at (or near) the exit.
    void
    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.

    Methods inherited from class java.lang.Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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

      public Maze(String filename, int xEntry, int yEntry)
      Creates a maze based on an image file (.png or .jpg).
      Parameters:
      filename - name of image file
      xEntry - x coordinate of the maze's entry point
      yEntry - y coordinate of the maze's entry point
  • Method Details

    • draw

      public void draw(SimpleWindow w)
      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 coordinate
      y - 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 coordinate
      y - 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 coordinate
      y - the y coordinate
      Returns:
      true if there's a wall directly in front, false otherwise