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.

Also provides a number of methods that can be called on a Direction object. Modifiers indicate the change involved with moving the given direction on a 2D board of squares. Whether for (row, col) or (x, y), the origin (0,0) is assumed to be the top-left of the board or screen.

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.
 int getXModifier()
          As getColModifier()
 int getYModifier()
          As getRowModifier()
 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 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

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 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

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.


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.


getXModifier

public int getXModifier()
As getColModifier()


getYModifier

public int getYModifier()
As getRowModifier()


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.)