Class Labyrinth2D
- All Implemented Interfaces:
Iterable<List<Wall>>,ILabyrinth2D
This class provides functionality for generating and interacting with a labyrinth in a 2D grid. It allows the management of walls, light sources, and spawn points, as well as collision detection.
-
Constructor Summary
ConstructorsConstructorDescriptionLabyrinth2D(int dimension, int quantityOfLights, long seed) Constructs a newLabyrinth2Dwith the specified dimension and number of light sources. -
Method Summary
Modifier and TypeMethodDescriptionbooleancheckAddress(int x, int y) Checks whether the specified coordinates are within the bounds of the labyrinth.final Wallget(int x, int y) Retrieves the wall at the specified coordinates (x, y) in the labyrinth.intReturns the dimension of the labyrinth (i.e., the width and height of the grid).longgetSeed()Returns the random seed used for labyrinth generation.@NotNull PointReturns the spawn point of the labyrinth.booleanisCollidingWithWall(double x, double y) Checks if the specified coordinates are colliding with a wall in the labyrinth.iterator()Returns an iterator over the rows of the labyrinth.final voidSets the wall at the specified coordinates (x, y) in the labyrinth.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.regsirius06.engine.utils.ILabyrinth2D
get, set, setMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
Labyrinth2D
public Labyrinth2D(int dimension, int quantityOfLights, long seed) Constructs a newLabyrinth2Dwith the specified dimension and number of light sources.This constructor generates a labyrinth and randomly places light sources and a spawn point.
- Parameters:
dimension- the dimension of the labyrinth (width and height of a square grid)quantityOfLights- the number of light sources to generate in the labyrinthseed- the random seed for labyrinth generation
-
-
Method Details
-
get
Retrieves the wall at the specified coordinates (x, y) in the labyrinth.The wall represents an element of the labyrinth at the given grid location.
- Specified by:
getin interfaceILabyrinth2D- Parameters:
x- the x-coordinate of the wally- the y-coordinate of the wall- Returns:
- the
Wallat the given coordinates
-
set
Sets the wall at the specified coordinates (x, y) in the labyrinth.This method allows you to modify the state of a specific wall in the labyrinth.
- Specified by:
setin interfaceILabyrinth2D- Parameters:
x- the x-coordinate of the wally- the y-coordinate of the wallwall- the new wall type to set
-
checkAddress
public boolean checkAddress(int x, int y) Checks whether the specified coordinates are within the bounds of the labyrinth.This method ensures that any point being accessed lies within the valid range of the labyrinth's grid.
- Specified by:
checkAddressin interfaceILabyrinth2D- Parameters:
x- the x-coordinate to checky- the y-coordinate to check- Returns:
- true if the coordinates are within bounds, false otherwise
-
isCollidingWithWall
public boolean isCollidingWithWall(double x, double y) Checks if the specified coordinates are colliding with a wall in the labyrinth.This method detects if a point within the labyrinth's grid is occupied by a non-empty wall.
- Specified by:
isCollidingWithWallin interfaceILabyrinth2D- Parameters:
x- the x-coordinate of the point to checky- the y-coordinate of the point to check- Returns:
- true if the point is colliding with a wall, false otherwise
-
getSpawnPoint
Returns the spawn point of the labyrinth.The spawn point is the location where the player or character starts within the labyrinth.
- Specified by:
getSpawnPointin interfaceILabyrinth2D- Returns:
- the
Pointrepresenting the spawn point
-
getDimension
public int getDimension()Returns the dimension of the labyrinth (i.e., the width and height of the grid).The dimension defines the size of the labyrinth's grid, both horizontally and vertically.
- Specified by:
getDimensionin interfaceILabyrinth2D- Returns:
- the dimension of the labyrinth
-
getSeed
public long getSeed()Returns the random seed used for labyrinth generation.This seed is used to ensure reproducibility of the labyrinth generation process.
- Returns:
- the seed used for labyrinth generation
-
iterator
Returns an iterator over the rows of the labyrinth.This iterator allows you to traverse the labyrinth row by row.
-