Package edu.uoc.pacman.model.utils
Enum Class Direction
- All Implemented Interfaces:
Serializable
,Comparable<Direction>
,Constable
Direction that Pacman and ghosts face.
RESPECT The order of the values: RIGHT, DOWN, LEFT, UP.
The methods valueOf(String name) and values() are provided by Java Enumeration. You don't have to create them!!
RESPECT The order of the values: RIGHT, DOWN, LEFT, UP.
The methods valueOf(String name) and values() are provided by Java Enumeration. You don't have to create them!!
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>>
-
Enum Constant Summary
Enum Constants -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Direction
getDirectionByKeyCode
(int keyCode) Given the value ofkeyCode
, it returns the correspondingDirection
value.int
Getter of the attibutekeyCode
int
getX()
Getter of the attibutex
int
getY()
Getter of the attibutey
opposite()
Gets the opposite direction of the direction that invokes this method.static Direction
Returns the enum constant of this class with the specified name.static Direction[]
values()
Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
RIGHT
RIGHT direction. x = 1, y = 0 and keyCode = 22. -
DOWN
DOWN direction. x = 0, y = 1 and keyCode = 20. -
LEFT
LEFT direction. x = -1, y = 0 and keyCode = 21. -
UP
UP direction. x = 0, y = -1 and keyCode = 19.
-
-
Field Details
-
x
private final int xOffset in X axis -
y
private final int yOffset in Y axis -
keyCode
private final int keyCodeIntenger value that is given by libgdx to a key pressed by the user
-
-
Constructor Details
-
Direction
private Direction(int x, int y, int keyCode) - Parameters:
x
- Value of the attributex
y
- Value of the attributey
keyCode
- Value of the attributekeyCode
-
-
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
-
getX
public int getX()Getter of the attibutex
- Returns:
- The value of the attribute
x
-
getY
public int getY()Getter of the attibutey
- Returns:
- The value of the attribute
y
-
getKeyCode
public int getKeyCode()Getter of the attibutekeyCode
- Returns:
- The value of the attribute
keyCode
-
getDirectionByKeyCode
Given the value ofkeyCode
, it returns the correspondingDirection
value.- Parameters:
keyCode
- Integer value of a key.- Returns:
- The
Direction
value linked tokeyCode
. If any, then returnsnull
.
-
opposite
Gets the opposite direction of the direction that invokes this method.- Returns:
- Opposite direction to the current direction.
-