Enum Class Direction

java.lang.Object
java.lang.Enum<Direction>
battlecode.common.Direction
All Implemented Interfaces:
Serializable, Comparable<Direction>, Constable

public enum Direction extends Enum<Direction>
This enumeration represents a direction from one MapLocation to another. There is a direction for each of the cardinals (north, south, east, west), each of the diagonals (northwest, southwest, northeast, southeast), and no direction (center).

Since Direction is a Java 1.5 enum, you can use it in switch statements, it has all the standard enum methods (valueOf, values, etc.), and you can safely use == for equality tests.

  • Enum Constant Details

    • NORTH

      public static final Direction NORTH
      Direction that represents pointing north (up on screen).
    • NORTHEAST

      public static final Direction NORTHEAST
      Direction that represents pointing northeast (up and to the right on screen).
    • EAST

      public static final Direction EAST
      Direction that represents pointing east (right on screen).
    • SOUTHEAST

      public static final Direction SOUTHEAST
      Direction that represents pointing southeast (down and to the right on screen).
    • SOUTH

      public static final Direction SOUTH
      Direction that represents pointing south (down on screen).
    • SOUTHWEST

      public static final Direction SOUTHWEST
      Direction that represents pointing southwest (down and to the left on screen).
    • WEST

      public static final Direction WEST
      Direction that represents pointing west (left on screen).
    • NORTHWEST

      public static final Direction NORTHWEST
      Direction that represents pointing northwest (up and to the left on screen).
    • CENTER

      public static final Direction CENTER
      Direction that represents pointing nowhere.
  • Field Details

    • DIRECTION_ORDER

      public static Direction[] DIRECTION_ORDER
    • dx

      public final int dx
      Change in x.
    • dy

      public final int dy
      Change in y.
  • 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
    • getDirectionOrderNum

      public int getDirectionOrderNum()
    • opposite

      public Direction opposite()
      Computes the direction opposite this one.
      Returns:
      the direction pointing in the opposite direction to this one
      Bytecode cost:
      1
    • rotateLeft

      public Direction rotateLeft()
      Computes the direction 45 degrees to the left (counter-clockwise) of this one.
      Returns:
      the direction 45 degrees left of this one
      Bytecode cost:
      1
    • rotateRight

      public Direction rotateRight()
      Computes the direction 45 degrees to the right (clockwise) of this one.
      Returns:
      the direction 45 degrees right of this one
      Bytecode cost:
      1
    • allDirections

      public static Direction[] allDirections()
      Returns a list of all directions. This is equivalent to calling values().
      Returns:
      array of all directions
    • cardinalDirections

      public static Direction[] cardinalDirections()
      Returns a list of all cardinal directions.
      Returns:
      array of all cardinal directions
    • getDeltaX

      public int getDeltaX()
      Returns the delta X of the direction.
      Returns:
      the delta X of the direction
    • getDeltaY

      public int getDeltaY()
      Returns the delta Y of the direction.
      Returns:
      the delta Y of the direction