Package com.iwolverton.smartbeetle
Enum Direction
- java.lang.Object
-
- java.lang.Enum<Direction>
-
- com.iwolverton.smartbeetle.Direction
-
- All Implemented Interfaces:
Serializable,Comparable<Direction>
public enum Direction extends Enum<Direction>
Cardinal direction on the game field.Note that in the game's coordinates,right (E) and down (S) are positive.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static DirectionforAxis(Axis axis, int sign)Get the direction that has the given sign on the given axis.static DirectionforX(int sign)Get the direction that has the given sign on the x axis.static DirectionforY(int sign)Get the direction that has the given sign on the y axis.AxisgetAxis()whether this is an x-axis or y-axis directionintgetSign()on this direction's axis, is it positive or negative (1 or -1).intgetX()x-axis component of the direction: either -1, 0, or 1intgetY()y-axis component of the direction: either -1, 0, or 1DirectionnextClockwise()Return the direction that is 90 degrees clockwise from this one.DirectionnextCounterclockwise()Return the direction that is 90 degrees counterclockwise from this one.Directionopposite()The opposite direction.CoordrelativeTo(Coord coord)Return the coordinate that is 1 unit of this direction from the given coordinate.CoordrelativeTo(Coord coord, int dist)Return the coordinate that is dist units of this direction from the given coordinate.static DirectionvalueOf(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.
-
-
-
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 nameNullPointerException- if the argument is null
-
getX
public int getX()
x-axis component of the direction: either -1, 0, or 1
-
getY
public int getY()
y-axis component of the direction: either -1, 0, or 1
-
getAxis
public Axis getAxis()
whether this is an x-axis or y-axis direction
-
getSign
public int getSign()
on this direction's axis, is it positive or negative (1 or -1).
-
relativeTo
public Coord relativeTo(Coord coord)
Return the coordinate that is 1 unit of this direction from the given coordinate.
-
relativeTo
public Coord relativeTo(Coord coord, int dist)
Return the coordinate that is dist units of this direction from the given coordinate.
-
opposite
public Direction opposite()
The opposite direction. E.g. N is the opposite of S.
-
forAxis
public static Direction forAxis(Axis axis, int sign)
Get the direction that has the given sign on the given axis.- Parameters:
sign- any number, only the sign (positive, negative or 0) will be taken into account.
-
nextClockwise
public Direction nextClockwise()
Return the direction that is 90 degrees clockwise from this one.
-
nextCounterclockwise
public Direction nextCounterclockwise()
Return the direction that is 90 degrees counterclockwise from this one.
-
forX
public static Direction forX(int sign)
Get the direction that has the given sign on the x axis.- Parameters:
sign- any number, only the sign (positive, negative or 0) will be taken into account.
-
forY
public static Direction forY(int sign)
Get the direction that has the given sign on the y axis.- Parameters:
sign- any number, only the sign (positive, negative or 0) will be taken into account.
-
-