gecco.server.automaton
Class Automaton

java.lang.Object
  |
  +--gecco.server.automaton.Automaton
Direct Known Subclasses:
AutomatonImpl, AutomatonImpl, AutomatonImpl

public abstract class Automaton
extends Object

The superclass for the automaton used in a game. This class should be subclassed by every game implementation. For each point on the map, one instance of this class is instanciated. Concrete subclasses should implement all states of the automaton and the different events that should be sent from or to the automaton. In particular, the subclasses should determine what colour the automaton should have, because that will be the colour of that pixel on the map. It is to subclass this class that the game designer can make the map dynamic in many ways, for example to let a fire spread across the map.

Author:
Henrik Bäärnhielm, Karl Hasselström, Henrik Hägerström

Field Summary
protected  Color currentColor
          The current color which is to be sent to the client in a given state.
 
Constructor Summary
Automaton()
          Constructor for the Automaton object
 
Method Summary
 Color getCurrentColor()
          Gets the CurrentColor attribute of the Automaton object
 int getState()
          Gets the State attribute of the Automaton object
abstract  UnitEvent getUnitEventForCurrentState(String unitType)
          Gets the UnitEvent for the current state of the automaton.
abstract  AutomatonReturn handleEvent(AutomatonEvent event)
          Handles incoming event to the automaton.
 boolean hasChanged()
          Indicates if the automaton has changed state since the last call to this method.
 void initialize(int initialState)
          Initialises the automaton.
 void setCurrentColor(int r, int g, int b)
          Sets the current color for the automaton.
protected  void setState(int newState)
          Sets the State attribute of the Automaton object
abstract  AutomatonReturn update(int[][] neighbourStates)
          The update method of the automaton.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

currentColor

protected Color currentColor
The current color which is to be sent to the client in a given state.
Constructor Detail

Automaton

public Automaton()
Constructor for the Automaton object
Method Detail

setCurrentColor

public void setCurrentColor(int r,
                            int g,
                            int b)
Sets the current color for the automaton.
Parameters:
r - The red component of the new color.
g - The gree component of the new color.
b - The blue component of the new color.

getUnitEventForCurrentState

public abstract UnitEvent getUnitEventForCurrentState(String unitType)
Gets the UnitEvent for the current state of the automaton. This method is called when a unit moves over the automaton.
Parameters:
unitType - The name of the UnitType of the unit that has moved over the automaton
Returns:
The UnitEvent for the current state. May be null if there is no event for this state.

getCurrentColor

public Color getCurrentColor()
Gets the CurrentColor attribute of the Automaton object
Returns:
The CurrentColor value

getState

public int getState()
Gets the State attribute of the Automaton object
Returns:
The State value

initialize

public void initialize(int initialState)
Initialises the automaton. Is only used by the game engine after the automaton has been dynamically loaded and instanciated.
Parameters:
initialState - Description of Parameter

update

public abstract AutomatonReturn update(int[][] neighbourStates)
The update method of the automaton. The states of the surronding automatons is provided in a 3x3 integer grid. The neighbour to the upper left is [0][0], the neighbour to the upper right is in [2][0].
Parameters:
neighbourStates - The states of the surrounding automatons, given in a 3x3 integer grid.
Returns:
An AutomatonReturn object

handleEvent

public abstract AutomatonReturn handleEvent(AutomatonEvent event)
Handles incoming event to the automaton.
Parameters:
event - The AutomatonEvent
Returns:
An AutomatonReturn object

hasChanged

public boolean hasChanged()
Indicates if the automaton has changed state since the last call to this method.
Returns:
true if the state has been changed, false otherwise

setState

protected void setState(int newState)
Sets the State attribute of the Automaton object
Parameters:
newState - The new State value