Class Direction
java.lang.Object
Direction
A notion of the eight directions things can move in.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
static final int
The largest possible direction value.static final int
The smallest possible direction value.static final int
static final int
static final int
static final int
The number of direction values.static final int
static final int
static final int
static final int
static final int
-
Constructor Summary
Constructors -
Method Summary
-
Field Details
-
NONE
public static final int NONE- See Also:
-
NORTH
public static final int NORTH- See Also:
-
NE
public static final int NE- See Also:
-
EAST
public static final int EAST- See Also:
-
SE
public static final int SE- See Also:
-
SOUTH
public static final int SOUTH- See Also:
-
SW
public static final int SW- See Also:
-
WEST
public static final int WEST- See Also:
-
NW
public static final int NW- See Also:
-
MIN_DIRECTION
public static final int MIN_DIRECTIONThe smallest possible direction value.- See Also:
-
MAX_DIRECTION
public static final int MAX_DIRECTIONThe largest possible direction value.- See Also:
-
NUM_DIRECTIONS
public static final int NUM_DIRECTIONSThe number of direction values.- See Also:
-
-
Constructor Details
-
Direction
public Direction()
-
-
Method Details
-
turn
public static int turn(int dir, int amount) Return a direction-value which is the specified turn from the specified direction value. The turn amount is the number of directions to turn - e.g. turn(Direction.NORTH,2) will return Direction.EAST. A negative amount means to turn counter-clockwise, a positive amount turns clockwise.- Parameters:
dir
- the direction (MIN_DIRECTION <= dir <= MAX_DIRECTION)amount
- the number of directions to turn from the current direction (positive = clockwise, negative = counter-clockwise)- Returns:
- the new direction
-
random
public static int random()Return a random direction-value.- Returns:
- random direction value
-