Package battlecode.common
Enum Class Direction
- All Implemented Interfaces:
Serializable,Comparable<Direction>,Constable
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.
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>> -
Enum Constant Summary
Enum ConstantsEnum ConstantDescriptionDirection that represents pointing nowhere.Direction that represents pointing east (right on screen).Direction that represents pointing north (up on screen).Direction that represents pointing northeast (up and to the right on screen).Direction that represents pointing northwest (up and to the left on screen).Direction that represents pointing south (down on screen).Direction that represents pointing southeast (down and to the right on screen).Direction that represents pointing southwest (down and to the left on screen).Direction that represents pointing west (left on screen). -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic Direction[]final intChange in x.final intChange in y. -
Method Summary
Modifier and TypeMethodDescriptionstatic Direction[]Returns a list of all directions.static Direction[]Returns a list of all cardinal directions.intReturns the delta X of the direction.intReturns the delta Y of the direction.intopposite()Computes the direction opposite this one.Computes the direction 45 degrees to the left (counter-clockwise) of this one.Computes the direction 45 degrees to the right (clockwise) of this one.static DirectionReturns 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
-
NORTH
Direction that represents pointing north (up on screen). -
NORTHEAST
Direction that represents pointing northeast (up and to the right on screen). -
EAST
Direction that represents pointing east (right on screen). -
SOUTHEAST
Direction that represents pointing southeast (down and to the right on screen). -
SOUTH
Direction that represents pointing south (down on screen). -
SOUTHWEST
Direction that represents pointing southwest (down and to the left on screen). -
WEST
Direction that represents pointing west (left on screen). -
NORTHWEST
Direction that represents pointing northwest (up and to the left on screen). -
CENTER
Direction that represents pointing nowhere.
-
-
Field Details
-
DIRECTION_ORDER
-
dx
public final int dxChange in x. -
dy
public final int dyChange in y.
-
-
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
-
getDirectionOrderNum
public int getDirectionOrderNum() -
opposite
Computes the direction opposite this one.- Returns:
- the direction pointing in the opposite direction to this one
- Bytecode cost:
1
-
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
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
Returns a list of all directions. This is equivalent to callingvalues().- Returns:
- array of all directions
-
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
-