Class Direction

java.lang.Object
Direction

public class Direction extends Object
A notion of the eight directions things can move in.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static 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
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    Return a random direction-value.
    static int
    turn(int dir, int amount)
    Return a direction-value which is the specified turn from the specified direction value.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • 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