net.sourceforge.simplegamenet.specs.to
Class GameSettings

java.lang.Object
  extended bynet.sourceforge.simplegamenet.specs.to.GameSettings
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
MultiPlayerGameSettings, TwoPlayerGameSettings

public abstract class GameSettings
extends Object
implements Serializable

An abstract superclass which represents all game settings that determine how a game is played. There is one single GameSettings object during a server session and every connected client holds a copy. A server session spawns over several game sessions, which start and stop with game start and end events.

If these settings are updated the game server and every game player client receive a GameServer#gameSettingsUpdated(GameSettings, GameSettings) event.

These game settings should only be changed by the host (using the "Game Settings" tab and a GameSettingsPanel created with the createGameSettingsPanel() method) or by the game server (using custom methods). The host is not allowed to change these game settings if the game is playing. The game server can change these game settings at any time but should call net.sourceforge.simplegamenet.framework.model.ServerEngineImpl#refreshGameSettings() so all clients update their copy.

Version:
1.0, 2003-06-18
Author:
Geoffrey De Smet
See Also:
net.sourceforge.simplegamenet.framework.model.EngineImpl#getGameSettings(), GameSettingsPanel, Serialized Form

Field Summary
protected  Engine engine
          The EngineImpl of the current application.
 
Constructor Summary
protected GameSettings()
          Constructs new game settings.
 
Method Summary
abstract  GameSettings createChangedGameSettings(GameSettingsPanel gameSettingsPanel)
          Creates a new GameSettings based on the GameSettingsPanel.
 PlayerSettings createDefaultPlayerSettings(Integer playerID, int playerType, String nickname)
          Creates a new PlayerSettings based on the current game state.
abstract  GameSettingsPanel createGameSettingsPanel()
          Creates a new GameSettingsPanel based on these game settings.
 boolean isChangeGameSettingsAllowed(GameSettings changedGameSettings)
          Returns true if the current game state allows these game settings to be updated to the changed game settings.
 boolean isChangePlayerSettingsAllowed(PlayerSettings currentPlayerSettings, PlayerSettings changedPlayerSettings)
          Return true if the current game state and these game settings allow a player to change his player settings.
 boolean isCreateDefaultPlayerSettingsAllowed(int playerType)
          Returns true if the current game state and these game settings allow the new player to connect.
 boolean isStartGameAllowed()
          Returns true if the current game state allows a game to be started.
 void setEngine(Engine engine)
          Sets the Engine for these game settings.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

engine

protected transient Engine engine
The EngineImpl of the current application. This variable allows the methods of these game settings to know the player settings of each player, the game state, etc.

Initially this variable is null, but when an engine is created it is set by the SimpleGameNet framework. During construction this variable is null and during the methods createGameSettingsPanel() and createChangedGameSettings(net.sourceforge.simplegamenet.specs.gui.GameSettingsPanel) it can be null.

Constructor Detail

GameSettings

protected GameSettings()
Constructs new game settings. The SimpleGameNet framework asks the GameFactory to create game settings for him with GameFactory.createDefaultGameSettings().

This class GameSettings can be extended directly to use custom settings or one of the configurable game settings from the net.sourceforge.simplegamenet.specs.tools package can be used, such as MultiPlayerGameSettings or TwoPlayerGameSettings.

During the construction the engine variable is null.

Method Detail

createGameSettingsPanel

public abstract GameSettingsPanel createGameSettingsPanel()
Creates a new GameSettingsPanel based on these game settings. This new GameSettingsPanel is shown in the "Connection wizard" dialog or the "Game settings" tab. That panel is enabled with the host which allows him to change the game settings, but it is disabled with all other users, who can just see the game settings.

During this method the engine variable can be null.

Returns:
a new GameSettingsPanel

createChangedGameSettings

public abstract GameSettings createChangedGameSettings(GameSettingsPanel gameSettingsPanel)
Creates a new GameSettings based on the GameSettingsPanel. This method fetches all the data a host can edit with custom methods from the GameSettingsPanel and copies any non editable data from these game settings into the new GameSettings.

This method will never be called when the game is playing because the host is not allowed to change the game settings during the game.

During this method the engine variable can be null.

Parameters:
gameSettingsPanel - a GameSettingsPanel changed by the host
Returns:
a new GameSettings

isChangeGameSettingsAllowed

public boolean isChangeGameSettingsAllowed(GameSettings changedGameSettings)
Returns true if the current game state allows these game settings to be updated to the changed game settings. This method is called after createChangedGameSettings(GameSettingsPanel) has been called.

If a subclass does not overwrite this method it always returns true. A subclass should override this method if it wants to prevent the host to change the game settings to certain settings sometimes.

Parameters:
changedGameSettings - the changed game settings created by createChangedGameSettings(net.sourceforge.simplegamenet.specs.gui.GameSettingsPanel)
Returns:
true if the game settings are allowed to change

isCreateDefaultPlayerSettingsAllowed

public boolean isCreateDefaultPlayerSettingsAllowed(int playerType)
Returns true if the current game state and these game settings allow the new player to connect. If true the createDefaultPlayerSettings(Integer, int, String) is called next, which will decide whether the new player becomes a participant or observer.

If a subclass does not overwrite this method it always returns true. A subclass should overwrite this method if it wants to block new players sometimes.

Parameters:
playerType - the new player's playerType, as defined in PlayerSettings
Returns:
true if the player is allowed to connect

createDefaultPlayerSettings

public PlayerSettings createDefaultPlayerSettings(Integer playerID,
                                                  int playerType,
                                                  String nickname)
Creates a new PlayerSettings based on the current game state. Subclasses that overwrite this method should not make any changes to the playerID, playerType or nickname and pass it to the constructor of a subclass of PlayerSettings, together with the engine variable.

If a subclass does not overwrite this method it creates a new StandardPlayerSettings, a participating if the game is not playing and observing if the game is playing. A subclass should overwrite this method if it wants to use custom PlayerSettings.

Parameters:
playerID - the new player's unique identification
playerType - the new player's playerType, as defined in PlayerSettings
nickname - the new player's preferred nickname filtered from bad language if bad language is filtered by the server.
Returns:
default player settings for the new player

isChangePlayerSettingsAllowed

public boolean isChangePlayerSettingsAllowed(PlayerSettings currentPlayerSettings,
                                             PlayerSettings changedPlayerSettings)
Return true if the current game state and these game settings allow a player to change his player settings.

If true the PlayerSettings.isChangePlayerSettingsAllowed(PlayerSettings) is called next, which checks if the old player settings allow the change.

If a subclass does not overwrite this method it always returns true. A subclass should overwrite this method if it wants to block players changing their player settings sometimes.

Parameters:
currentPlayerSettings - the current player settings
changedPlayerSettings - the changed player settings
Returns:
true if player is allowed to change his player settings

isStartGameAllowed

public boolean isStartGameAllowed()
Returns true if the current game state allows a game to be started.

If a subclass does not overwrite this method it always returns true. A subclass should overwrite this method if it wants to disallow a game to be started, for example when there aren't enough participants.

Returns:
true if a game is allowed to start

setEngine

public final void setEngine(Engine engine)
Sets the Engine for these game settings. This method should only be used by the SGN framework.

Parameters:
engine -


Copyright © 2003-2004 The 3 Belgians. All Rights Reserved.