Package com.edu.xmum.CST210.Model.Entity
Class MazeModel
java.lang.Object
com.edu.xmum.CST210.Model.AbstractClass.GameObject
com.edu.xmum.CST210.Model.Entity.MazeModel
- All Implemented Interfaces:
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
ConstructorsConstructorDescriptionMazeModel(int rows, int cols) Constructor to initialize the maze with the specified number of rows and columns. -
Method Summary
Modifier and TypeMethodDescriptionvoidGenerates the maze using the stochastic Prim's algorithm.intgetCols()Gets the number of columns in the maze.intgetGoalX()Gets the x-coordinate of the goal position in the maze.intgetGoalY()Gets the y-coordinate of the goal position in the maze.int[][]getMaze()Gets the maze structure as a two-dimensional array.intgetRows()Gets the number of rows in the maze.intGets the x-coordinate of the start position in the maze.intGets the y-coordinate of the start position in the maze.voidsetCols(int cols) Sets the number of columns in the maze.voidsetRows(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
-
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:
generateMazein interfaceIMazeModel
-
getRows
public int getRows()Description copied from interface:IMazeModelGets the number of rows in the maze.- Specified by:
getRowsin interfaceIMazeModel- Returns:
- The number of rows.
-
setRows
public void setRows(int rows) Description copied from interface:IMazeModelSets the number of rows in the maze.- Specified by:
setRowsin interfaceIMazeModel- Parameters:
rows- The number of rows to set.
-
getCols
public int getCols()Description copied from interface:IMazeModelGets the number of columns in the maze.- Specified by:
getColsin interfaceIMazeModel- Returns:
- The number of columns.
-
setCols
public void setCols(int cols) Description copied from interface:IMazeModelSets the number of columns in the maze.- Specified by:
setColsin interfaceIMazeModel- Parameters:
cols- The number of columns to set.
-
getMaze
public int[][] getMaze()Description copied from interface:IMazeModelGets the maze structure as a two-dimensional array. 0 means the cell is accessible, 1 means the cell is a wall.- Specified by:
getMazein interfaceIMazeModel- Returns:
- The maze structure.
-
getGoalX
public int getGoalX()Description copied from interface:IMazeModelGets the x-coordinate of the goal position in the maze.- Specified by:
getGoalXin interfaceIMazeModel- Returns:
- The x-coordinate of the goal.
-
getGoalY
public int getGoalY()Description copied from interface:IMazeModelGets the y-coordinate of the goal position in the maze.- Specified by:
getGoalYin interfaceIMazeModel- Returns:
- The y-coordinate of the goal.
-
getStartX
public int getStartX()Description copied from interface:IMazeModelGets the x-coordinate of the start position in the maze.- Specified by:
getStartXin interfaceIMazeModel- Returns:
- The x-coordinate of the start.
-
getStartY
public int getStartY()Description copied from interface:IMazeModelGets the y-coordinate of the start position in the maze.- Specified by:
getStartYin interfaceIMazeModel- Returns:
- The y-coordinate of the start.
-