simuLCS
Class Entity

java.lang.Object
  extended bysimuLCS.Entity
Direct Known Subclasses:
Agent, Arena, Food

public abstract class Entity
extends java.lang.Object

Superclass of all the entities, providing basic functions, but relying a lot on the implementation given by subclasses.

Author:
Benoit

Field Summary
protected  java.awt.Color color_ext
          The color of the border of the entity.
protected  java.awt.Color color_int
          The color inside the entity.
protected  java.awt.geom.Point2D coord
          Current position of the entity
protected  java.util.Random generator
          Pointer to the Random generator
private  int id
          unique for each entity
protected  java.lang.String name
           
private static int nbInstances
          To obtain the unique id
protected  boolean paintName
          Boolean which indicates whether or not the name of the Agent should be painted.
protected  int size
           
 
Constructor Summary
Entity()
           
 
Method Summary
 void clear(java.awt.Graphics2D g, java.awt.geom.Point2D c)
          Clear the drawing of the agent at the indicated coordinates (Basically, a white circle is drawn)
 boolean collideWithMe(Agent a)
          By default, returns false.
 double distanceTo(java.awt.geom.Point2D p)
          Calculates the distance between the CENTER of this entity and another point p.
 java.awt.Color getColor_ext()
           
 java.awt.Color getColor_int()
           
 java.awt.geom.Point2D getCoord()
           
 java.awt.geom.Point2D getCoordNearTo(Entity otherEntity)
          By default, the closest coordinates of an entity are its normal coordinates.
 int getId()
           
 java.lang.String getName()
           
 double getRadiusBody()
           
 int getSize()
           
abstract  boolean isDangerous()
          Should be defined by subclasses
abstract  boolean isMoving()
          Should be defined by subclasses
 boolean isPaintName()
          Indicates if the name should be painted
abstract  void move(Arena a, Entity[] others, int nbEntities, java.awt.Graphics2D g)
          Subclasses must explain how the entity moves.
 void paint(java.awt.Graphics2D g)
          Paint the entity.
 void setColor_ext(java.awt.Color color)
          Set the color of the outer circle.
 void setColor_int(java.awt.Color color)
          Set the color of the inner circle.
 void setName(java.lang.String string)
           
 void setPaintName(boolean b)
          Set the parameter paintName to the boolean b.
 void setSize(int s)
           
 java.lang.String toString()
          Returns a string describing the Entity.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

nbInstances

private static int nbInstances
To obtain the unique id


id

private int id
unique for each entity


name

protected java.lang.String name

coord

protected java.awt.geom.Point2D coord
Current position of the entity


size

protected int size

generator

protected java.util.Random generator
Pointer to the Random generator

See Also:
Random

color_int

protected java.awt.Color color_int
The color inside the entity.


color_ext

protected java.awt.Color color_ext
The color of the border of the entity.


paintName

protected boolean paintName
Boolean which indicates whether or not the name of the Agent should be painted.

Constructor Detail

Entity

public Entity()
Method Detail

paint

public void paint(java.awt.Graphics2D g)
Paint the entity. Default painting is a circle, should be overriden for a different drawing.


clear

public void clear(java.awt.Graphics2D g,
                  java.awt.geom.Point2D c)
Clear the drawing of the agent at the indicated coordinates (Basically, a white circle is drawn)

Parameters:
g - Graphics
c - The coordinates where to clear the drawing of the agent.

getCoordNearTo

public java.awt.geom.Point2D getCoordNearTo(Entity otherEntity)
By default, the closest coordinates of an entity are its normal coordinates. Should be overriden for special subclasses (ex: the Arena)


distanceTo

public double distanceTo(java.awt.geom.Point2D p)
Calculates the distance between the CENTER of this entity and another point p. Should be overriden to handle walls (Arena).

Parameters:
p - Point2D
Returns:
the distance between the point and the center of the agent

collideWithMe

public boolean collideWithMe(Agent a)
By default, returns false. Should be overriden by subclasses

Parameters:
a -
Returns:

isDangerous

public abstract boolean isDangerous()
Should be defined by subclasses

Returns:

isMoving

public abstract boolean isMoving()
Should be defined by subclasses

Returns:

move

public abstract void move(Arena a,
                          Entity[] others,
                          int nbEntities,
                          java.awt.Graphics2D g)
Subclasses must explain how the entity moves. In subclasses, an Agent might move according to the positions of the other agents, while the Arena or some Food might not move at all.

Parameters:
a - The Arena inside which to move
g - Graphics
See Also:
AgentDuck.move(Arena, Entity[], int, Graphics2D), AgentClassifier.move(Arena, Entity[], int, Graphics2D)

getId

public int getId()
Returns:

getName

public java.lang.String getName()
Returns:

setName

public void setName(java.lang.String string)
Parameters:
string -

getCoord

public java.awt.geom.Point2D getCoord()

setSize

public void setSize(int s)

getSize

public int getSize()

getRadiusBody

public double getRadiusBody()

getColor_ext

public java.awt.Color getColor_ext()
Returns:
The color of the outer circle.

getColor_int

public java.awt.Color getColor_int()
Returns:
The color of the inner circle.

setColor_ext

public void setColor_ext(java.awt.Color color)
Set the color of the outer circle.

Parameters:
color -

setColor_int

public void setColor_int(java.awt.Color color)
Set the color of the inner circle.

Parameters:
color -

isPaintName

public boolean isPaintName()
Indicates if the name should be painted

Returns:
true if it should be painted, false otherwise.
See Also:
paintName

setPaintName

public void setPaintName(boolean b)
Set the parameter paintName to the boolean b.

Parameters:
b -
See Also:
paintName

toString

public java.lang.String toString()
Returns a string describing the Entity.