Enum Direction

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

public enum Direction
extends Enum<Direction>

One of 9 possible directions an object can move on a 2D board of squares. Includes the 8 cardinal and intermediate compass directions (N, NE, E, etc.) plus HERE, which means the current square.

Version:
08 Nov 2008
Author:
Zach Tomaszewski

Enum Constant Summary
E
           
HERE
           
N
           
NE
           
NW
           
S
           
SE
           
SW
           
W
           
 
Method Summary
 int getColModifier()
          Returns the X/column change on the screen that is associated with this direction: -1 for W, 0 for N/S, and +1 for E.
 int getRowModifier()
          Returns the Y/row change on the screen that is associated with this direction: -1 for N, 0 for E/W, and +1 for south.
 Direction reverse()
          Returns the direction that is the opposite 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're declared.
 
Methods inherited from class java.lang.Enum
clone, compareTo, equals, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Enum Constant Detail

N

public static final Direction N

NE

public static final Direction NE

E

public static final Direction E

SE

public static final Direction SE

S

public static final Direction S

SW

public static final Direction SW

W

public static final Direction W

NW

public static final Direction NW

HERE

public static final Direction HERE
Method Detail

values

public static final Direction[] values()
Returns an array containing the constants of this enum type, in the order they're 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're 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

getRowModifier

public int getRowModifier()
Returns the Y/row change on the screen that is associated with this direction: -1 for N, 0 for E/W, and +1 for south.


getColModifier

public int getColModifier()
Returns the X/column change on the screen that is associated with this direction: -1 for W, 0 for N/S, and +1 for E.


reverse

public Direction reverse()
Returns the direction that is the opposite of this one. For example, Direction.NE.reverse() == Direction.SW. (The opposite of HERE is still HERE though.)