vooga.gameEngine.core
Class GameEngine

java.lang.Object
  extended by vooga.gameEngine.core.GameEngine
All Implemented Interfaces:
java.lang.Runnable

public class GameEngine
extends java.lang.Object
implements java.lang.Runnable

Main class for the VOOGA Game Engine. The GameEngine contains the game loop, which at a simple level, consists of updating and then displaying the game.

Author:
Scott Brothers, Geoffrey Lawler, Jeremy Walch

Constructor Summary
GameEngine(java.lang.Class<? extends AbstractGame> gameClass)
          Creates a GameEngine object provided Class of the AbstractGame to be played.
GameEngine(java.lang.Class<? extends AbstractGame> gameClass, boolean isReplayMode)
          NOTE: This constructor should be used by the replay module when hoping to replay a game.
GameEngine(java.lang.Class<? extends AbstractGame> gameClass, int playerNo, int totalPlayers, VoogaGameClient networkClient)
          Constructor for a networked instance of a game and game engine.
GameEngine(java.lang.Class<? extends AbstractGame> gameClass, int playerNo, int totalPlayers, VoogaGameClient networkClient, VoogaSave replay, java.util.Collection<? extends java.util.EventListener> gameStatusListeners)
          Constructor for a networked instance of a game and game engine that can be replayed.
GameEngine(java.lang.Class<? extends AbstractGame> gameClass, VoogaSave replay, java.util.Collection<? extends java.util.EventListener> gameStatusListeners)
          Creates a GameEngine object provided Class of the AbstractGame to be played and the VoogaSave object, which stores game time as well as any events fired due to user/network input.
 
Method Summary
 AbstractGame getGame()
          Simple getter for the AbstractGame.
 javax.swing.JComponent getGamePanel()
          Simple getter method for the panel in which the game is displayed.
 HumanController getHumanController()
          Simple getter for the HumanController for the game.
 NetworkController getNetworkController()
          Simple getter for the NetworkController for the game.
 TimingController getTimingController()
          Simple getter for the TimingController for the game.
 boolean isGameLoopRunning()
          Returns whether or not the game loop is currently running.
 boolean pauseGameLoop()
          Attempts to pause the game loop.
 void resumeGameLoop()
          Attempts to resume the game loop (if the game loop were paused).
 void run()
          Simulates the execution of a game.
 void shutDown()
          Stops the game loop and all components associated with the game which is currently running.
 void startGameLoop()
          Starts the game loop
 void stepThroughGameLoop(int numSteps)
          Runs the specified number of iterations through the game loop (in terms of number of times game state is update, not frames) before repainting the canvas.
 void stopGameLoop()
          Stops the Game Loop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GameEngine

public GameEngine(java.lang.Class<? extends AbstractGame> gameClass)
Creates a GameEngine object provided Class of the AbstractGame to be played. Instantiates the various components needed to execute the game.

Parameters:
gameClass - the Class of the game to be run using this engine.

GameEngine

public GameEngine(java.lang.Class<? extends AbstractGame> gameClass,
                  VoogaSave replay,
                  java.util.Collection<? extends java.util.EventListener> gameStatusListeners)
Creates a GameEngine object provided Class of the AbstractGame to be played and the VoogaSave object, which stores game time as well as any events fired due to user/network input. Instantiates the various components needed to execute the game.

Parameters:
gameClass - the Class of the game to be run using this engine.
replay - the VoogaSave object to which time and input/network-caused events will be sent
gameStatusListeners - the Collection of EventListeners to be notified of important information regarding the game status, such as the score or any achievements made

GameEngine

public GameEngine(java.lang.Class<? extends AbstractGame> gameClass,
                  int playerNo,
                  int totalPlayers,
                  VoogaGameClient networkClient)
Constructor for a networked instance of a game and game engine.

Parameters:
gameClass -
playerNo -
totalPlayers -
networkClient -

GameEngine

public GameEngine(java.lang.Class<? extends AbstractGame> gameClass,
                  int playerNo,
                  int totalPlayers,
                  VoogaGameClient networkClient,
                  VoogaSave replay,
                  java.util.Collection<? extends java.util.EventListener> gameStatusListeners)
Constructor for a networked instance of a game and game engine that can be replayed.

Parameters:
gameClass -
playerNo -
totalPlayers -
networkClient -
replay -
gameStatusListeners - the Collection of EventListeners to be notified of important information regarding the game status, such as the score or any achievements made

GameEngine

public GameEngine(java.lang.Class<? extends AbstractGame> gameClass,
                  boolean isReplayMode)
NOTE: This constructor should be used by the replay module when hoping to replay a game. Creates a GameEngine object provided Class of the AbstractGame to be played and whether or not the GameEngine should enter into replay mode. If isReplayMode is set to false, this is equivalent to using the GameEngine(Class) constructor.

Parameters:
gameClass - the Class of the game to be run using this engine.
isReplayMode - true if the game should enter replay mode; false otherwise
Method Detail

run

public void run()
Simulates the execution of a game. First attempts to start the game, and if successful, enters the game loop. Based on deWiTTERS Game Loop, by Koen Witters

Specified by:
run in interface java.lang.Runnable
See Also:
Runnable.run()

startGameLoop

public void startGameLoop()
Starts the game loop


stopGameLoop

public void stopGameLoop()
Stops the Game Loop


pauseGameLoop

public boolean pauseGameLoop()
Attempts to pause the game loop. If the game being played is a network game, a pause is not allowed.

Returns:
true if the game loop was successfully paused; false otherwise

resumeGameLoop

public void resumeGameLoop()
Attempts to resume the game loop (if the game loop were paused).


stepThroughGameLoop

public void stepThroughGameLoop(int numSteps)
Runs the specified number of iterations through the game loop (in terms of number of times game state is update, not frames) before repainting the canvas. If the game loop is currently running this method will stop the game loop before stepping. For use by the mod/dev environment.


shutDown

public void shutDown()
Stops the game loop and all components associated with the game which is currently running. This method is the equivalent of quitting the game and should be called when such behavior is desired.


getGamePanel

public javax.swing.JComponent getGamePanel()
Simple getter method for the panel in which the game is displayed.

Returns:
the game's panel

isGameLoopRunning

public boolean isGameLoopRunning()
Returns whether or not the game loop is currently running.

Returns:
true if the game loop is running; false otherwise

getHumanController

public HumanController getHumanController()
Simple getter for the HumanController for the game. Intended to be called only for the purposes of replaying a game.

Returns:
a HumanController

getNetworkController

public NetworkController getNetworkController()
Simple getter for the NetworkController for the game. Intended to be called only for the purposes of replaying a game.

Returns:
a NetworkController

getTimingController

public TimingController getTimingController()
Simple getter for the TimingController for the game. Intended to be called only for the purposes of replaying a game.

Returns:
a TimingController

getGame

public AbstractGame getGame()
Simple getter for the AbstractGame. Implemented for the development team.

Returns:
an AbstractGame.