gecco.client
Class Piece

java.lang.Object
  |
  +--gecco.client.Piece
Direct Known Subclasses:
AnimatedPiece, Ghost

public class Piece
extends Object

Represents a piece (unit) on the game board. A Piece has several properties; a unique identifier (handle), position, name and type.

Every new instance must be given a handle. The name is a descriptive String. The type determines what symbol to use.

A Piece has several so called Properties. A property contains of a name and value. Every Piece is assumed to only have one Property of a given name.

The Piece is linked to zero or more Actions; things that this specific piece can do. A Piece has a queue of action that are to be executed in order, and at most one action that is currently executed.

A piece contains a number of messages that describe things that has happened to the piece.

A Piece can be marked as selected by a boolean. Selected piece will be painted with a red rectangle around it.

Author:
Andreas Enblom

Field Summary
static int MAX_MESSAGES
          The maximum number of messages.
 
Constructor Summary
Piece(int handle)
          Constructor for the Piece object
Piece(int handle, Position position, String name, String type)
          Constructor for the Piece object
 
Method Summary
 void abortAllExecutingActions()
          Removes all executing actions of this piece (both queued and currenlty executing).
 void abortQueuedAction(Action a)
          Description of the Method
 void addAction(Action a)
          Adds the given actions to the list of available actions of this piece.
 void addMessage(String msg)
          Adds a feature to the Message attribute of the Piece object
 boolean equals(Object o)
          Description of the Method
 Action executeNextAction()
          Lets the next action execute.
 Enumeration getActions()
          Returns all actions that this piece can do.
 Vector getAllQueuedActions()
          Returns all actions that is currently queued for this piece.
 Action getExecutingAction()
          Returns the currently executing action, or null if no action is executing.
 int getHandle()
          Gets the Handle attribute of the Piece object
 Enumeration getMessages()
          Gets the Messages attribute of the Piece object
 String getName()
          Gets the Name attribute of the Piece object
 int getNumberOfMessages()
          Gets the NumberOfMessages attribute of the Piece object
 Position getPosition()
          Gets the Position attribute of the Piece object
 Property[] getProperties()
          Returns an array containing the properties of this Piece.
 Property getProperty(String name)
          Returns the property with the given name.
 Image getSymbol()
          Gets the Symbol attribute of the Piece object
 String getType()
          Gets the Type attribute of the Piece object
 int hashCode()
          Description of the Method
 boolean isSelected()
          Gets the Selected attribute of the Piece object
 void paint(Graphics g, Rectangle bounds)
          Paints the symbol on the given graphics, within the given bounding rectangle.
 void queue(Action a)
          Queues the given action, allowing it to be executed after the other actions has finished.
 void removeAction(Action a)
          Removes any action that has the same type as the given action from the list of available actions of this piece.
 void removeAllActions()
          Removes all actions that indicates what this piece can do.
 void removeProperty(String name)
          Removes the property with the given name from this Piece.
 void setName(String s)
          Sets the Name attribute of the Piece object
 void setPosition(Position p)
          Sets the Position attribute of the Piece object
 void setProperty(Property p)
          Adds the given property to the properties of this object.
 void setProperty(String name, String value)
          Adds a property with the given name and value to the properties of this object.
 void setSelected(boolean b)
          Sets the Selected attribute of the Piece object
 void setType(String s)
          Sets the Type attribute of the Piece object
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

MAX_MESSAGES

public static final int MAX_MESSAGES
The maximum number of messages.
Constructor Detail

Piece

public Piece(int handle)
Constructor for the Piece object
Parameters:
handle - Description of Parameter

Piece

public Piece(int handle,
             Position position,
             String name,
             String type)
Constructor for the Piece object
Parameters:
handle - Description of Parameter
position - Description of Parameter
name - Description of Parameter
type - Description of Parameter
Method Detail

setPosition

public void setPosition(Position p)
Sets the Position attribute of the Piece object
Parameters:
p - The new Position value

setName

public void setName(String s)
Sets the Name attribute of the Piece object
Parameters:
s - The new Name value

setType

public void setType(String s)
Sets the Type attribute of the Piece object
Parameters:
s - The new Type value

setSelected

public void setSelected(boolean b)
Sets the Selected attribute of the Piece object
Parameters:
b - The new Selected value

setProperty

public void setProperty(Property p)
Adds the given property to the properties of this object. If a property with such a name already is linked to this piece, it will be replaced.
Parameters:
p - The new Property value

setProperty

public void setProperty(String name,
                        String value)
Adds a property with the given name and value to the properties of this object. If a property with such a name already is linked to this piece, it will be replaced.
Parameters:
name - The new Property value
value - The new Property value

getHandle

public int getHandle()
Gets the Handle attribute of the Piece object
Returns:
The Handle value

getPosition

public Position getPosition()
Gets the Position attribute of the Piece object
Returns:
The Position value

getSymbol

public Image getSymbol()
Gets the Symbol attribute of the Piece object
Returns:
The Symbol value

getName

public String getName()
Gets the Name attribute of the Piece object
Returns:
The Name value

getType

public String getType()
Gets the Type attribute of the Piece object
Returns:
The Type value

isSelected

public boolean isSelected()
Gets the Selected attribute of the Piece object
Returns:
The Selected value

getActions

public Enumeration getActions()
Returns all actions that this piece can do.
Returns:
The Actions value

getProperty

public Property getProperty(String name)
Returns the property with the given name. If no such property exists, null is returned.
Parameters:
name - Description of Parameter
Returns:
The Property value

getMessages

public Enumeration getMessages()
Gets the Messages attribute of the Piece object
Returns:
The Messages value

getNumberOfMessages

public int getNumberOfMessages()
Gets the NumberOfMessages attribute of the Piece object
Returns:
The NumberOfMessages value

getProperties

public Property[] getProperties()
Returns an array containing the properties of this Piece. The array is sorted.
Returns:
The Properties value

getAllQueuedActions

public Vector getAllQueuedActions()
Returns all actions that is currently queued for this piece. This does not include the currently executing action.
Returns:
The AllQueuedActions value

getExecutingAction

public Action getExecutingAction()
Returns the currently executing action, or null if no action is executing.
Returns:
The ExecutingAction value

equals

public boolean equals(Object o)
Description of the Method
Overrides:
equals in class Object
Parameters:
o - Description of Parameter
Returns:
Description of the Returned Value

hashCode

public int hashCode()
Description of the Method
Overrides:
hashCode in class Object
Returns:
Description of the Returned Value

addAction

public void addAction(Action a)
Adds the given actions to the list of available actions of this piece. It is only the type of the actions that is of interest here.
Parameters:
a - The feature to be added to the Action attribute

removeAction

public void removeAction(Action a)
Removes any action that has the same type as the given action from the list of available actions of this piece. If there are such actions executing, the caller has to make sure that they are removed.
Parameters:
a - Description of Parameter

removeAllActions

public void removeAllActions()
Removes all actions that indicates what this piece can do.

removeProperty

public void removeProperty(String name)
Removes the property with the given name from this Piece.
Parameters:
name - Description of Parameter

addMessage

public void addMessage(String msg)
Adds a feature to the Message attribute of the Piece object
Parameters:
msg - The feature to be added to the Message attribute

queue

public void queue(Action a)
Queues the given action, allowing it to be executed after the other actions has finished.
Parameters:
a - Description of Parameter

abortQueuedAction

public void abortQueuedAction(Action a)
Description of the Method
Parameters:
a - Description of Parameter

abortAllExecutingActions

public void abortAllExecutingActions()
Removes all executing actions of this piece (both queued and currenlty executing). There is no connection with the server.

executeNextAction

public Action executeNextAction()
Lets the next action execute. Returns the Action to execute. If no more actions are to be executed, null is returned. There is no connection with the server.
Returns:
Description of the Returned Value

paint

public void paint(Graphics g,
                  Rectangle bounds)
Paints the symbol on the given graphics, within the given bounding rectangle.
Parameters:
g - Description of Parameter
bounds - Description of Parameter

toString

public String toString()
Overrides:
toString in class Object