Class 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
    He wants to play, chooses an SFSGame and attempts to join it.
    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 Detail

      • SFSGame

        public SFSGame​(java.lang.String name)
    • 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
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class SFSRoom