Interface IPlayerIdGenerator

  • All Known Implementing Classes:
    DefaultPlayerIdGenerator

    public interface IPlayerIdGenerator

    Overview

    This interface provides the skeleton for a PlayerId Generator implementation used in Game Rooms. The task of PlayerId Generator is to create and distribute unique player id(s) to users joining a Game Room. By default SFS2X provides its default implementation which uses incremental integer values starting from index 1.

    Developers will be able to create their own implementation and plug it in any dynamic or static Room by providing a reference to their class name.

    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      void freePlayerSlot​(int playerId)
      This method is called by the parent Room when a Player leaves the game and his player slot can be freed up.
      Room getParentRoom()
      Get a reference to the parent Room
      int getPlayerSlot()
      Return a new player slot/id
      void init()
      The init() method is invoked immediately after the successful creation of the Game Room.
      void onRoomResize()
      This method is invoked upon a Room size change.
      void setParentRoom​(Room room)  
    • Method Detail

      • init

        void init()
        The init() method is invoked immediately after the successful creation of the Game Room. Here the developer can add any initialization code. It is recommended to use this method instead of the constructor to setup your data structures etc... This is because only in the init() method you will be able to access the parent Room.
        See Also:
        getParentRoom()
      • getPlayerSlot

        int getPlayerSlot()
        Return a new player slot/id
        Returns:
        the new player id
      • freePlayerSlot

        void freePlayerSlot​(int playerId)
        This method is called by the parent Room when a Player leaves the game and his player slot can be freed up.
        Parameters:
        playerId - the id that should be freed up
      • onRoomResize

        void onRoomResize()
        This method is invoked upon a Room size change. Depending on the logic that generates Player id(s) it might be necessary to take rearrange player id data after a Room resize.
      • setParentRoom

        void setParentRoom​(Room room)
      • getParentRoom

        Room getParentRoom()
        Get a reference to the parent Room
        Returns:
        the parent Room