Package com.edu.xmum.CST210.Service
Class MazeService
java.lang.Object
com.edu.xmum.CST210.Service.MazeService
- All Implemented Interfaces:
IMazeService
Implementation of the IMazeService interface.
Provides methods to handle maze-related logic.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetMaze()Gets the current maze model instance.List<int[]>getPath(int x, int y) Provides a hint for the maze path using the DFS algorithm.booleanhasReachedGoal(IPlayerModel player) Checks if the player has reached the goal position in the maze.booleanisPath(int x, int y) Checks if the specified coordinates (x, y) are a path and not a wall.booleanisValidMove(IPlayerModel player, int dx, int dy) Checks if the player's move to the specified direction (dx, dy) is valid within the maze.booleanisWithinBounds(int x, int y) Checks if the specified coordinates (x, y) are within the maze boundaries.voidreset()Resets the maze to its initial state by generating a new maze.
-
Constructor Details
-
MazeService
Constructor for MazeService. Uses dependency injection to initialize the maze model.- Parameters:
mazeModel- The maze model instance.
-
-
Method Details
-
getPath
Provides a hint for the maze path using the DFS algorithm.- Specified by:
getPathin interfaceIMazeService- Parameters:
x- The starting x coordinate.y- The starting y coordinate.- Returns:
- A list of coordinate pairs representing the path to the goal.
-
isValidMove
Checks if the player's move to the specified direction (dx, dy) is valid within the maze.- Specified by:
isValidMovein interfaceIMazeService- Parameters:
player- The player model instance.dx- The delta x value for the move.dy- The delta y value for the move.- Returns:
- True if the move is valid, false otherwise.
-
isPath
public boolean isPath(int x, int y) Checks if the specified coordinates (x, y) are a path and not a wall.- Specified by:
isPathin interfaceIMazeService- Parameters:
x- The x coordinate to check.y- The y coordinate to check.- Returns:
- True if the coordinates represent a path, false otherwise.
-
isWithinBounds
public boolean isWithinBounds(int x, int y) Checks if the specified coordinates (x, y) are within the maze boundaries.- Specified by:
isWithinBoundsin interfaceIMazeService- Parameters:
x- The x coordinate to check.y- The y coordinate to check.- Returns:
- True if the coordinates are within bounds, false otherwise.
-
hasReachedGoal
Checks if the player has reached the goal position in the maze.- Specified by:
hasReachedGoalin interfaceIMazeService- Parameters:
player- The player model instance.- Returns:
- True if the player has reached the goal, false otherwise.
-
reset
public void reset()Resets the maze to its initial state by generating a new maze.- Specified by:
resetin interfaceIMazeService
-
getMaze
Gets the current maze model instance.- Specified by:
getMazein interfaceIMazeService- Returns:
- The maze model instance.
-