Position
Class Position

java.lang.Object
  |
  +--Position.Position

public class Position
extends java.lang.Object

H thesh enos antikeimenou panw ston xarth.

Invariant: oi syntetagmenes ths theshs (x,y) einai megalyteres h ises tou mhden, dhladh x>=0 kai y>=0.

Pedia ths klasshs: x: syntetegmenh x y: syntetagmenh y max_distance: h megisth apostash apo thn opoia ena zwo mporei na faei enan allon organismo.


Constructor Summary
Position(int x, int y)
          Constructor ths Position.
 
Method Summary
 boolean checkIfClose(Position.Position p)
          Mas leei an oi dyo theseis twn organismwn einai toso konta wste na mporei o enas na faei ton allon.
 double distance(Position.Position p)
          Epistrefei thn apostash dyo thesewn.
 int get_x()
          Epistrefei to x.
 int get_y()
          Epistrefei to y.
 boolean isEqual(Position.Position p)
          Elegxei an oi dyo theseis einai idies.
 boolean isInside(Position.Position p, int width, int height)
          Elegxei an to antikeimeno me authn thn thesh einai mesa sto antikeimeno me thesh p.
 void set_x(int x)
          Thetei to x.
 void set_y(int y)
          Thetei to y.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Position

public Position(int x,
                int y)
Constructor ths Position. Ftiaxnei ena neo Position me syntetagmenes x,y.

Precondition: Prepei ta x,y na einai egkyra. Dhladh x>=0 kai y>=0 kai x,y mesa sta oria tou xarth x<=x_max kai y<=y_max.

Postcondition: Ftiaxnoume mia nea thesh me syntetagmenes x,y.

Parameters:
x - H syntetagmenh x.
y - H syntetagmenh y.
Method Detail

get_x

public int get_x()
Epistrefei to x. Accesor - Selector.

Postcondition: Epistrefei to x.

Returns:
To x.

get_y

public int get_y()
Epistrefei to y. Accesor - Selector.

Postcondition: Epistrefei to y.

Returns:
To y.

set_x

public void set_x(int x)
Thetei to x. Transformer - Mutative.

Precondition: Egkyro x, dhladh x>=0 kai x mesa sta oria tou xarth.

Postcondition: Thetei to x.

Parameters:
x - H timh pou tha dwsoume sto x.

set_y

public void set_y(int y)
Thetei to y. Transformer - Mutative.

Precondition: Egkyro y, dhladh y>=0 kai y mesa sta oria tou xarth.

Postcondition: Thetei to y.

Parameters:
y - H timh pou tha dwsoume sto y.

checkIfClose

public boolean checkIfClose(Position.Position p)
Mas leei an oi dyo theseis twn organismwn einai toso konta wste na mporei o enas na faei ton allon. Accesor - Observer.

Postcondition: Epistrefei true an oi dyo theseis exoun diafora mikroterh h ish apo max_distance alliws false.

Returns:
true an oi dyo theseis diaferoun to poly kata max_distance alliws false.

isEqual

public boolean isEqual(Position.Position p)
Elegxei an oi dyo theseis einai idies. Accesor - Observer.

Postcondition: Epistrefei true an oi dyo theseis einai idies alliws false.

Returns:
true an oi dyo theseis einai idies alliws false.

distance

public double distance(Position.Position p)
Epistrefei thn apostash dyo thesewn. Accesor - Observer.

Postcondition: Epistrefei thn apostash ths theshs auths apo thn thesh p.

param p H thesh pou theloume na doume poso apexei apo th thesh pou eimaste.

Returns:
Thn apostash ths theshs auths apo thn thesh p.

isInside

public boolean isInside(Position.Position p,
                        int width,
                        int height)
Elegxei an to antikeimeno me authn thn thesh einai mesa sto antikeimeno me thesh p. Accesor - Observer. Ena antikeimeno einai mesa se ena allo an p.x<=this.x<=p.x+width kai p.y<=this.y<=p.y+height.

Postcondition: Epistrefei true an to antikeimeno me auth th thesh einai mesa sto antikeimeno me thesh p alliws false.

Parameters:
p - H thesh tou antikeimenou sto opoio theloume na doume an eimaste mesa.
width - To mhkos tou antikeimenou me thesh p.
height - To ypsos tou antikeimenou me thesh p.
Returns:
true an to antikeimeno me auth th thesh einai mesa sto antikeimeno me thesh p alliws false.