net.sf.freecol.common.model
Enum Map.Direction

java.lang.Object
  extended by java.lang.Enum<Map.Direction>
      extended by net.sf.freecol.common.model.Map.Direction
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable<Map.Direction>
Enclosing class:
Map

public static enum Map.Direction
extends java.lang.Enum<Map.Direction>

The directions a Unit can move to. Includes deltas for moving to adjacent squares, which are required due to the isometric map. Starting north and going clockwise.


Enum Constant Summary
E
           
N
           
NE
           
NW
           
S
           
SE
           
SW
           
W
           
 
Field Summary
static Map.Direction[] corners
           
private  int evenDX
           
private  int evenDY
           
static Map.Direction[] longSides
           
static int NUMBER_OF_DIRECTIONS
           
private  int oddDX
           
private  int oddDY
           
 
Method Summary
 Map.Direction[] getClosestDirections(java.lang.String logMe, java.util.Random random)
          Creates an array of the directions in an order that favours a supplied one.
 int getEvenDX()
           
 int getEvenDY()
           
 java.lang.String getNameKey()
           
 Map.Direction getNextDirection()
          Get the next direction after this one (clockwise).
 int getOddDX()
           
 int getOddDY()
           
 Map.Direction getPreviousDirection()
          Get the previous direction after this one (anticlockwise).
static Map.Direction getRandomDirection(java.lang.String logMe, java.util.Random random)
          Gets a random Direction.
static Map.Direction[] getRandomDirections(java.lang.String logMe, java.util.Random random)
          Creates an array of the eight directions in a random order.
 Map.Direction getReverseDirection()
          Returns the reverse direction of the given direction.
private  Map.Direction rotate(int n)
          Gets this direction rotated by n places.
static Map.Direction valueOf(java.lang.String name)
          Returns the enum constant of this type with the specified name.
static Map.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 Map.Direction N

NE

public static final Map.Direction NE

E

public static final Map.Direction E

SE

public static final Map.Direction SE

S

public static final Map.Direction S

SW

public static final Map.Direction SW

W

public static final Map.Direction W

NW

public static final Map.Direction NW
Field Detail

NUMBER_OF_DIRECTIONS

public static final int NUMBER_OF_DIRECTIONS

longSides

public static final Map.Direction[] longSides

corners

public static final Map.Direction[] corners

oddDX

private int oddDX

oddDY

private int oddDY

evenDX

private int evenDX

evenDY

private int evenDY
Method Detail

values

public static Map.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 (Map.Direction c : Map.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 Map.Direction valueOf(java.lang.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:
java.lang.IllegalArgumentException - if this enum type has no constant with the specified name
java.lang.NullPointerException - if the argument is null

getOddDX

public int getOddDX()

getOddDY

public int getOddDY()

getEvenDX

public int getEvenDX()

getEvenDY

public int getEvenDY()

rotate

private Map.Direction rotate(int n)
Gets this direction rotated by n places.

Parameters:
n - The number of places to rotate.
Returns:
The rotated direction.

getNextDirection

public Map.Direction getNextDirection()
Get the next direction after this one (clockwise).

Returns:
The next Direction.

getPreviousDirection

public Map.Direction getPreviousDirection()
Get the previous direction after this one (anticlockwise).

Returns:
The previous Direction.

getReverseDirection

public Map.Direction getReverseDirection()
Returns the reverse direction of the given direction.

Returns:
The reverse Direction.

getNameKey

public java.lang.String getNameKey()

getRandomDirection

public static Map.Direction getRandomDirection(java.lang.String logMe,
                                               java.util.Random random)
Gets a random Direction.

Parameters:
logMe - A string to log with the random results.
random - A Random number source.
Returns:
A random Direction value.

getRandomDirections

public static Map.Direction[] getRandomDirections(java.lang.String logMe,
                                                  java.util.Random random)
Creates an array of the eight directions in a random order.

Parameters:
logMe - A string to log with the random results.
random - A Random number source.
Returns:
An array of the Directions in a random order.

getClosestDirections

public Map.Direction[] getClosestDirections(java.lang.String logMe,
                                            java.util.Random random)
Creates an array of the directions in an order that favours a supplied one. Entry 0 will be the supplied direction, entry 1+2 will be those immediately to the left and right of it (chosen randomly), and so on until the last entry will be the complete reverse of the supplied direction. Useful if we to step in a particular direction, but if this fails to be able to try the closest other directions to the original one in order.

Parameters:
logMe - A string to log with the random results.
random - A Random number source.
Returns:
An array of the Directions favouring this one.