Class Character
java.lang.Object
edu.uoc.pacman.model.entities.Entity
edu.uoc.pacman.model.entities.characters.Character
A character is any entity that is able to move and hit. As a result, it can traverse the
game board and interact with other entities.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate boolean
Indicates if the character is dead (true
) or not (false
).private Direction
The direction that the character faces.private int
Left time so that the ghost changes its current behaviour or the Pacman changes its current state.private Level
Reference to the current level object.private Position
Stores the initial/start position of the character. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a character at the given position facing in the given direction.
Any character ispathable
.
If the position isnull
, then the position will be (0,0).
Take into consideration that the value of the parameterposition
is also the start/initial position of the character.
If the direction isnull
, then the direction will beUP
.
By default, any character is alive. -
Method Summary
Modifier and TypeMethodDescriptionvoid
alive()
Sets the attributedead
tofalse
.Gets the direction that the character is facing.protected int
Getter of the attributeduration
.getLevel()
Getter of the attributelevel
.protected Position
Getter of the attributestartPosition
.boolean
isDead()
Getter of the attributedead
.void
kill()
Sets the attributedead
totrue
.void
reset()
Resets the character.private void
setDead
(boolean dead) Setter of the attributedead
.void
setDirection
(Direction direction) Sets the direction of the character.
If the direction isnull
, then the direction is not set and remains the same.protected void
setDuration
(int duration) Setter of the attributeduration
.void
Setter of the attributelevel
.private void
setStartPosition
(Position startPosition) Setter of the attributestartPosition
.toString()
Represents this entity in a comma-separated string format.
Format is: "x,y,DIRECTION", where DIRECTION is uppercase enum type value.
Example: 4,5,LEFTMethods inherited from class edu.uoc.pacman.model.entities.Entity
getPosition, getSprite, isPathable, setPathable, setPosition, setSprite
-
Field Details
-
direction
The direction that the character faces. -
duration
private int durationLeft time so that the ghost changes its current behaviour or the Pacman changes its current state. -
dead
private boolean deadIndicates if the character is dead (true
) or not (false
). -
startPosition
Stores the initial/start position of the character. Its value is the one which is provided by the level configuration file. -
level
Reference to the current level object.
-
-
Constructor Details
-
Character
Creates a character at the given position facing in the given direction.
Any character ispathable
.
If the position isnull
, then the position will be (0,0).
Take into consideration that the value of the parameterposition
is also the start/initial position of the character.
If the direction isnull
, then the direction will beUP
.
By default, any character is alive.- Parameters:
position
- to be set to.direction
- to be facing.sprite
- to be set to.level
- Reference to the current level
-
-
Method Details
-
reset
public void reset()Resets the character. This means that the character is placed in the start position and is alive. -
getDirection
Gets the direction that the character is facing.- Returns:
- The current direction of the character.
-
setDirection
Sets the direction of the character.
If the direction isnull
, then the direction is not set and remains the same.- Specified by:
setDirection
in interfaceMovable
- Parameters:
direction
- New value for the attributedirection
.- Since:
- setDirection in interface
Movable
.
-
getDuration
protected int getDuration()Getter of the attributeduration
.- Returns:
- Current value of the attribute
duration
.
-
setDuration
protected void setDuration(int duration) Setter of the attributeduration
.- Parameters:
duration
- New value for the attributeduration
.
-
setDead
private void setDead(boolean dead) Setter of the attributedead
.- Parameters:
dead
- New value of the attributedead
.
-
isDead
public boolean isDead()Getter of the attributedead
.- Returns:
- The current value of the attribute
dead
.
-
setStartPosition
Setter of the attributestartPosition
.- Parameters:
startPosition
- New value of the attributestartPosition
.
-
getStartPosition
Getter of the attributestartPosition
.- Returns:
- Current value of the attribute
startPosition
.
-
kill
public void kill()Sets the attributedead
totrue
. -
alive
public void alive()Sets the attributedead
tofalse
. -
getLevel
Getter of the attributelevel
.- Returns:
- The current value of the attribute
level
.
-
setLevel
Setter of the attributelevel
.- Parameters:
level
- New value for the attributelevel
.
-
toString
Represents this entity in a comma-separated string format.
Format is: "x,y,DIRECTION", where DIRECTION is uppercase enum type value.
Example: 4,5,LEFT
-