Class Position


  • public class Position
    extends Object
    Represents a position on the playfield.

    Objects of this class are immutable

    x is the row; negative towards the top (Direction.NORTH) and positive towards the bottom (Direction.SOUTH)

    y is the column; negative towards the left (Direction.WEST) and positive towards the right (Direction.EAST)

    Author:
    Tim Neumann
    See Also:
    Direction
    • Constructor Detail

      • Position

        public Position​(int x,
                        int y)
        Create a new position from the given parameters.
        Parameters:
        x - The x coordinate for the new position
        y - The y coordinate for the new position
    • Method Detail

      • getX

        public int getX()
        Returns:
        the x coordinate of this position
      • getY

        public int getY()
        Returns:
        the y coordinate of this position
      • adjacentPosition

        public Position adjacentPosition​(Direction direction)
        Get the adjacent position in the given direction.
        Parameters:
        direction - The direction to get the adjacent position in
        Returns:
        The position adjacent to this in the given direction
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object