vooga.engine.state
Class GameStateManager

java.lang.Object
  extended by vooga.engine.state.GameStateManager

public class GameStateManager
extends java.lang.Object

GameStateManager manages the behavior of GameState for overarching classes like Game. At its heart, GameStateManager is a collection of GameStates with a number of useful methods for toggling, activating, and deactivating specific states. Otherwise, its main purpose is to sort and iterate over GameStates, rendering and updating the active ones.


Constructor Summary
GameStateManager()
          Constructs a new empty GameStateManager.
 
Method Summary
 void activateAll()
          Activates all GameStates.
 void activateOnly(GameState gamestate)
          Activates the specified GameState and deactivates all others.
 void addGameState(GameState... states)
          Add game state(s) to the game state manager.
 void addGameState(GameState gamestate)
          Adds a GameState to the top layer of a GameStateManager's collection of GameStates.
 void addGameState(GameState gamestate, int index)
          Adds a GameState to the layer above the specified GameState
 void deactivateAll()
          Deactivates all GameStates in the GameStateManager.
 void deactivateOnly(GameState gamestate)
          Deactivates the specified GameState.
 GameState getGameState(int index)
          Retrieves the game state at the specified index
 void removeGameState(GameState gamestate)
          Removes a GameState from the GameStateManager's collection of GameStates.
 void render(java.awt.Graphics2D g)
          Iterates over the GameStates, in order of their layer values, and renders the active ones in order.
 void switchTo(GameState activatedGameState)
          Deactivates all GameStates except for the parameter GameState, which is activated.
 void toggle(GameState gamestate)
          If the specified GameState is in the GameStateManager, toggles it between active and inactive.
 void update(long t)
          Iterates over the GameStates, in order of their layer values, and updates the active ones in order.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GameStateManager

public GameStateManager()
Constructs a new empty GameStateManager.

Method Detail

addGameState

public void addGameState(GameState gamestate)
Adds a GameState to the top layer of a GameStateManager's collection of GameStates.

Parameters:
gamestate -

addGameState

public void addGameState(GameState gamestate,
                         int index)
Adds a GameState to the layer above the specified GameState

Parameters:
gamestate - represents the GameState to be added
nextStateDown - represents the GameState one layer below the new GameState

addGameState

public void addGameState(GameState... states)
Add game state(s) to the game state manager. Assumes the first game state in the list to be the default game state and activates it.

Parameters:
states - a list of game states

removeGameState

public void removeGameState(GameState gamestate)
Removes a GameState from the GameStateManager's collection of GameStates.

Parameters:
gamestate -

update

public void update(long t)
Iterates over the GameStates, in order of their layer values, and updates the active ones in order.

Parameters:
t -

render

public void render(java.awt.Graphics2D g)
Iterates over the GameStates, in order of their layer values, and renders the active ones in order.

Parameters:
g - represents the Graphics2D instance

activateOnly

public void activateOnly(GameState gamestate)
Activates the specified GameState and deactivates all others.

Parameters:
gamestate - represents the GameState to be activated; all others will be deactivated

deactivateOnly

public void deactivateOnly(GameState gamestate)
Deactivates the specified GameState.

Parameters:
gamestate -

activateAll

public void activateAll()
Activates all GameStates.


toggle

public void toggle(GameState gamestate)
If the specified GameState is in the GameStateManager, toggles it between active and inactive.

Parameters:
gamestate -

deactivateAll

public void deactivateAll()
Deactivates all GameStates in the GameStateManager.


switchTo

public void switchTo(GameState activatedGameState)
Deactivates all GameStates except for the parameter GameState, which is activated.

Parameters:
gamestate -

getGameState

public GameState getGameState(int index)
Retrieves the game state at the specified index

Parameters:
index - location of the game state in GameStateManager arraylist
Returns:
gamestate