Class Character

java.lang.Object
edu.uoc.pacman.model.entities.Entity
edu.uoc.pacman.model.entities.characters.Character
All Implemented Interfaces:
Hitable, Movable
Direct Known Subclasses:
Ghost, Pacman

public abstract class Character extends Entity implements Movable, Hitable
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

    Fields
    Modifier and Type
    Field
    Description
    private 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

    Constructors
    Constructor
    Description
    Character(Position position, Direction direction, Sprite sprite, Level level)
    Creates a character at the given position facing in the given direction.
    Any character is pathable.
    If the position is null, then the position will be (0,0).
    Take into consideration that the value of the parameter position is also the start/initial position of the character.
    If the direction is null, then the direction will be UP.
    By default, any character is alive.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Sets the attribute dead to false.
    Gets the direction that the character is facing.
    protected int
    Getter of the attribute duration.
    Getter of the attribute level.
    protected Position
    Getter of the attribute startPosition.
    boolean
    Getter of the attribute dead.
    void
    Sets the attribute dead to true.
    void
    Resets the character.
    private void
    setDead(boolean dead)
    Setter of the attribute dead.
    void
    Sets the direction of the character.
    If the direction is null, then the direction is not set and remains the same.
    protected void
    setDuration(int duration)
    Setter of the attribute duration.
    void
    setLevel(Level level)
    Setter of the attribute level.
    private void
    setStartPosition(Position startPosition)
    Setter of the attribute startPosition.
    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

    Methods inherited from class edu.uoc.pacman.model.entities.Entity

    getPosition, getSprite, isPathable, setPathable, setPosition, setSprite

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface edu.uoc.pacman.model.entities.characters.Hitable

    hit

    Methods inherited from interface edu.uoc.pacman.model.entities.characters.Movable

    move
  • Field Details

    • direction

      private Direction direction
      The direction that the character faces.
    • duration

      private int duration
      Left time so that the ghost changes its current behaviour or the Pacman changes its current state.
    • dead

      private boolean dead
      Indicates if the character is dead (true) or not (false).
    • startPosition

      private Position startPosition
      Stores the initial/start position of the character. Its value is the one which is provided by the level configuration file.
    • level

      private Level level
      Reference to the current level object.
  • Constructor Details

    • Character

      public Character(Position position, Direction direction, Sprite sprite, Level level)
      Creates a character at the given position facing in the given direction.
      Any character is pathable.
      If the position is null, then the position will be (0,0).
      Take into consideration that the value of the parameter position is also the start/initial position of the character.
      If the direction is null, then the direction will be UP.
      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

      public Direction getDirection()
      Gets the direction that the character is facing.
      Returns:
      The current direction of the character.
    • setDirection

      public void setDirection(Direction direction)
      Sets the direction of the character.
      If the direction is null, then the direction is not set and remains the same.
      Specified by:
      setDirection in interface Movable
      Parameters:
      direction - New value for the attribute direction.
      Since:
      setDirection in interface Movable.
    • getDuration

      protected int getDuration()
      Getter of the attribute duration.
      Returns:
      Current value of the attribute duration.
    • setDuration

      protected void setDuration(int duration)
      Setter of the attribute duration.
      Parameters:
      duration - New value for the attribute duration.
    • setDead

      private void setDead(boolean dead)
      Setter of the attribute dead.
      Parameters:
      dead - New value of the attribute dead.
    • isDead

      public boolean isDead()
      Getter of the attribute dead.
      Returns:
      The current value of the attribute dead.
    • setStartPosition

      private void setStartPosition(Position startPosition)
      Setter of the attribute startPosition.
      Parameters:
      startPosition - New value of the attribute startPosition.
    • getStartPosition

      protected Position getStartPosition()
      Getter of the attribute startPosition.
      Returns:
      Current value of the attribute startPosition.
    • kill

      public void kill()
      Sets the attribute dead to true.
    • alive

      public void alive()
      Sets the attribute dead to false.
    • getLevel

      public Level getLevel()
      Getter of the attribute level.
      Returns:
      The current value of the attribute level.
    • setLevel

      public void setLevel(Level level)
      Setter of the attribute level.
      Parameters:
      level - New value for the attribute level.
    • toString

      public String 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
      Overrides:
      toString in class Object
      Returns:
      "x,y,DIRECTION"