Class MazeModel

java.lang.Object
com.edu.xmum.CST210.Model.AbstractClass.GameObject
com.edu.xmum.CST210.Model.Entity.MazeModel
All Implemented Interfaces:
IMazeModel

public class MazeModel extends GameObject implements IMazeModel
Concrete implementation class of the maze object. This class represents a maze and provides methods to generate it using the stochastic Prim's algorithm.

Attributes: - rows: number of rows in the maze - cols: number of columns in the maze - maze: a two-dimensional array to represent the maze, [y][x] - goalX, goalY: target position coordinates - startX, startY: start position coordinates

  • Constructor Summary

    Constructors
    Constructor
    Description
    MazeModel(int rows, int cols)
    Constructor to initialize the maze with the specified number of rows and columns.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Generates the maze using the stochastic Prim's algorithm.
    int
    Gets the number of columns in the maze.
    int
    Gets the x-coordinate of the goal position in the maze.
    int
    Gets the y-coordinate of the goal position in the maze.
    int[][]
    Gets the maze structure as a two-dimensional array.
    int
    Gets the number of rows in the maze.
    int
    Gets the x-coordinate of the start position in the maze.
    int
    Gets the y-coordinate of the start position in the maze.
    void
    setCols(int cols)
    Sets the number of columns in the maze.
    void
    setRows(int rows)
    Sets the number of rows in the maze.

    Methods inherited from class com.edu.xmum.CST210.Model.AbstractClass.GameObject

    getX, getY, setX, setY

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • MazeModel

      public MazeModel(int rows, int cols)
      Constructor to initialize the maze with the specified number of rows and columns.
      Parameters:
      rows - The number of rows in the maze.
      cols - The number of columns in the maze.
  • Method Details

    • generateMaze

      public void generateMaze()
      Generates the maze using the stochastic Prim's algorithm. 1. Initialize all cells in the maze to 1 (wall). 2. Set the entrance position to 0 (path). 3. Initialize a list of adjacent edges to store candidate edges. 4. Add candidate edges from the current position. 5. Randomly select a pathway from the list of candidate edges. 6. Repeat until the list of candidate edges is empty.
      Specified by:
      generateMaze in interface IMazeModel
    • getRows

      public int getRows()
      Description copied from interface: IMazeModel
      Gets the number of rows in the maze.
      Specified by:
      getRows in interface IMazeModel
      Returns:
      The number of rows.
    • setRows

      public void setRows(int rows)
      Description copied from interface: IMazeModel
      Sets the number of rows in the maze.
      Specified by:
      setRows in interface IMazeModel
      Parameters:
      rows - The number of rows to set.
    • getCols

      public int getCols()
      Description copied from interface: IMazeModel
      Gets the number of columns in the maze.
      Specified by:
      getCols in interface IMazeModel
      Returns:
      The number of columns.
    • setCols

      public void setCols(int cols)
      Description copied from interface: IMazeModel
      Sets the number of columns in the maze.
      Specified by:
      setCols in interface IMazeModel
      Parameters:
      cols - The number of columns to set.
    • getMaze

      public int[][] getMaze()
      Description copied from interface: IMazeModel
      Gets the maze structure as a two-dimensional array. 0 means the cell is accessible, 1 means the cell is a wall.
      Specified by:
      getMaze in interface IMazeModel
      Returns:
      The maze structure.
    • getGoalX

      public int getGoalX()
      Description copied from interface: IMazeModel
      Gets the x-coordinate of the goal position in the maze.
      Specified by:
      getGoalX in interface IMazeModel
      Returns:
      The x-coordinate of the goal.
    • getGoalY

      public int getGoalY()
      Description copied from interface: IMazeModel
      Gets the y-coordinate of the goal position in the maze.
      Specified by:
      getGoalY in interface IMazeModel
      Returns:
      The y-coordinate of the goal.
    • getStartX

      public int getStartX()
      Description copied from interface: IMazeModel
      Gets the x-coordinate of the start position in the maze.
      Specified by:
      getStartX in interface IMazeModel
      Returns:
      The x-coordinate of the start.
    • getStartY

      public int getStartY()
      Description copied from interface: IMazeModel
      Gets the y-coordinate of the start position in the maze.
      Specified by:
      getStartY in interface IMazeModel
      Returns:
      The y-coordinate of the start.