jfreerails.world.common
Class PositionOnTrack

java.lang.Object
  extended by jfreerails.world.common.PositionOnTrack
All Implemented Interfaces:
java.io.Serializable, FreerailsMutableSerializable

public final class PositionOnTrack
extends java.lang.Object
implements FreerailsMutableSerializable

A mutable class that stores the coordinates of the tile on entity is standing on and the direction in which the entity is facing (usually the direction the entity as just been moving - the opposite to the direction it came from), it provides methods to encode and decode its field values to and from a single int.

Author:
Luke
See Also:
Serialized Form

Field Summary
private static int BITS_FOR_COORINATE
           
private static int BITS_FOR_DIRECTION
           
private  Step cameFrom
          The direction from which we entered the tile.
static int MAX_COORINATE
           
static int MAX_DIRECTION
           
private static long serialVersionUID
           
private  int x
           
private  int y
           
 
Constructor Summary
  PositionOnTrack()
           
  PositionOnTrack(int i)
           
private PositionOnTrack(int x, int y, Step direction)
           
 
Method Summary
 Step cameFrom()
           
static PositionOnTrack createComingFrom(int x, int y, Step direction)
           
static PositionOnTrack createFacing(int x, int y, Step direction)
           
 boolean equals(java.lang.Object o)
           
 Step facing()
           
static PositionOnTrack[] fromInts(int[] ints)
           
 PositionOnTrack getOpposite()
           
 int getX()
           
 int getY()
           
 int hashCode()
           
 void move(Step step)
           
 void setCameFrom(Step v)
           
 void setFacing(Step v)
           
 void setValuesFromInt(int i)
           
 void setX(int x)
           
 void setY(int y)
           
 int toInt()
           
static int[] toInts(PositionOnTrack[] pos)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

BITS_FOR_COORINATE

private static final int BITS_FOR_COORINATE
See Also:
Constant Field Values

BITS_FOR_DIRECTION

private static final int BITS_FOR_DIRECTION
See Also:
Constant Field Values

MAX_COORINATE

public static final int MAX_COORINATE
See Also:
Constant Field Values

MAX_DIRECTION

public static final int MAX_DIRECTION
See Also:
Constant Field Values

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

cameFrom

private Step cameFrom
The direction from which we entered the tile.


x

private int x

y

private int y
Constructor Detail

PositionOnTrack

public PositionOnTrack()

PositionOnTrack

public PositionOnTrack(int i)

PositionOnTrack

private PositionOnTrack(int x,
                        int y,
                        Step direction)
Method Detail

createComingFrom

public static PositionOnTrack createComingFrom(int x,
                                               int y,
                                               Step direction)

createFacing

public static PositionOnTrack createFacing(int x,
                                           int y,
                                           Step direction)

fromInts

public static PositionOnTrack[] fromInts(int[] ints)

toInts

public static int[] toInts(PositionOnTrack[] pos)

cameFrom

public Step cameFrom()
Returns:
The direction the entity came from.

equals

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

facing

public Step facing()
Returns:
The direction the entity is facing.

getOpposite

public PositionOnTrack getOpposite()
Returns:
the position on the track which is in the opposite direction.

getX

public int getX()

getY

public int getY()

hashCode

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

setCameFrom

public void setCameFrom(Step v)

setFacing

public void setFacing(Step v)

setValuesFromInt

public void setValuesFromInt(int i)

setX

public void setX(int x)

setY

public void setY(int y)

move

public void move(Step step)

toInt

public int toInt()
Returns:
an integer representing this PositionOnTrack object

toString

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