nankin.zheng.gatem.util
Class Position

java.lang.Object
  |
  +--nankin.zheng.gatem.util.Position

public class Position
extends java.lang.Object

Logical position of a role on the whole map.

Version:
1.0, Date 2003-04-11
Author:
ZHENG Zhong

Field Summary
 int x
           
 int y
           
 
Constructor Summary
Position()
          Constructor.
Position(int x, int y)
          Constructor, create according to x and y.
 
Method Summary
 java.lang.Object clone()
          Clone a copy
 int distance(Position p)
          Calculate the distance between itself and another position.
 boolean equals(java.lang.Object p)
          Whether equals.
 void move(int direction)
          move the positon in a given direction
 void round(int width, int height)
          Round both its x and its y to the nearest block with the given width and height of the block.
private  int roundNumber(int n, int step)
          Round number n to the nearest block whose width is step.
 void set(int x, int y)
          Initialize according to coordonates x and y
 void set(Position p)
          Initialize according to another position
 java.lang.String toString()
          Convert to String.
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

x

public int x

y

public int y
Constructor Detail

Position

public Position(int x,
                int y)
Constructor, create according to x and y.

Parameters:
x - x of position
y - y of position

Position

public Position()
Constructor.

Method Detail

distance

public int distance(Position p)
Calculate the distance between itself and another position. The distance is in integer format.

Parameters:
p - position to calculate the distance, cannot be null
Throws:
java.lang.NullPointerException - if p is null

set

public void set(Position p)
Initialize according to another position

Parameters:
p - position to be copied, cannot be null
Throws:
java.lang.NullPointerException - if p is null

set

public void set(int x,
                int y)
Initialize according to coordonates x and y

Parameters:
x - x of position
y - y of position

move

public void move(int direction)
move the positon in a given direction

Parameters:
direction - to move, whose value is defined in class Env

round

public void round(int width,
                  int height)
Round both its x and its y to the nearest block with the given width and height of the block.

Parameters:
width - width of the block
height - height of the block

roundNumber

private int roundNumber(int n,
                        int step)
Round number n to the nearest block whose width is step. For example: - roundNumber(5,4) returns 4 - roundNumber(27,4) returns 28 This private method supports public method round.

Parameters:
n - number to be rounded
step - step width of the block

toString

public java.lang.String toString()
Convert to String.

Overrides:
toString in class java.lang.Object

equals

public boolean equals(java.lang.Object p)
Whether equals.

Overrides:
equals in class java.lang.Object
Parameters:
p - position to be compared

clone

public java.lang.Object clone()
Clone a copy

Overrides:
clone in class java.lang.Object