unc.cdva.gameengine
Class GameEngine

java.lang.Object
  extended by unc.cdva.gameengine.GameEngine
All Implemented Interfaces:
java.util.EventListener, GameEventListener

public class GameEngine
extends java.lang.Object
implements GameEventListener

Raw source events are passed to the game engine, which then in turn notifies listeners. The game engine will also as appropriate call the object managers to change the state of the model as needed by the specific event. The game engine is essentially the brain of the software, viewed in another way it is the controller of the mvc architecture implemented.

Author:
Dan Van Atta, Garrett Davis, Guillaume Conte

Field Summary
protected  java.util.Vector<GraphicsEventListener> graphicsEventlisteners
           
protected  java.util.Vector<UIEventListener> uiEventlisteners
           
 
Constructor Summary
GameEngine(javax.media.opengl.GLCanvas glCanvas)
          Constructor - initializes the game engine.
 
Method Summary
 void addGraphicsEventListener(GraphicsEventListener listener)
          Registers a graphics event listener.
 void addProblem(GameEvent e, Id problemId)
          Invoked when a problem is added to the screen
 void addUIEventListener(UIEventListener listener)
          Registers a ui event listener object.
 void cancelProblem(GameEvent e, Id problemId)
          Invoked when a problem is removed from the screen
 void fire(GameEvent e, Id problemId)
          Invoked when the gun fires!
 void freezeGame(GameEvent e)
          Invoked when you stop the game
protected  ItemManager getItemsManager()
           
protected  ProblemManager getProblemManager()
           
 void loadLevel(int level)
          Inits the game to a certain level.
 void loadMainMenu(GameEvent e)
          Invoked when you load the main menu
 void loadNextLevel(GameEvent e)
          Invoked when you load the next level after winning a level
 void loadOptionMenu(GameEvent e)
          Invoked when you load the option menu
 void loadSinglePlayer(GameEvent e)
          Invoked when you load a single player game
 void notifyAddGun(Id id)
          Notifies the graphic listeners that a gun object has been added.
 void notifyAddProblem(Id problemId, Object3D object)
          Notifies the graphic listeners that a new problem object has been created.
 void notifyAddProjectile(Id id)
          Notifes the graphic listeners that a projectile has been added.
 void notifyAddReticle(Id id)
          Notifes the graphic listeners that a reticle has been added.
 void notifyAddTarget(Id id)
          Notifes the graphic listeners that a target has been added.
 void notifyEndGame()
          Notifes UI event listeners that the player has lost.
 void notifyEndLevel()
          Notifies UI event listeners that the level is over, (the player has finished it).
 void notifyFreezeFireWindows()
          Notifies UI event listeners that the fire windows have to been frozen
 void notifyInitLevel()
          Notifes the graphic listeners that a new game level has been started.
 void notifyLoadBackground(java.lang.String background)
          Notifies the ui listeners to load a new background.
 void notifyRemoveGun(Id id)
          Notifies the graphic listeners that a gun has been removed.
 void notifyRemoveProblem(Id problemId)
          Notifies graphic listeners that a problem has been removed.
 void notifyRemoveProjectile(Id id)
          Notifes the graphic listeners that a projectile has been removed.
 void notifyRemoveReticle(Id id)
          Notifes the graphic listeners that a reticle has been removed.
 void notifyRemoveTarget(Id id)
          Notifes the graphic listeners that a target has been removed.
 void notifySetHighScoreLabel(long score)
          Notifes the graphic listeners that the player's high score needs to be set.
 void notifySetLevelLabel(long level)
          Notifes the graphic listeners that the level label needs to be updated.
 void notifySetScoreLabel(long score)
          Notifes the graphic listeners that the player's score needs to be set.
 void notifyUnfreezeFireWindows()
          Notifies UI event listeners that the fire windows no longer have to be frozen
 void notifyUpdateDisplayList()
          Notifies the graphic event listeners that the display list has changed,and that there a new/updated things to draw.
 void notifyUpdateItemsBean(ItemsBean itemsBean)
          Alerts the graphic event listeners that the items bean has changed.
 void quit(GameEvent e)
          Invoked when the game quits
 void removeGraphicsEventListener(GraphicsEventListener listener)
          Removes a graphics event listener.
 void removeUIEventListener(UIEventListener listener)
          Removes a ui event listener.
 void setMasterVolume(GameEvent e, float masterVolume)
          Invoked when you set the master volume
 void setMusicFolder(GameEvent e, java.lang.String musicFolder)
          Invoked when you change the music folder
 void setProblemValue(GameEvent e, Id problemId, long value)
          Invoked when the user set the value of a problem
 void setVideoResolution(GameEvent e, java.awt.Dimension dimension)
          Invoked when you change the screen resolution
 void unfreezeGame(GameEvent e)
          Invoked when you resume the game
 void update(GameEvent e)
          Invoked when the game engine is updated and the screen re-drawn
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

uiEventlisteners

protected java.util.Vector<UIEventListener> uiEventlisteners

graphicsEventlisteners

protected java.util.Vector<GraphicsEventListener> graphicsEventlisteners
Constructor Detail

GameEngine

public GameEngine(javax.media.opengl.GLCanvas glCanvas)
Constructor - initializes the game engine.

Method Detail

addProblem

public void addProblem(GameEvent e,
                       Id problemId)
Description copied from interface: GameEventListener
Invoked when a problem is added to the screen

Specified by:
addProblem in interface GameEventListener
problemId - id of the new problem
See Also:
GameEventListener.addProblem(unc.cdva.events.gameevents.GameEvent, Id)

cancelProblem

public void cancelProblem(GameEvent e,
                          Id problemId)
Description copied from interface: GameEventListener
Invoked when a problem is removed from the screen

Specified by:
cancelProblem in interface GameEventListener
problemId - is of the problem that has to be removed
See Also:
GameEventListener.cancelProblem(unc.cdva.events.gameevents.GameEvent, Id)

fire

public void fire(GameEvent e,
                 Id problemId)
Description copied from interface: GameEventListener
Invoked when the gun fires!

Specified by:
fire in interface GameEventListener
See Also:
GameEventListener.fire(unc.cdva.events.gameevents.GameEvent, Id)

freezeGame

public void freezeGame(GameEvent e)
Description copied from interface: GameEventListener
Invoked when you stop the game

Specified by:
freezeGame in interface GameEventListener
See Also:
GameEventListener.freezeGame(unc.cdva.events.gameevents.GameEvent)

loadMainMenu

public void loadMainMenu(GameEvent e)
Description copied from interface: GameEventListener
Invoked when you load the main menu

Specified by:
loadMainMenu in interface GameEventListener
See Also:
GameEventListener.loadMainMenu(unc.cdva.events.gameevents.GameEvent)

loadNextLevel

public void loadNextLevel(GameEvent e)
Description copied from interface: GameEventListener
Invoked when you load the next level after winning a level

Specified by:
loadNextLevel in interface GameEventListener
See Also:
GameEventListener.loadNextLevel(unc.cdva.events.gameevents.GameEvent)

loadLevel

public void loadLevel(int level)
Inits the game to a certain level.

Parameters:
level - The level to initialize the game to.

loadOptionMenu

public void loadOptionMenu(GameEvent e)
Description copied from interface: GameEventListener
Invoked when you load the option menu

Specified by:
loadOptionMenu in interface GameEventListener
See Also:
GameEventListener.loadOptionMenu(unc.cdva.events.gameevents.GameEvent)

loadSinglePlayer

public void loadSinglePlayer(GameEvent e)
Description copied from interface: GameEventListener
Invoked when you load a single player game

Specified by:
loadSinglePlayer in interface GameEventListener
See Also:
GameEventListener.loadSinglePlayer(unc.cdva.events.gameevents.GameEvent)

quit

public void quit(GameEvent e)
Description copied from interface: GameEventListener
Invoked when the game quits

Specified by:
quit in interface GameEventListener
See Also:
GameEventListener.quit(unc.cdva.events.gameevents.GameEvent)

setMasterVolume

public void setMasterVolume(GameEvent e,
                            float masterVolume)
Description copied from interface: GameEventListener
Invoked when you set the master volume

Specified by:
setMasterVolume in interface GameEventListener
masterVolume - new value of the volume (0. to 1.)
See Also:
GameEventListener.setMasterVolume(unc.cdva.events.gameevents.GameEvent, float)

setMusicFolder

public void setMusicFolder(GameEvent e,
                           java.lang.String musicFolder)
Description copied from interface: GameEventListener
Invoked when you change the music folder

Specified by:
setMusicFolder in interface GameEventListener
musicFolder - path of the new music folder
See Also:
GameEventListener.setMusicFolder(unc.cdva.events.gameevents.GameEvent, java.lang.String)

setProblemValue

public void setProblemValue(GameEvent e,
                            Id problemId,
                            long value)
Description copied from interface: GameEventListener
Invoked when the user set the value of a problem

Specified by:
setProblemValue in interface GameEventListener
problemId - id of the problem
value - value entered by the user
See Also:
GameEventListener.setProblemValue(unc.cdva.events.gameevents.GameEvent, Id, long)

setVideoResolution

public void setVideoResolution(GameEvent e,
                               java.awt.Dimension dimension)
Description copied from interface: GameEventListener
Invoked when you change the screen resolution

Specified by:
setVideoResolution in interface GameEventListener
dimension - new size of the screen
See Also:
GameEventListener.setVideoResolution(unc.cdva.events.gameevents.GameEvent, java.awt.Dimension)

unfreezeGame

public void unfreezeGame(GameEvent e)
Description copied from interface: GameEventListener
Invoked when you resume the game

Specified by:
unfreezeGame in interface GameEventListener
See Also:
GameEventListener.unfreezeGame(unc.cdva.events.gameevents.GameEvent)

update

public void update(GameEvent e)
Description copied from interface: GameEventListener
Invoked when the game engine is updated and the screen re-drawn

Specified by:
update in interface GameEventListener
See Also:
GameEventListener.update(unc.cdva.events.gameevents.GameEvent)

addUIEventListener

public void addUIEventListener(UIEventListener listener)
Registers a ui event listener object.

Parameters:
listener - The UIEventListener to notify.

removeUIEventListener

public void removeUIEventListener(UIEventListener listener)
Removes a ui event listener. It will no longer be notified.

Parameters:
listener - The listener to remove.

addGraphicsEventListener

public void addGraphicsEventListener(GraphicsEventListener listener)
Registers a graphics event listener. It will be notified on (certain) events.

Parameters:
listener - The listener to add.

removeGraphicsEventListener

public void removeGraphicsEventListener(GraphicsEventListener listener)
Removes a graphics event listener. It will no longer be notified on events.

Parameters:
listener - The listener to remove.

notifyUpdateDisplayList

public void notifyUpdateDisplayList()
Notifies the graphic event listeners that the display list has changed,and that there a new/updated things to draw.


notifyUpdateItemsBean

public void notifyUpdateItemsBean(ItemsBean itemsBean)
Alerts the graphic event listeners that the items bean has changed.

Parameters:
itemsBean - The new item bean to notify the graphic event listeners of.

notifyLoadBackground

public void notifyLoadBackground(java.lang.String background)
Notifies the ui listeners to load a new background.

Parameters:
background - "main" to load the main menu background "option" to load the option menu background

notifyAddProblem

public void notifyAddProblem(Id problemId,
                             Object3D object)
Notifies the graphic listeners that a new problem object has been created.

Parameters:
problemId - The id of the problem that has been created.
object - The problem's object3d drawable object.

notifyRemoveProblem

public void notifyRemoveProblem(Id problemId)
Notifies graphic listeners that a problem has been removed.

Parameters:
problemId - The id of the problem that has been removed.

notifyAddGun

public void notifyAddGun(Id id)
Notifies the graphic listeners that a gun object has been added.

Parameters:
id - the id of the added gun.

notifyRemoveGun

public void notifyRemoveGun(Id id)
Notifies the graphic listeners that a gun has been removed.

Parameters:
id - The id of the removed gun.

notifyAddTarget

public void notifyAddTarget(Id id)
Notifes the graphic listeners that a target has been added.

Parameters:
id - The id of the added target.

notifyRemoveTarget

public void notifyRemoveTarget(Id id)
Notifes the graphic listeners that a target has been removed.

Parameters:
id - The id of the removed target.

notifyAddProjectile

public void notifyAddProjectile(Id id)
Notifes the graphic listeners that a projectile has been added.

Parameters:
id - The id of the added projectile.

notifyRemoveProjectile

public void notifyRemoveProjectile(Id id)
Notifes the graphic listeners that a projectile has been removed.

Parameters:
id - The id of the removed projectile.

notifyAddReticle

public void notifyAddReticle(Id id)
Notifes the graphic listeners that a reticle has been added.

Parameters:
id - The id of the added reticle.

notifyRemoveReticle

public void notifyRemoveReticle(Id id)
Notifes the graphic listeners that a reticle has been removed.

Parameters:
id - The id of the removed reticle.

notifyInitLevel

public void notifyInitLevel()
Notifes the graphic listeners that a new game level has been started.


notifySetScoreLabel

public void notifySetScoreLabel(long score)
Notifes the graphic listeners that the player's score needs to be set.

Parameters:
score - The player's total score.

notifySetHighScoreLabel

public void notifySetHighScoreLabel(long score)
Notifes the graphic listeners that the player's high score needs to be set.

Parameters:
score - The player's total high score.

notifySetLevelLabel

public void notifySetLevelLabel(long level)
Notifes the graphic listeners that the level label needs to be updated.

Parameters:
level - The level number the player is on.

notifyEndGame

public void notifyEndGame()
Notifes UI event listeners that the player has lost.


notifyEndLevel

public void notifyEndLevel()
Notifies UI event listeners that the level is over, (the player has finished it).


notifyFreezeFireWindows

public void notifyFreezeFireWindows()
Notifies UI event listeners that the fire windows have to been frozen


notifyUnfreezeFireWindows

public void notifyUnfreezeFireWindows()
Notifies UI event listeners that the fire windows no longer have to be frozen


getProblemManager

protected ProblemManager getProblemManager()
Returns:
the problemManager

getItemsManager

protected ItemManager getItemsManager()
Returns:
the itemManager