public enum Direction extends Enum<Direction>
for (Direction d : Direction.values()) { ... }
Modifier and Type | Method and Description |
---|---|
Point |
forward(Point p)
The point one step forward in this direction.
|
Point |
forward(Point p,
int n)
The point n steps forward in this direction.
|
abstract Point |
forward(Point p,
int n,
Point overwrite)
Computes the point n steps forward in this direction,
saves it to overwrite, and then returns overwrite.
|
static Direction |
fromInt(int i) |
static Direction |
fromTo(Point a,
Point b)
Returns the larger direction from a to b, favoring the vertical.
|
boolean |
isHorizontal()
True for East and West
|
boolean |
isVertical()
True for North and South
|
abstract Direction |
left()
The direction 90-degrees to the left.
|
Direction |
left(int n)
The direction 90*n-degrees to the left.
|
int |
numTurns(Direction d)
The number of turns needed to reach direction d from this direction.
|
abstract Direction |
opposite()
Returns the direction 180 degrees from this one.
|
static Direction |
random()
Uniformly distributed random direction.
|
static Direction |
random(Random r)
Uniformly distributed random direction.
|
abstract Direction |
right()
The direction 90-degrees to the right.
|
Direction |
right(int n)
The direction 90*n-degrees to the right.
|
abstract int |
toInt()
Returns a number between 0 and 3: NORTH = 0, EAST = 1, ...
|
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.
|
public static final Direction NORTH
public static final Direction WEST
public static final Direction SOUTH
public static final Direction EAST
public static Direction[] values()
for (Direction c : Direction.values()) System.out.println(c);
public static Direction valueOf(String name)
name
- the name of the enum constant to be returned.IllegalArgumentException
- if this enum type has no constant
with the specified nameNullPointerException
- if the argument is nullpublic static Direction random()
public Direction left(int n)
public Direction right(int n)
public abstract Direction left()
public abstract Direction right()
public boolean isHorizontal()
public boolean isVertical()
public int numTurns(Direction d)
public static Direction fromTo(Point a, Point b)
public abstract Direction opposite()
public abstract Point forward(Point p, int n, Point overwrite)
public abstract int toInt()
public static Direction fromInt(int i)