VASSAL.build.module
Class GameState

java.lang.Object
  |
  +--VASSAL.build.module.GameState

public abstract class GameState
extends java.lang.Object

The GameState represents the state of the game currently being played. Only one game can be open at once.

See Also:
GameModule.getGameState()

Nested Class Summary
static class GameState.SetupCommand
           
 
Field Summary
protected  javax.swing.JMenuItem closeGame
           
protected  java.util.Vector gameComponents
           
protected  java.lang.String lastSave
           
protected  javax.swing.JMenuItem loadGame
           
protected  javax.swing.JMenuItem newGame
           
protected  java.util.Hashtable pieces
           
protected  javax.swing.JMenuItem saveGame
           
 
Constructor Summary
GameState()
           
 
Method Summary
 void addGameComponent(GameComponent theComponent)
          Add a GameComponent to the list of objects that will be notified when a game is started/ended
 void addPiece(GamePiece p)
          Add a GamePiece to the current game.
 void addTo(GameModule mod)
          Expects to be added to a GameModule.
 java.util.Enumeration getGameComponentsEnum()
           
 java.lang.String getNewPieceId()
           
 GamePiece getPieceForId(java.lang.String id)
           
 java.util.Enumeration getPieces()
           
abstract  Command getRestoreCommand()
          Return a GameState.SetupCommand that, when executed, will restore the game to its current state.
 boolean isGameStarted()
           
 boolean isModified()
           
abstract  void loadContinuation(java.io.File f)
           
 void loadGame()
          Read the game from a savefile.
abstract  void loadGame(java.io.File f)
           
 void removeGameComponent(GameComponent theComponent)
          Remove a GameComponent from the list of objects that will be notified when a game is started/ended
 void removePiece(java.lang.String id)
          Remove a GamePiece from the current game
 void saveGame()
          Prompts the user for a file into which to save the game
abstract  void saveGame(java.io.File f)
           
protected  java.lang.String saveString()
           
 void setModified(boolean modified)
           
 void setup(boolean gameStarting)
          Start/end a game.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

pieces

protected java.util.Hashtable pieces

gameComponents

protected java.util.Vector gameComponents

loadGame

protected javax.swing.JMenuItem loadGame

saveGame

protected javax.swing.JMenuItem saveGame

newGame

protected javax.swing.JMenuItem newGame

closeGame

protected javax.swing.JMenuItem closeGame

lastSave

protected java.lang.String lastSave
Constructor Detail

GameState

public GameState()
Method Detail

addTo

public void addTo(GameModule mod)
Expects to be added to a GameModule. Adds New, Load, Close, and Save entries to the File menu of the controls window


isModified

public boolean isModified()
Returns:
true if the game state is different from when it was last saved

addGameComponent

public void addGameComponent(GameComponent theComponent)
Add a GameComponent to the list of objects that will be notified when a game is started/ended


removeGameComponent

public void removeGameComponent(GameComponent theComponent)
Remove a GameComponent from the list of objects that will be notified when a game is started/ended


getGameComponentsEnum

public java.util.Enumeration getGameComponentsEnum()
Returns:
an enumeration of all GameComponent objects that have been added to this GameState

setup

public void setup(boolean gameStarting)
Start/end a game. Prompt to save if the game state has been modified since last save. Invoke GameComponent.setup(boolean) on all registered GameComponent objects


isGameStarted

public boolean isGameStarted()

loadGame

public void loadGame()
Read the game from a savefile. The contents of the file is sent to GameModule.decode(java.lang.String) and translated into a GameState.SetupCommand, which is then executed. The command read from the file should be that returned by getRestoreCommand()


saveString

protected java.lang.String saveString()

getRestoreCommand

public abstract Command getRestoreCommand()
Return a GameState.SetupCommand that, when executed, will restore the game to its current state. Invokes GameComponent.getRestoreCommand() on each registered GameComponent


saveGame

public void saveGame()
Prompts the user for a file into which to save the game


setModified

public void setModified(boolean modified)

addPiece

public void addPiece(GamePiece p)
Add a GamePiece to the current game. The GameState keeps track of all GamePieces in the system, regardless of which Map they belong to (if any)


getPieceForId

public GamePiece getPieceForId(java.lang.String id)
Returns:
the GamePiece in the current game with the given id

removePiece

public void removePiece(java.lang.String id)
Remove a GamePiece from the current game


getNewPieceId

public java.lang.String getNewPieceId()
Returns:
a String identifier guaranteed to be different from the id of all GamePieces in the game
See Also:
GamePiece.getId()

loadGame

public abstract void loadGame(java.io.File f)
                       throws java.io.IOException
java.io.IOException

saveGame

public abstract void saveGame(java.io.File f)
                       throws java.io.IOException
java.io.IOException

loadContinuation

public abstract void loadContinuation(java.io.File f)
                               throws java.io.IOException
java.io.IOException

getPieces

public java.util.Enumeration getPieces()
Returns:
an Enumeration of all GamePieces in the game.