uk.ac.ic.doc.game
Interface IGame

All Known Implementing Classes:
Game

public interface IGame

Interface for representing games. A game is responsible for creating the window in which all drawing takes place, accepting and drawing IGameObject instances and allowing IGameObject instances to register listeners for timer, keypress, collision and screen exit events. Instead of creating the initial game objects in the constructor, implementations of this interface should create these objects in the onGameStart() method. This will ensure that the game can be re-intialised without creating a new game instance.


Method Summary
 void add(IGameObject object)
          Adds object to the game.
 void addCollisionListener(IGameObject object, ICollisionListener listener)
          Registers a collision listener that will be notified whenever a collision occurs between object and any other IGameObject.
 void addKeyListener(IGameObject object, Key key, IKeyListener listener)
          Registers a key listener that will be notified of every timer tick that occurs while the given key is pressed.
 void addScreenExitListener(IGameObject object, IScreenExitListener listener)
          Registers a screen exit listener that will be notified whenever object leaves the screen.
 void addTimerListener(IGameObject object, ITimerListener listener)
          Registers a timer listener that will be called after every cycle of the main game loop.
 void onGameStart()
          Called just before the main game loop is started.
 void remove(IGameObject object)
          Removes object from the game.
 void start()
          Starts this game.
 

Method Detail

start

void start()
Starts this game. Implementations of this method should perform the following: Create and display the main window. Call the onGameStart() method in which the initial game objects should be created. Start the main game loop which processes game events and notifies the appropriate listeners.


add

void add(IGameObject object)
Adds object to the game. This object will then be redrawn when the game redraws itself.

Parameters:
object - The IGameObject to be added.

remove

void remove(IGameObject object)
Removes object from the game. This object will no longer be redrawn when the game redraws itself. Any listeners that this object has registered will also be removed.

Parameters:
object - The IGameObject to be removed.

addTimerListener

void addTimerListener(IGameObject object,
                      ITimerListener listener)
Registers a timer listener that will be called after every cycle of the main game loop.

Parameters:
object - The object registering this listener.
listener - The listener to register.

addCollisionListener

void addCollisionListener(IGameObject object,
                          ICollisionListener listener)
Registers a collision listener that will be notified whenever a collision occurs between object and any other IGameObject.

Parameters:
object - The listener will be notified whenever this object collides with another object in the game.
listener - The listener to register.

addScreenExitListener

void addScreenExitListener(IGameObject object,
                           IScreenExitListener listener)
Registers a screen exit listener that will be notified whenever object leaves the screen.

Parameters:
object - The listener will be notified whenever this object leaves the screen.
listener - The listener to register.

addKeyListener

void addKeyListener(IGameObject object,
                    Key key,
                    IKeyListener listener)
Registers a key listener that will be notified of every timer tick that occurs while the given key is pressed.

Parameters:
object - The object registering this listener.
key - The listener will be notified while this key is pressed.
listener - The listener to register.

onGameStart

void onGameStart()
Called just before the main game loop is started. Implementations of this method should construct the initial objects of the game and register any necessary listeners.