Enum Class Direction

java.lang.Object
java.lang.Enum<Direction>
edu.uoc.pacman.model.utils.Direction
All Implemented Interfaces:
Serializable, Comparable<Direction>, Constable

public enum Direction extends Enum<Direction>
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!!
  • Nested Class Summary

    Nested classes/interfaces inherited from class java.lang.Enum

    Enum.EnumDesc<E extends Enum<E>>
  • Enum Constant Summary

    Enum Constants
    Enum Constant
    Description
    DOWN direction. x = 0, y = 1 and keyCode = 20.
    LEFT direction. x = -1, y = 0 and keyCode = 21.
    RIGHT direction. x = 1, y = 0 and keyCode = 22.
    UP direction. x = 0, y = -1 and keyCode = 19.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final int
    Intenger value that is given by libgdx to a key pressed by the user
    private final int
    Offset in X axis
    private final int
    Offset in Y axis
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    Direction(int x, int y, int keyCode)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static Direction
    getDirectionByKeyCode(int keyCode)
    Given the value of keyCode, it returns the corresponding Direction value.
    int
    Getter of the attibute keyCode
    int
    Getter of the attibute x
    int
    Getter of the attibute y
    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[]
    Returns an array containing the constants of this enum class, in the order they are declared.

    Methods inherited from class java.lang.Object

    getClass, notify, notifyAll, wait, wait, wait
  • Enum Constant Details

    • DOWN

      public static final Direction DOWN
      DOWN direction. x = 0, y = 1 and keyCode = 20.
    • LEFT

      public static final Direction LEFT
      LEFT direction. x = -1, y = 0 and keyCode = 21.
    • UP

      public static final Direction UP
      UP direction. x = 0, y = -1 and keyCode = 19.
  • Field Details

    • x

      private final int x
      Offset in X axis
    • y

      private final int y
      Offset in Y axis
    • keyCode

      private final int keyCode
      Intenger 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 attribute x
      y - Value of the attribute y
      keyCode - Value of the attribute keyCode
  • Method Details

    • values

      public static Direction[] 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

      public static Direction valueOf(String name)
      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 name
      NullPointerException - if the argument is null
    • getX

      public int getX()
      Getter of the attibute x
      Returns:
      The value of the attribute x
    • getY

      public int getY()
      Getter of the attibute y
      Returns:
      The value of the attribute y
    • getKeyCode

      public int getKeyCode()
      Getter of the attibute keyCode
      Returns:
      The value of the attribute keyCode
    • getDirectionByKeyCode

      public static Direction getDirectionByKeyCode(int keyCode)
      Given the value of keyCode, it returns the corresponding Direction value.
      Parameters:
      keyCode - Integer value of a key.
      Returns:
      The Direction value linked to keyCode. If any, then returns null.
    • opposite

      public Direction opposite()
      Gets the opposite direction of the direction that invokes this method.
      Returns:
      Opposite direction to the current direction.