uk.ac.ic.doc.game
Class Game

java.lang.Object
  extended by uk.ac.ic.doc.game.Game
All Implemented Interfaces:
IGame

public abstract class Game
extends java.lang.Object
implements IGame

This class handles the creation of a game window, drawing of objects, running of the main game loop and reading key presses. Subclasses should implement the void onGameStart() method and use this to create and add initial game objects. Objects can register listeners for events such as key presses, timer ticks, collisions and screen exit using the methods of this class.


Constructor Summary
Game()
           
 
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 whenever 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.
abstract  void onGameStart()
          Called just before the main game loop is started.
 void remove(IGameObject object)
          Removes object from the game.
 void start()
          Creates and displays the game window, invokes the onGameStart() method in which the initial game objects should be created, then starts the main game loop.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Game

public Game()
Method Detail

start

public void start()
Creates and displays the game window, invokes the onGameStart() method in which the initial game objects should be created, then starts the main game loop.

Specified by:
start in interface IGame

add

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

Specified by:
add in interface IGame
Parameters:
object - The IGameObject to be added.

remove

public 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.

Specified by:
remove in interface IGame
Parameters:
object - The IGameObject to be removed.

addCollisionListener

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

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

addScreenExitListener

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

Specified by:
addScreenExitListener in interface IGame
Parameters:
object - The listener will be notified whenever this object leaves the screen.
listener - The listener to register.

addTimerListener

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

Specified by:
addTimerListener in interface IGame
Parameters:
object - The object registering this listener.
listener - The listener to register.

addKeyListener

public void addKeyListener(IGameObject object,
                           Key key,
                           IKeyListener listener)
Registers a key listener that will be notified whenever the given key is pressed.

Specified by:
addKeyListener in interface IGame
Parameters:
object - The object registering this listener.
key - The listener will be notified whenever this key is pressed.
listener - The listener to register.

onGameStart

public abstract 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.

Specified by:
onGameStart in interface IGame