battlecode.common
Enum Direction

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

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), and each of diagonals (northwest, southwest, northeast, southeast). There is also NONE, representing no direction, and OMNI, representing all directions.

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 Summary
EAST
           
NONE
          No direction.
NORTH
           
NORTH_EAST
           
NORTH_WEST
           
OMNI
          All directions.
SOUTH
           
SOUTH_EAST
           
SOUTH_WEST
           
WEST
           
 
Field Summary
 int dx
           
 int dy
           
 
Method Summary
 boolean isDiagonal()
          Determines whether or not this direction is a diagonal one.
 Direction opposite()
          Computes the direction opposite this one.
 Direction rotateLeft()
          Computes the direction 45 degrees to the left (counter-clockwise) of this one.
 Direction rotateRight()
          Computes the direction 45 degrees to the right (clockwise) of this one.
static Direction valueOf(String name)
          Returns the enum constant of this type with the specified name.
static Direction[] values()
          Returns an array containing the constants of this enum type, in the order they are declared.
 
Methods inherited from class java.lang.Enum
clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Enum Constant Detail

NORTH

public static final Direction NORTH

NORTH_EAST

public static final Direction NORTH_EAST

EAST

public static final Direction EAST

SOUTH_EAST

public static final Direction SOUTH_EAST

SOUTH

public static final Direction SOUTH

SOUTH_WEST

public static final Direction SOUTH_WEST

WEST

public static final Direction WEST

NORTH_WEST

public static final Direction NORTH_WEST

NONE

public static final Direction NONE
No direction.


OMNI

public static final Direction OMNI
All directions.

Field Detail

dx

public final int dx

dy

public final int dy
Method Detail

values

public static Direction[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
for (Direction c : Direction.values())
    System.out.println(c);

Returns:
an array containing the constants of this enum type, in the order they are declared

valueOf

public static Direction valueOf(String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (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 type has no constant with the specified name
NullPointerException - if the argument is null

isDiagonal

public boolean isDiagonal()
Determines whether or not this direction is a diagonal one.

Returns:
true if this Direction is diagonal (northwest, northeast, southwest, southeast) or false if it's a cardinal, NONE, or OMNI.

opposite

public Direction opposite()
Computes the direction opposite this one.

Returns:
the direction pointing in the opposite direction to this one, or NONE if it's NONE, or OMNI if it's OMNI

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, or NONE if it's NONE, or OMNI if it's OMNI

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, or NONE if it's NONE, or OMNI if it's OMNI