Enum Class State
- All Implemented Interfaces:
Serializable
,Comparable<State>
,Constable
Represents the three state which Pacman can have. The behaviour are defined
as "NORMAL", "EATER" and "INVINCIBLE".
- "NORMAL" - Its the most frequent state. Its duration is
Integer.MAX_VALUE
. - "EATER" - Pacman can kill ghosts. It has a duration of 30, the same as the ghosts's frightened behaviour.
- "INVINCIBLE" - Pacman cannot be killed by ghosts, but it does not kill ghosts either. Duration = 5.
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>>
-
Enum Constant Summary
Enum ConstantsEnum ConstantDescriptionState when Pacman eats an energizer and is able to eat/kill ghosts.State when Pacman has been killed, and it cannot neither be killed nor kill ghosts.State in which Pacman is usually. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint
Gets the duration of the state.toString()
Returns a String with information of the State.
Format: STATE:stateDuration
Example: "INVINCIBLE:5"
Hint: Remember that toString() is already coded in Object.static State
Returns the enum constant of this class with the specified name.static State[]
values()
Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
NORMAL
State in which Pacman is usually. -
EATER
State when Pacman eats an energizer and is able to eat/kill ghosts. -
INVINCIBLE
State when Pacman has been killed, and it cannot neither be killed nor kill ghosts.
-
-
Field Details
-
duration
private final int durationStores the duration of the state.
-
-
Constructor Details
-
State
private State(int duration) Constructor with arguments.- Parameters:
duration
- Value to set to the state.
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name
- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException
- if this enum class has no constant with the specified nameNullPointerException
- if the argument is null
-
getDuration
public int getDuration()Gets the duration of the state.- Returns:
- duration of the state.
-
toString
Returns a String with information of the State.
Format: STATE:stateDuration
Example: "INVINCIBLE:5"
Hint: Remember that toString() is already coded in Object.
-