Package com.smartfoxserver.v2.game
Class SFSGame
- java.lang.Object
-
- com.smartfoxserver.v2.entities.SFSRoom
-
- com.smartfoxserver.v2.game.SFSGame
-
- All Implemented Interfaces:
Room
public class SFSGame extends SFSRoom
Introduction
The SFSGame class is part of the SFS2X Game API which allow advanced Game tools for setting up matches, invite and challenge users, quick jump into a game, matching users based on custom criteria and more... An SFSGame extends the normal capabilities of a Room adding the ability to set the Game as public or private and provide a list of invited people that the system will invite in the game.Each game can be configured to match specific types of Users by providing a User Match Expression. The expression contains criteria that are checked against each User that wants to join the game and provides a mean for filtering players. The Match Expression can check any User Variable plus a number of other properties exposed in the
UserProperties
class.Let's see an example: user Peter has two variables set.
- Rank: 10
- BestScore: 25000
Unfortunately the SFSGame expression is set as follows: (Rank > 10) OR (BestScore > 30000)
Any attempt to join the Game will be refused because the player doesn't match the SFSGame criteria.Public SFSGame
A public game can be joined by any Player whose variables match the SFSGame User Match Expression.Private SFSGame
A private game will only be accessible to invited players. The list of invited users is passed to the API at the creation of the Game and it will also be possible to let the server find more players to invite automatically if necessary.Game State
The SFSGame object can also automatically notify the game stated (started / not started) state via a reserved RoomVariable. The variable will have the global flag set so it will be visible to all Users in the Zone.- See Also:
CreateSFSGameSettings
-
-
Constructor Summary
Constructors Constructor Description SFSGame(java.lang.String name)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addUser(User user, boolean asSpectator)
int
getMinPlayersToStartGame()
This is the minimum number of players that are required for the game to startMatchExpression
getPlayerMatchExpression()
Get the MatchExpression that is going to be checked against any Player joining this Room.
By default this is null and no matching is performed.MatchExpression
getSpectatorMatchExpression()
Get the MatchExpression that is going to be checked against any Spectator joining this Room.
By default this is null and no matching is performed.boolean
isGameStarted()
Checks if the minimum amount of players to start the game was reached.boolean
isGameStateChanged()
This is useful for server side events.boolean
isLeaveLastRoomOnJoin()
A Game can be configured so that when the Player has joined he auto-leaves the previous Roomboolean
isNotifyGameStarted()
The SFSGame can notify the status of the Game (started/not started) via a reserved RoomVariablevoid
removeUser(User user)
void
setLeaveLastRoomOnJoin(boolean leaveLastRoomOnJoin)
void
setMinPlayersToStartGame(int min)
This is not modifiable at runtime.
The parameter should be specified in the CreateGameSettingsvoid
setNotifyGameStarted(boolean notifyGameStarted)
void
setPlayerMatchExpression(MatchExpression exp)
This is not modifiable at runtime.
The MatchExpression should be specified in the CreateGameSettingsvoid
setSpectatorMatchExpression(MatchExpression spectatorMatchExpression)
This is not modifiable at runtime.
The parameter should be specified in the CreateGameSettingsvoid
switchPlayerToSpectator(User user)
void
switchSpectatorToPlayer(User user)
java.lang.String
toString()
-
Methods inherited from class com.smartfoxserver.v2.entities.SFSRoom
addUser, containsProperty, containsUser, containsUser, containsVariable, destroy, equals, getAdminHelper, getAutoRemoveMode, getCapacity, getDump, getExtension, getGroupId, getId, getLifeTime, getMaxRoomVariablesAllowed, getMaxSpectators, getMaxUsers, getName, getOwner, getPassword, getPlayerIdGeneratorClassName, getPlayersList, getProperties, getProperty, getRoomVariablesData, getSessionList, getSize, getSpectatorsList, getUserById, getUserByName, getUserByPlayerId, getUserBySession, getUserList, getUserListData, getUserManager, getVariable, getVariables, getVariablesCount, getVariablesCreatedByUser, getZone, isActive, isAllowOwnerInvitations, isDynamic, isEmpty, isFlagSet, isFull, isGame, isHidden, isPasswordProtected, isPublic, isSuppressUserList, isUseWordsFilter, removeProperty, removeVariable, removeVariablesCreatedByUser, removeVariablesCreatedByUser, setActive, setAdminHelper, setAllowOwnerInvitations, setAutoRemoveMode, setCapacity, setDynamic, setExtension, setFlag, setFlags, setGame, setGame, setGroupId, setHidden, setMaxRoomVariablesAllowed, setMaxSpectators, setMaxUsers, setName, setOwner, setPassword, setProperties, setProperty, setSuppressUserList, setUserManager, setUseWordsFilter, setVariable, setVariable, setVariables, setVariables, setZone, toSFSArray
-
-
-
-
Method Detail
-
getPlayerMatchExpression
public MatchExpression getPlayerMatchExpression()
Get the MatchExpression that is going to be checked against any Player joining this Room.
By default this is null and no matching is performed.- Returns:
- the MatchExpression
- See Also:
MatchExpression
-
getMinPlayersToStartGame
public int getMinPlayersToStartGame()
This is the minimum number of players that are required for the game to start- Returns:
- the amoung of players required to start the game
-
setPlayerMatchExpression
public void setPlayerMatchExpression(MatchExpression exp)
This is not modifiable at runtime.
The MatchExpression should be specified in the CreateGameSettings- See Also:
CreateSFSGameSettings
-
getSpectatorMatchExpression
public MatchExpression getSpectatorMatchExpression()
Get the MatchExpression that is going to be checked against any Spectator joining this Room.
By default this is null and no matching is performed.- Returns:
- the MatchExpression
- See Also:
MatchExpression
-
setSpectatorMatchExpression
public void setSpectatorMatchExpression(MatchExpression spectatorMatchExpression)
This is not modifiable at runtime.
The parameter should be specified in the CreateGameSettings- See Also:
CreateSFSGameSettings
-
setMinPlayersToStartGame
public void setMinPlayersToStartGame(int min)
This is not modifiable at runtime.
The parameter should be specified in the CreateGameSettings- See Also:
CreateSFSGameSettings
-
isLeaveLastRoomOnJoin
public boolean isLeaveLastRoomOnJoin()
A Game can be configured so that when the Player has joined he auto-leaves the previous Room- Returns:
- true if the Game is configured to make the Player leave his previous Room once joined.
-
setLeaveLastRoomOnJoin
public void setLeaveLastRoomOnJoin(boolean leaveLastRoomOnJoin)
-
isNotifyGameStarted
public boolean isNotifyGameStarted()
The SFSGame can notify the status of the Game (started/not started) via a reserved RoomVariable- Returns:
- true if the game status notification is active
- See Also:
ReservedRoomVariables.RV_GAME_STARTED
-
setNotifyGameStarted
public void setNotifyGameStarted(boolean notifyGameStarted)
-
isGameStarted
public boolean isGameStarted()
Checks if the minimum amount of players to start the game was reached.- Returns:
- true, if the minimum amount of players to start the game was reached
-
isGameStateChanged
public boolean isGameStateChanged()
This is useful for server side events. When a JOIN or LEAVE is fired the extension code can check the parameter to learn if the game state was changed- Returns:
- true if the game state has changed since the last change in the user count, e.g. from started to stopped or vice-versa
-
addUser
public void addUser(User user, boolean asSpectator) throws SFSJoinRoomException
Description copied from class:SFSRoom
- Specified by:
addUser
in interfaceRoom
- Overrides:
addUser
in classSFSRoom
- Throws:
SFSJoinRoomException
-
removeUser
public void removeUser(User user)
Description copied from class:SFSRoom
- Specified by:
removeUser
in interfaceRoom
- Overrides:
removeUser
in classSFSRoom
-
switchPlayerToSpectator
public void switchPlayerToSpectator(User user) throws SFSRoomException
Description copied from class:SFSRoom
- Specified by:
switchPlayerToSpectator
in interfaceRoom
- Overrides:
switchPlayerToSpectator
in classSFSRoom
- Throws:
SFSRoomException
-
switchSpectatorToPlayer
public void switchSpectatorToPlayer(User user) throws SFSRoomException
Description copied from class:SFSRoom
- Specified by:
switchSpectatorToPlayer
in interfaceRoom
- Overrides:
switchSpectatorToPlayer
in classSFSRoom
- Throws:
SFSRoomException
-
-