Package org.progettoedids.labyrinth
Class Labyrinth
java.lang.Object
org.progettoedids.labyrinth.Labyrinth
The Labyrinth class holds the state of the game's environment and supplies handy methods to access and make changes to
the various components that make up the state.
Due to the complexity of the construction of a Labyrinth object, a Builder class is supplied, an instance of such class can be retrieved with the method newBuilder()
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classIt's the class responsible for Building a fully configured Labyrinth in a valid state. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds an Entity to the Labyrinth at the specified PositionbooleancanMoveByOne(UUID entityUUID, Direction direction) Checks whether a move by one of a specific Entity in a certain Direction is allowed.booleanChecks whether the Player can go back to its previous Position.Returns the Difficulty of the Labyrinth<T> Entity[]getEntitiesInRoomWithPlayer(Class<T> entityClass) Returns certain subtypes of Entity(ies) in Room with the Player.Returns the Entity associated with the specified UUIDgetEntityPosition(UUID entityUUID) Returns the Position of the Entity with the specified UUIDReturns a matrix representation of all the rooms and the current position of the Player.getName()Returns the name of the LabyrinthReturns the Player instance held by the LabyrinthReturns the Position of the Player in the LabyrinthReturns the Room instance where the Player is locatedReturns the Random generator to use for random numbers.longReturns the Room instance associated with the Position suppliedbooleanisValidPosition(Position position) Checks whether a Position is within the dimensions of the Room matrixvoidmoveEntityByOne(UUID entityUUID, Direction direction) Moves the Entity by one Room in a certain Direction.static Labyrinth.BuilderReturns an instance of Builder which is needed to build a Labyrinth.voidMoves the Player back to its previous Position.voidsetEntityPosition(UUID entityUUID, Position entityWantedPosition) Sets the Position of an Entity.
-
Constructor Details
-
Labyrinth
protected Labyrinth()
-
-
Method Details
-
getPlayer
Returns the Player instance held by the Labyrinth- Returns:
- Player instance
-
getPlayerPosition
Returns the Position of the Player in the Labyrinth- Returns:
- Position of the Player
-
getPlayerRoom
Returns the Room instance where the Player is located- Returns:
- Player's Room
-
getEntitiesInRoomWithPlayer
-
getEntity
-
getEntityPosition
-
getRoom
-
canPlayerGoBack
public boolean canPlayerGoBack()Checks whether the Player can go back to its previous Position.- Returns:
- true if the Player has previous Position(s), false otherwise
-
playerGoBack
public void playerGoBack()Moves the Player back to its previous Position.- Throws:
UnsupportedOperationException- if the Player can't go back because canPlayerGoBack returned false
-
canMoveByOne
Checks whether a move by one of a specific Entity in a certain Direction is allowed. For example, an Entity may not move in a certain Direction if the next Room in that direction is locked or if the Entity was about to move outside the edge of the Labyrinth.- Parameters:
entityUUID- the UUID of the Entity to movedirection- the Direction in which to move the Entity- Returns:
- true if the Entity can legally move in that Direction, false otherwise
-
moveEntityByOne
-
setEntityPosition
Sets the Position of an Entity.Please note that it's always preferable to use the moveEntityByOne method instead, if possible. If a Player Entity is moved its old Position is added to the stack of previous positions.
- Parameters:
entityUUID- the UUID of the entity to move. Must not be nullentityWantedPosition- the Position where to move the Entity. Must not be null- Throws:
IllegalArgumentException- if the Position supplied is invalid
-
addEntity
Adds an Entity to the Labyrinth at the specified Position- Parameters:
position- the Position at which to place the Entityentity- the Entity to insert in the Labyrinth- Throws:
IllegalArgumentException- if the Position supplied is invalid
-
isValidPosition
Checks whether a Position is within the dimensions of the Room matrix- Parameters:
position- a position. Must not be null- Returns:
- true if the position is valid, false otherwise
-
getName
-
getDifficulty
Returns the Difficulty of the Labyrinth- Returns:
- the Difficulty enumerator of the Labyrinth
-
getRandomGenerator
Returns the Random generator to use for random numbers.- Returns:
- a Random generator
-
getRandomGeneratorSeed
public long getRandomGeneratorSeed() -
getMatrixString
Returns a matrix representation of all the rooms and the current position of the Player.Each room is labeled with its characterizing character and the Player is represented with a 'P'.
- Returns:
- a String with the representation
-
newBuilder
Returns an instance of Builder which is needed to build a Labyrinth.- Returns:
- a non-configured Builder
-