nankin.zheng.gatem.model
Class GameScheduler

java.lang.Object
  |
  +--nankin.zheng.gatem.model.GameScheduler
All Implemented Interfaces:
java.lang.Runnable

public abstract class GameScheduler
extends java.lang.Object
implements java.lang.Runnable

A game scheduler is a container holding several game containers. It contains methods to create thread for the game, update each game container during the game loop, control the game status and pass game events among different game containers.

Version:
1.0, Date 2003-04-14
Author:
ZHENG Zhong

Field Summary
static int CONTAINER_ACTIVE
           
static int CONTAINER_NOT_ACTIVE
           
protected  java.util.Vector containers
           
protected  CacheContainer displayer
           
protected  Env env
           
static int GAME_EXIT
           
static int GAME_FAIL
           
static int GAME_OVER
           
static int GAME_PASS
           
static int GAME_PAUSE
           
static int GAME_PREFACE
           
static int GAME_RUNNING
           
static int GAME_STAGE_INTRO
           
protected  int gameStatus
           
 
Constructor Summary
GameScheduler(Env environ, CacheContainer disp)
          Constructor.
 
Method Summary
 void addGameContainer(GameContainer gcont)
          Add a game container.
 void broadcastGameEvent(GameEvent gevt)
          Broadcast game event to all the active game containers.
protected  void gameActivity(int sts)
          executed in a loop while game status is unrecognizable.
protected  void gameFail()
          executed in a loop during GAME_FAIL.
protected  void gameOver()
          executed in a loop during GAME_OVER.
protected  void gamePass()
          executed in a loop during GAME_PASS.
protected  void gamePause()
          executed in a loop during GAME_PAUSE.
protected  void gamePreface()
          executed in a loop during GAME_PREFACE While GAME_PREFACE, a preface of the game will be displayed.
protected  void gameRunning()
          executed in a loop during GAME_RUNNING.
protected  void gameStageIntro()
          executed in a loop during GAME_STAGE_INTRO While GAME_STAGE_INTRO, a brief introduction of this stage will be displayed.
 int getGameStatus()
          Get game status.
protected  boolean hasNextStage()
          Whether has next stage.
protected  void loadNextStage()
          Load next stage into all its containers.
 void readStageScript(java.lang.String fname)
          Read stage script.
protected abstract  void receiveGameEvent(GameEvent gevt)
          Receive game event itself.
protected  void reloadStage()
          Reload the current stage into all its containers.
 void run()
          Implements Runnable
 void startGame()
          Start game.
 void testInitialization()
          Whether this game scheduler is initialized properly.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

env

protected Env env

displayer

protected CacheContainer displayer

containers

protected java.util.Vector containers

gameStatus

protected int gameStatus

CONTAINER_ACTIVE

public static final int CONTAINER_ACTIVE
See Also:
Constant Field Values

CONTAINER_NOT_ACTIVE

public static final int CONTAINER_NOT_ACTIVE
See Also:
Constant Field Values

GAME_EXIT

public static final int GAME_EXIT
See Also:
Constant Field Values

GAME_OVER

public static final int GAME_OVER
See Also:
Constant Field Values

GAME_PREFACE

public static final int GAME_PREFACE
See Also:
Constant Field Values

GAME_STAGE_INTRO

public static final int GAME_STAGE_INTRO
See Also:
Constant Field Values

GAME_RUNNING

public static final int GAME_RUNNING
See Also:
Constant Field Values

GAME_PAUSE

public static final int GAME_PAUSE
See Also:
Constant Field Values

GAME_PASS

public static final int GAME_PASS
See Also:
Constant Field Values

GAME_FAIL

public static final int GAME_FAIL
See Also:
Constant Field Values
Constructor Detail

GameScheduler

public GameScheduler(Env environ,
                     CacheContainer disp)
              throws GameException
Constructor.

Parameters:
environ - game environment
disp - displayer
Throws:
java.lang.NullPointerException - if environ or disp is null.
GameException - may be thrown out by its subclasses.
Method Detail

getGameStatus

public int getGameStatus()
Get game status.

Returns:
game status.

addGameContainer

public void addGameContainer(GameContainer gcont)
Add a game container.

Parameters:
gcont - GameContainer to be added.
Throws:
java.lang.NullPointerException - if gcont is null.

testInitialization

public void testInitialization()
                        throws GameException
Whether this game scheduler is initialized properly.

Throws:
GameException - if is not initialized properly.

broadcastGameEvent

public void broadcastGameEvent(GameEvent gevt)
                        throws GameException
Broadcast game event to all the active game containers. This method is in charge of the communication among game containers.

Parameters:
gevt - GameEvent to be broadcasted.
Throws:
java.lang.NullPointerException - if gevt is null
GameException - may be thrown out by GameContainer.broadcaseGameEvent().

receiveGameEvent

protected abstract void receiveGameEvent(GameEvent gevt)
                                  throws GameException
Receive game event itself. Some game event may have effect on the game status. This method should be overwritten by its subclasses.

Parameters:
gevt - GameEvent received
Throws:
GameException - may be thrown out by its subclasses.

gamePreface

protected void gamePreface()
                    throws GameException
executed in a loop during GAME_PREFACE While GAME_PREFACE, a preface of the game will be displayed. This method may be overwritten by its subclasses.

GameException

gameStageIntro

protected void gameStageIntro()
                       throws GameException
executed in a loop during GAME_STAGE_INTRO While GAME_STAGE_INTRO, a brief introduction of this stage will be displayed. This method may be overwritten by its subclasses.

GameException

gameRunning

protected void gameRunning()
                    throws GameException
executed in a loop during GAME_RUNNING. While game is running, all game containers' methods GameContainer.updateGameFrame() and GameContainer.drawGameFrame() are called in a loop.

GameException

gamePause

protected void gamePause()
                  throws GameException
executed in a loop during GAME_PAUSE. While game is pausing, only GameContainer.drawGameFrame() is called, and the logical attributes of the game will not change.

GameException

gamePass

protected void gamePass()
                 throws GameException
executed in a loop during GAME_PASS. While GAME_PASS, the player has achieved the goal of the current stage, and the next stage will be loaded (if any), or game will be finished.

GameException

gameFail

protected void gameFail()
                 throws GameException
executed in a loop during GAME_FAIL. While GAME_FAIL, the player has losen one life, but it has more lives to go on playing. The current stage will be (reloaded and) continued.

GameException

gameOver

protected void gameOver()
                 throws GameException
executed in a loop during GAME_OVER. While GAME_OVER, the player has losen all its lives, and game will be finished.

GameException

gameActivity

protected void gameActivity(int sts)
                     throws GameException
executed in a loop while game status is unrecognizable. This method support user-defined game status. It should be overwritten by its subclasses if necessary.

GameException

run

public void run()
Implements Runnable

Specified by:
run in interface java.lang.Runnable

startGame

public void startGame()
Start game.

This method creates a thread and start the game.


loadNextStage

protected void loadNextStage()
                      throws GameException
Load next stage into all its containers.

GameException

reloadStage

protected void reloadStage()
                    throws GameException
Reload the current stage into all its containers.

GameException

hasNextStage

protected boolean hasNextStage()
                        throws GameException
Whether has next stage.

GameException

readStageScript

public void readStageScript(java.lang.String fname)
                     throws GameException
Read stage script.

GameException