|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | ENUM CONSTANTS | FIELD | METHOD | DETAIL: ENUM CONSTANTS | FIELD | METHOD |
java.lang.Objectjava.lang.Enum<Direction>
gameLogic.Direction
public enum Direction
This is an enum representing a direction in which a snake can move. Directions are what getNextMove in the Brain interface are supposed to return. Note that these are absolute directions, e.g. NORTH, and not relative directions, e.g. FORWARD.
Enum Constant Summary | |
---|---|
EAST
|
|
NORTH
|
|
SOUTH
|
|
WEST
|
Method Summary | |
---|---|
Position |
calculateNextPosition(Position oldPosition)
Gets the next position a snake would end up in if it continues in this direction. |
static Direction |
getDirectionFromPositionToPosition(Position from,
Position to)
Returns the direction between two positions, as long as they are on a straight line. |
Position |
getDirectionVector()
|
Direction |
turnLeft()
Returns a new direction that would be the same as turning left. |
Direction |
turnRight()
Returns a new direction that would be the same as turning right. |
static Direction |
valueOf(java.lang.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 |
---|
compareTo, equals, getDeclaringClass, hashCode, name, ordinal, toString, valueOf |
Methods inherited from class java.lang.Object |
---|
getClass, notify, notifyAll, wait, wait, wait |
Enum Constant Detail |
---|
public static final Direction NORTH
public static final Direction WEST
public static final Direction SOUTH
public static final Direction EAST
Method Detail |
---|
public static Direction[] values()
for (Direction c : Direction.values()) System.out.println(c);
public static Direction valueOf(java.lang.String name)
name
- the name of the enum constant to be returned.
java.lang.IllegalArgumentException
- if this enum type has no constant
with the specified name
java.lang.NullPointerException
- if the argument is nullpublic Position getDirectionVector()
public Position calculateNextPosition(Position oldPosition)
oldPosition
- The current position of the snake.
public Direction turnLeft()
public Direction turnRight()
public static Direction getDirectionFromPositionToPosition(Position from, Position to)
from
- The starting positionto
- The destination position.
java.lang.IllegalArgumentException
- either if the two positions are the same
or if they are not on a straight line.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | ENUM CONSTANTS | FIELD | METHOD | DETAIL: ENUM CONSTANTS | FIELD | METHOD |