org.gjt.universe
Class GameEngine

java.lang.Object
  |
  +--java.lang.Thread
        |
        +--org.gjt.universe.GameEngine
All Implemented Interfaces:
java.lang.Runnable

public final class GameEngine
extends java.lang.Thread

This class starts and runs the game.

Version:
$Id: GameEngine.java,v 1.12 2001/07/01 06:53:25 noordvyk Exp $

Nested Class Summary
private  class GameEngine.ProcessedTurnStruct
           
 
Field Summary
private  boolean gameOptionsProcessed
          Flag to indicate whether the game options have been processed.
private  boolean gameOptionsSubmitted
          Flag to indicate whether the game options have been submitted.
private  GameOptions options
          The game options
static java.util.Random randomGen
           
private static boolean running
          Flag to indicate whether the game is currently running.
private static GameEngine single
          Instance of GameEngine used in implementing the Singleton design pattern.
private  java.util.Vector turnListeners
          Data structure containing registered TurnListeners.
private  int turnNumber
          Current turn number.
private  java.util.Vector turnSubmitted
          The
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
private GameEngine()
          Instantiate GameEngine with default state.
 
Method Summary
 void addTurnProcessedListener(TurnProcessedListener tpl)
          Register a listener to receive notification when turns have been processed.
private  boolean allTurnsSubmitted()
          Returns true if all players have submitted their turn.
(package private)  void AutoProcessing()
           
static void ExitGame()
          Flag the game to be exited at the end of the current turn.
(package private)  void ExternalCommunication()
           
static boolean gameOptionsProcessed()
          Find out whether the game options have been processed.
static GameOptions getGameOptions()
          Provides access to the game options currently in effect.
static int getTurnNumber()
          Returns the current turn number.
static GameEngine Initialize()
          Initialise the game engine, creating the singleton instance of GameEngine.
static GameEngine Instance()
          Return the singleton instance of the GameEngine.
(package private)  void processGameOptions()
           
(package private)  void processTurn()
          The main turn processing mechanism.
(package private) static void readObject(java.io.ObjectInputStream in)
           
static boolean ReadyToExit()
          Returns true if the game has been flagged to exit.
 void registerGameOptions(GameOptions in_GO)
           
 void removeTurnProcessedListener(TurnProcessedListener tpl)
          Unregister a listener to receive notification when turns have been processed.
 void run()
          Main game loop.
 void submitGameOptions(GameOptions in_GO)
           
(package private)  boolean submittedTurn(PlayerID pid)
          Discover whether a specified civ has submitted their turn in the current game turn.
(package private) static void SubmitTurn(TurnBase turn)
          Interface for allowing players to submit turns.
(package private) static void writeObject(java.io.ObjectOutputStream out)
           
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

single

private static GameEngine single
Instance of GameEngine used in implementing the Singleton design pattern.


options

private GameOptions options
The game options


turnNumber

private int turnNumber
Current turn number.


running

private static boolean running
Flag to indicate whether the game is currently running.


gameOptionsSubmitted

private boolean gameOptionsSubmitted
Flag to indicate whether the game options have been submitted.


gameOptionsProcessed

private boolean gameOptionsProcessed
Flag to indicate whether the game options have been processed.


randomGen

public static java.util.Random randomGen

turnSubmitted

private java.util.Vector turnSubmitted
The
turnSubmitted
field contains a list of instances of
ProcessedTurnStruct
objects, each of which acts as a pigeonhole for a civ to submit a turn into. The presence of a value in the turnSubmitted data structure does not guarantee that this is a current turn ready to be processed: instead the
ProcessedTurnStruct
instance should be consulted to check the
submitted
value.


turnListeners

private java.util.Vector turnListeners
Data structure containing registered TurnListeners.

Constructor Detail

GameEngine

private GameEngine()
Instantiate GameEngine with default state.

Method Detail

Initialize

public static GameEngine Initialize()
Initialise the game engine, creating the singleton instance of GameEngine.


run

public void run()
Main game loop. Once the game options have been processed and initialisation has been carried out, keep processing turns until the game is terminated.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

Instance

public static GameEngine Instance()
Return the singleton instance of the GameEngine. Note that this will return null if the engine has not yet been initialised.


SubmitTurn

static void SubmitTurn(TurnBase turn)
Interface for allowing players to submit turns. The turn will not be processed until all players have submitted their turns. A NullPointerException will be generated if the game engine has not been initialised.


ExitGame

public static void ExitGame()
Flag the game to be exited at the end of the current turn.


ReadyToExit

public static boolean ReadyToExit()
Returns true if the game has been flagged to exit.


getTurnNumber

public static int getTurnNumber()
Returns the current turn number. If no game has been started, the turn value is 0.


registerGameOptions

public void registerGameOptions(GameOptions in_GO)

submitGameOptions

public void submitGameOptions(GameOptions in_GO)

gameOptionsProcessed

public static boolean gameOptionsProcessed()
Find out whether the game options have been processed.


processGameOptions

void processGameOptions()

submittedTurn

boolean submittedTurn(PlayerID pid)
Discover whether a specified civ has submitted their turn in the current game turn.


AutoProcessing

void AutoProcessing()

ExternalCommunication

void ExternalCommunication()

processTurn

void processTurn()
The main turn processing mechanism. Each turn the following stages will be carried out:

This method should be invoked once per turn.


allTurnsSubmitted

private boolean allTurnsSubmitted()
Returns true if all players have submitted their turn.


getGameOptions

public static GameOptions getGameOptions()
Provides access to the game options currently in effect.


addTurnProcessedListener

public void addTurnProcessedListener(TurnProcessedListener tpl)
Register a listener to receive notification when turns have been processed.


removeTurnProcessedListener

public void removeTurnProcessedListener(TurnProcessedListener tpl)
Unregister a listener to receive notification when turns have been processed.


writeObject

static void writeObject(java.io.ObjectOutputStream out)
                 throws java.io.IOException
java.io.IOException

readObject

static void readObject(java.io.ObjectInputStream in)
                throws java.io.IOException,
                       java.lang.ClassNotFoundException
java.io.IOException
java.lang.ClassNotFoundException


Copyright © 2001 Universe Dev Team All Rights Reserved.