|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectuk.ac.ic.doc.game.Game
public abstract class Game
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 |
---|
public Game()
Method Detail |
---|
public void start()
start
in interface IGame
public void add(IGameObject object)
add
in interface IGame
object
- The IGameObject to be added.public void remove(IGameObject object)
remove
in interface IGame
object
- The IGameObject to be removed.public void addCollisionListener(IGameObject object, ICollisionListener listener)
addCollisionListener
in interface IGame
object
- The listener will be notified whenever this object collides
with another object in the game.listener
- The listener to register.public void addScreenExitListener(IGameObject object, IScreenExitListener listener)
addScreenExitListener
in interface IGame
object
- The listener will be notified whenever this object leaves the
screen.listener
- The listener to register.public void addTimerListener(IGameObject object, ITimerListener listener)
addTimerListener
in interface IGame
object
- The object registering this listener.listener
- The listener to register.public void addKeyListener(IGameObject object, Key key, IKeyListener listener)
addKeyListener
in interface IGame
object
- The object registering this listener.key
- The listener will be notified whenever this key is pressed.listener
- The listener to register.public abstract void onGameStart()
onGameStart
in interface IGame
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |