org.vizzini.game
Class AbstractEngine

java.lang.Object
  extended by org.vizzini.game.AbstractEngine
All Implemented Interfaces:
IEngine
Direct Known Subclasses:
AsynchronousEngine, SynchronousEngine

public abstract class AbstractEngine
extends Object
implements IEngine

Provides base functionality for engines in the game framework. An engine instance encapsulates the game mechanics, meaning how the agents interact. Examples of engines include a synchronous engine, where agents take turns, a simultaneous engine, where each agent's actions occur at the same time, or an asynchronous engine, where the agent's actions occur at any time and any amount.

Since:
v0.1
Version:
v0.3
Author:
Jeffrey M. Thompson

Constructor Summary
AbstractEngine()
           
 
Method Summary
 void addGameListener(IGameListener listener)
          Add the given listener.
 void configure(Properties properties)
          Configure this engine.
protected  Thread createGameThread(IEngine engine)
          Create the internal game thread.
protected  void cycleSleep(long start)
          Sleep for long enough to bring the cycle time up to the minimum.
protected  ActionCollection getActionList()
          Return the action list.
 IAgent getCurrentAgent()
          Return the current agent.
 IEnvironment getEnvironment()
          Return the environment.
protected  Thread getGameThread()
          Return the game thread.
 long getMinCycleTime()
          Return the minimum cycle time.
 boolean isFiringGameChanges()
          Return true if this is set to fire game change events.
 boolean isGameOver()
          Return true if the game is over.
 boolean isPaused()
          Return true if this is paused.
 void pause()
          Pause the engine.
 void removeGameListener(IGameListener listener)
          Remove the given listener.
 void reset()
          Reset to the initial state.
 void resume()
          Resume the engine from a pause.
protected  void setCurrentAgent(IAgent agent)
          Set the current agent.
 void setEnvironment(IEnvironment environment)
          Set the environment to the given value.
 void setFiringGameChanges(boolean fire)
          Set the flag which indicates whether to fire game change events.
 void setGameOver(boolean isGameOver, IAgent winner)
          Set the game over flag to the given value.
 void setMinCycleTime(long minCycleTime)
          Set the minimum cycle time.
 void start()
          Start the engine by starting the game loop thread.
 void step()
          Step the engine.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.vizzini.game.IEngine
run
 

Constructor Detail

AbstractEngine

public AbstractEngine()
Method Detail

addGameListener

public void addGameListener(IGameListener listener)
Add the given listener.

Specified by:
addGameListener in interface IEngine
Since:
v0.1

configure

public void configure(Properties properties)
               throws InstantiationException,
                      IllegalAccessException
Configure this engine.

Specified by:
configure in interface IEngine
Parameters:
properties - Source of configuration information.
Throws:
InstantiationException
IllegalAccessException
Since:
v0.1

getCurrentAgent

public IAgent getCurrentAgent()
Return the current agent.

Specified by:
getCurrentAgent in interface IEngine
Since:
v0.1

getEnvironment

public IEnvironment getEnvironment()
Return the environment.

Specified by:
getEnvironment in interface IEngine
Since:
v0.1

getMinCycleTime

public long getMinCycleTime()
Return the minimum cycle time.

Specified by:
getMinCycleTime in interface IEngine
Since:
v0.1

isFiringGameChanges

public boolean isFiringGameChanges()
Return true if this is set to fire game change events.

Specified by:
isFiringGameChanges in interface IEngine
Since:
v0.3

isGameOver

public boolean isGameOver()
Return true if the game is over.

Specified by:
isGameOver in interface IEngine
Since:
v0.1

isPaused

public boolean isPaused()
Return true if this is paused.

Specified by:
isPaused in interface IEngine
Since:
v0.1

pause

public void pause()
Pause the engine.

Specified by:
pause in interface IEngine
Since:
v0.1

removeGameListener

public void removeGameListener(IGameListener listener)
Remove the given listener.

Specified by:
removeGameListener in interface IEngine
Since:
v0.1

reset

public void reset()
Reset to the initial state.

Specified by:
reset in interface IEngine
Since:
v0.1

resume

public void resume()
Resume the engine from a pause.

Specified by:
resume in interface IEngine
Since:
v0.1

setEnvironment

public void setEnvironment(IEnvironment environment)
Set the environment to the given value.

Specified by:
setEnvironment in interface IEngine
Parameters:
environment - The new environment.
Since:
v0.1

setFiringGameChanges

public void setFiringGameChanges(boolean fire)
Set the flag which indicates whether to fire game change events.

Specified by:
setFiringGameChanges in interface IEngine
Since:
v0.3

setGameOver

public void setGameOver(boolean isGameOver,
                        IAgent winner)
Set the game over flag to the given value.

Specified by:
setGameOver in interface IEngine
Parameters:
isGameOver - The new value.
Since:
v0.1

setMinCycleTime

public void setMinCycleTime(long minCycleTime)
Set the minimum cycle time.

Specified by:
setMinCycleTime in interface IEngine
Since:
v0.1

start

public void start()
Start the engine by starting the game loop thread.

Specified by:
start in interface IEngine
Since:
v0.1

step

public void step()
Step the engine.

Specified by:
step in interface IEngine
Since:
v0.1

createGameThread

protected Thread createGameThread(IEngine engine)
Create the internal game thread. This thread calls the run method.

Parameters:
engine - The owning engine.
Since:
v0.1

cycleSleep

protected void cycleSleep(long start)
Sleep for long enough to bring the cycle time up to the minimum.

Since:
v0.1

getActionList

protected ActionCollection getActionList()
Return the action list.

Since:
v0.1

getGameThread

protected Thread getGameThread()
Return the game thread.

Since:
v0.1

setCurrentAgent

protected void setCurrentAgent(IAgent agent)
Set the current agent.

Since:
v0.1


Copyright 2007 Vizzini.org. All Rights Reserved. 2007.12.25.03.00.02