gameLogic
Enum Direction

java.lang.Object
  extended by java.lang.Enum<Direction>
      extended by gameLogic.Direction
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable<Direction>

public enum Direction
extends java.lang.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.

Author:
Sixten Hilborn, Arian Jafari

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

NORTH

public static final Direction NORTH

WEST

public static final Direction WEST

SOUTH

public static final Direction SOUTH

EAST

public static final Direction EAST
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(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

getDirectionVector

public Position getDirectionVector()

calculateNextPosition

public Position calculateNextPosition(Position oldPosition)
Gets the next position a snake would end up in if it continues in this direction.

Parameters:
oldPosition - The current position of the snake.
Returns:
The next position if movement continues in this direction.

turnLeft

public Direction turnLeft()
Returns a new direction that would be the same as turning left.

Returns:
The direction towards which one would move if one turned left.

turnRight

public Direction turnRight()
Returns a new direction that would be the same as turning right.

Returns:
The direction towards which one would move if one turned right.

getDirectionFromPositionToPosition

public static Direction getDirectionFromPositionToPosition(Position from,
                                                           Position to)
Returns the direction between two positions, as long as they are on a straight line.

Parameters:
from - The starting position
to - The destination position.
Returns:
The direction towards which one needs to move from the starting position in order to reach the destination.
Throws:
java.lang.IllegalArgumentException - either if the two positions are the same or if they are not on a straight line.