gameLogic
Class Position

java.lang.Object
  extended by gameLogic.Position
All Implemented Interfaces:
java.io.Serializable

public class Position
extends java.lang.Object
implements java.io.Serializable

Represents a coordinate (x and y position) on the game board. All methods requiring coordinates as a parameter should be called using a Position object.

Author:
Sixten Hilborn, Arian Jafari
See Also:
Serialized Form

Constructor Summary
Position(int x, int y)
          Constructs a Position object with the given coordinates.
Position(Position position)
           
 
Method Summary
 boolean equals(java.lang.Object other)
           
 int getDistanceTo(Position other)
          Calculates the manhattan distance (the number of squares that must be traversed) between this Position and another Position.
 java.util.List<Position> getNeighbours()
          Get a list of all neighbours to this position.
 int getX()
          Gets the X coordinate of this position object.
 int getY()
          Gets the Y coordinate of this position object.
 int hashCode()
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Position

public Position(int x,
                int y)
Constructs a Position object with the given coordinates.

Parameters:
x - The x coordinate.
y - The y coordinate.

Position

public Position(Position position)
Method Detail

getX

public int getX()
Gets the X coordinate of this position object.

Returns:
The x coordinate of this position.

getY

public int getY()
Gets the Y coordinate of this position object.

Returns:
The y coordinate of this position.

getNeighbours

public java.util.List<Position> getNeighbours()
Get a list of all neighbours to this position. One position may have up to four neighbours (up, down, left and right).

Returns:
A list of neighbour positions.

getDistanceTo

public int getDistanceTo(Position other)
Calculates the manhattan distance (the number of squares that must be traversed) between this Position and another Position.

Parameters:
other - The Position to measure distance to.
Returns:
The manhattan distance between this and other.

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object other)
Overrides:
equals in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object