net.sourceforge.simplegamenet.specs.to
Class PlayerSettings

java.lang.Object
  extended bynet.sourceforge.simplegamenet.specs.to.PlayerSettings
All Implemented Interfaces:
Comparable, Serializable
Direct Known Subclasses:
ColoredPlayerSettings, StandardPlayerSettings

public abstract class PlayerSettings
extends Object
implements Serializable, Comparable

An abstract superclass which represents all player settings for one player, identified by a playerID. For each player, there is one single PlayerSettings 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#playerSettingsUpdated(PlayerSettings, PlayerSettings) event.

These player settings should only be changed by the player (using the "Player Settings" panel in the "Chat" tab and a PlayerSettingsPanel created with the createPlayerSettingsPanel() method) or by the game server (using custom methods). The player is not allowed to change these player settings if the game is playing. The game server can change these player settings at any time but should call net.sourceforge.simplegamenet.framework.model.ServerEngineImpl#refreshPlayerSettings(Integer) so all clients update their copy.

Version:
1.0, 2003-06-18
Author:
Geoffrey De Smet
See Also:
PlayerSettingsMap, PlayerSettingsPanel, Serialized Form

Field Summary
static int BOT
          The player type of a bot.
protected  Engine engine
          The EngineImpl of the current application.
static int HOST
          The player type of the host.
static int MAXIMUM_NICKNAME_LENGTH
          The maximum length of a player's nickname
static int OBSERVING
          The playing state of a player observing the game.
static int PARTICIPATING
          The playing state of a player participating in the game.
static int USER
          The player type of a user, different from the host.
 
Constructor Summary
PlayerSettings(Engine engine, Integer playerID, int playerType, String nickname, int playingState)
          Constructs new players settings.
 
Method Summary
 int compareTo(Object object)
          Compares two player settings based on their playerIDs.
abstract  PlayerSettings createChangedPlayerSettings(PlayerSettingsPanel playerSettingsPanel)
          Creates a new PlayerSettings based on the PlayerSettingsPanel.
abstract  PlayerSettingsPanel createPlayerSettingsPanel()
          Creates a new PlayerSettingsPanel based on these player settings.
 boolean equals(Object object)
          Compares two player settings based on their playerIDs.
 String getNickname()
          Get the nickname of the player.
 Integer getPlayerID()
          Gets the playerID of the player.
 int getPlayerType()
          Gets the player type (HOST, USER or BOT) of the player.
 int getPlayingState()
          Gets the playing state (PARTICIPATING or OBSERVING) of the player.
 boolean isChangePlayerSettingsAllowed(PlayerSettings changedPlayerSettings)
          Returns true if the current game state allows these player settings to be updated to the changed player settings.
 boolean isChattingAllowedDuringGame()
          Returns true if the player is allowed to chat while the game is playing.
 void setEngine(Engine engine)
          Sets the engine for these game settings.
 void setNickname(String nickname)
          Sets the nickname for these player settings.
 void setPlayingState(int playingState)
          Sets the playing state (PARTICIPATING or OBSERVING) of the player.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAXIMUM_NICKNAME_LENGTH

public static final int MAXIMUM_NICKNAME_LENGTH
The maximum length of a player's nickname

See Also:
Constant Field Values

HOST

public static final int HOST
The player type of the host.

See Also:
Constant Field Values

USER

public static final int USER
The player type of a user, different from the host.

See Also:
Constant Field Values

BOT

public static final int BOT
The player type of a bot.

See Also:
Constant Field Values

PARTICIPATING

public static final int PARTICIPATING
The playing state of a player participating in the game.

See Also:
Constant Field Values

OBSERVING

public static final int OBSERVING
The playing state of a player observing the game.

See Also:
Constant Field Values

engine

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

Constructor Detail

PlayerSettings

public PlayerSettings(Engine engine,
                      Integer playerID,
                      int playerType,
                      String nickname,
                      int playingState)
Constructs new players settings. The SimpleGameNet framework asks the GameSettings to create player settings for a new player with GameSettings.createDefaultPlayerSettings(Integer, int, String).

This class PlayerSettings can be extended directly to use custom settings or one of the configurable player settings from the net.sourceforge.simplegamenet.specs.tools package can be used, such as StandardPlayerSettings or ColoredPlayerSettings.

Parameters:
engine - the engine of the current application
playerID - the playerID which uniquely identifies the player, which never changes
playerType - the type of the player (HOST, USER or BOT), which never changes
nickname - the nickname of the player
playingState - the playing state of the player (PARTICIPATING or OBSERVING)
Method Detail

createPlayerSettingsPanel

public abstract PlayerSettingsPanel createPlayerSettingsPanel()
Creates a new PlayerSettingsPanel based on these player settings. This new PlayerSettingsPanel is shown in the "Player Settings" panel in the "Chat" tab only with the player whose player settings it represent.

Returns:
a new PlayerSettingsPanel

createChangedPlayerSettings

public abstract PlayerSettings createChangedPlayerSettings(PlayerSettingsPanel playerSettingsPanel)
Creates a new PlayerSettings based on the PlayerSettingsPanel. This method fetches all the data a player can edit with custom methods from the PlayerSettingsPanel and copies any non editable data from these player settings into the new PlayerSettings.

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

Returns:
a new PlayerSettings

isChangePlayerSettingsAllowed

public boolean isChangePlayerSettingsAllowed(PlayerSettings changedPlayerSettings)
Returns true if the current game state allows these player settings to be updated to the changed player settings. This method is called after createChangedPlayerSettings(PlayerSettingsPanel) 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 player to change his player settings to certain settings sometimes.

Parameters:
changedPlayerSettings - the changed player settings created by createChangedPlayerSettings(PlayerSettingsPanel)
Returns:
true if the player settings are allowed to change

isChattingAllowedDuringGame

public boolean isChattingAllowedDuringGame()
Returns true if the player is allowed to chat while the game is playing.

If a subclass does not overwrite this method it always returns true.

Returns:
true if the player is allowed to chat while the game is playing

getPlayerID

public Integer getPlayerID()
Gets the playerID of the player.

Returns:
the playerID of the player

getPlayerType

public int getPlayerType()
Gets the player type (HOST, USER or BOT) of the player.

Returns:
the player type of the player

getNickname

public String getNickname()
Get the nickname of the player.

Returns:
the nickname of the player

getPlayingState

public int getPlayingState()
Gets the playing state (PARTICIPATING or OBSERVING) of the player.

Returns:
the playing state of the player

setPlayingState

public void setPlayingState(int playingState)
Sets the playing state (PARTICIPATING or OBSERVING) of the player. Afther this method the game server should call net.sourceforge.simplegamenet.framework.model.ServerEngineImpl#refreshPlayerSettings(Integer) with the playerID of these player settings.

Parameters:
playingState - the playing state of the player

equals

public boolean equals(Object object)
Compares two player settings based on their playerIDs.

Parameters:
object - the object to compare these player settings against
Returns:
these player settings's playerID compared to those of the argument

compareTo

public int compareTo(Object object)
Compares two player settings based on their playerIDs.

Specified by:
compareTo in interface Comparable
Parameters:
object - the object to compare these player settings against
Returns:
these player settings's playerID compared to those of the argument

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 -

setNickname

public void setNickname(String nickname)
Sets the nickname for these player settings. This method should only be used by the SGN framework.

Parameters:
nickname -


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