Class Game

java.lang.Object
io.sockit.gameserver.Game

public abstract class Game
extends Object
An instance of this class represents a New Game. The class has factory methods to create rooms. Every Game class has to extend Game and override the abstract factory methods and event/callback methods
  • Field Summary

    Fields 
    Modifier and Type Field Description
    String gameName
    the game Name
  • Constructor Summary

    Constructors 
    Constructor Description
    Game​(String gameName, boolean isPlayerDataSameForAllClients)
    Creates a new Game.
  • Method Summary

    Modifier and Type Method Description
    void addNewLocation​(String locationName)
    This method adds a new location to the Game
    Room createPrivateRoom​(User user, int totalNoOfSeats, int turnDurationInSecs, JsonObject additionalRoomConfig)
    Creates a private room for a user if one does not exist.
    Room createPublicRoom​(String locationName, String roomName, RoomType roomType, int totalNoOfSeats, int turnDurationInSecs, JsonObject additionalRoomConfig)
    Creates a public room.
    void deleteLocation​(Location location)
    Deletes the specified location from the game
    void deleteLocation​(String locationName)
    Deletes a location of the specified name from the game
    void destroyPrivateRoom​(User user)
    This method destroys the private room of the user if one exists
    Location getLocation​(String locationName)
    gets Location by Name
    List<Location> getLocations()
    This method returns returns all the locations of the Game.
    Room getPrivateRoom​(User user)
    The method returns a the private room of the user if one exists
    static Room getRoom​(Long roomId)
    Returms the room with the specified room ID
    boolean hasPrivateRoom​(User user)
    Checks if user has a private room
    protected abstract CompressibleData newGameUserData()
    Factory method for creating GameUserData for a first time player of the Game.
    protected abstract Room newRoom​(String roomName, RoomType roomType, int totalNoOfSeats, int turnDurationInSecs, JsonObject additionalRoomConfig)
    Factory method which is called to create a new room for the Game at runtime.
    protected abstract void onEnterGame​(Session session, boolean firstTime)
    Event-Handler/Callback - called when a client session enters the Game (i.e.
    protected abstract void onExitGame​(Session session)
    Event-Handler/Callback - called when a client session exits the Game (i.e.
    void reconfigurePrivateRoom​(User user, int totalNoOfSeats, int turnDurationInSecs, JsonObject additionalRoomConfig)
    Reconfigures a private room for a user if one exists.
    protected abstract void setUpGame()
    This method is called to initialize and set up the Game - here create the locations and public rooms of the game and start bots.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • Game

      public Game​(String gameName, boolean isPlayerDataSameForAllClients)
      Creates a new Game. isPlayerDataSameForAllClients should be true if the player data is same for player's client as well as other clients. For example in poker you will not send the player's hole cards to other clients. But in games like chess or tic tac toe the player data will be the same. If the data is same this method should return true. When this method returns true the game engine can do some optimizations and speed up the sending of room state to clients. Note if you are not sure then this value should be false.
      Parameters:
      gameName - - the game Name
      isPlayerDataSameForAllClients - - whether the player data is same for player's client as well as other clients. if you are not sure then this value should be false.
  • Method Details

    • setUpGame

      protected abstract void setUpGame()
      This method is called to initialize and set up the Game - here create the locations and public rooms of the game and start bots.
    • addNewLocation

      public final void addNewLocation​(String locationName)
      This method adds a new location to the Game
      Parameters:
      locationName - - the location name. eg "Mumbai" or "Las Vegas"
    • deleteLocation

      public void deleteLocation​(Location location)
      Deletes the specified location from the game
      Parameters:
      location - - the location to be deleted
    • deleteLocation

      public void deleteLocation​(String locationName)
      Deletes a location of the specified name from the game
      Parameters:
      locationName - - the name of the location to be deleted
    • getLocation

      public Location getLocation​(String locationName)
      gets Location by Name
      Parameters:
      locationName - - the name of the location
      Returns:
      Location - the location with the given Name
    • getRoom

      public static Room getRoom​(Long roomId)
      Returms the room with the specified room ID
      Parameters:
      roomId - - the room Id
      Returns:
      Room - the room with the specified roomId
    • getLocations

      public List<Location> getLocations()
      This method returns returns all the locations of the Game.
      Returns:
      List<Location> - list of all the locations of the Game
    • createPrivateRoom

      public Room createPrivateRoom​(User user, int totalNoOfSeats, int turnDurationInSecs, JsonObject additionalRoomConfig)
      Creates a private room for a user if one does not exist. Returns the new room. If a private room already exists then the method will return the existing room.
      Parameters:
      user - - the user for whom the private room is created
      totalNoOfSeats - - the max number of players who can play in the room
      turnDurationInSecs - - the duration of 1 turn in seconds
      additionalRoomConfig - - additional configuration data for the room in json format
      Returns:
      Room - the new private room that was created or old private room if one already exists for the user
    • getPrivateRoom

      public Room getPrivateRoom​(User user)
      The method returns a the private room of the user if one exists
      Parameters:
      user - - the user who owns the private room
      Returns:
      - the private room of the user if one exists or null.
    • reconfigurePrivateRoom

      public final void reconfigurePrivateRoom​(User user, int totalNoOfSeats, int turnDurationInSecs, JsonObject additionalRoomConfig) throws SeatsNotEmptyException, GamePlayInProgressException
      Reconfigures a private room for a user if one exists.
      Parameters:
      user - - the user for whom the private room is created
      totalNoOfSeats - - the max number of players who can play in the room
      turnDurationInSecs - - the duration of 1 turn in seconds
      additionalRoomConfig - - additional configuration data for the room in json format
      Throws:
      GamePlayInProgressException - - if this method is invoked while gamePlay is in progres
      SeatsNotEmptyException - - if this method tries to change the totalNoOfSeats and the seats are not empty
    • destroyPrivateRoom

      public final void destroyPrivateRoom​(User user)
      This method destroys the private room of the user if one exists
      Parameters:
      user - - the user who owns the private room
    • hasPrivateRoom

      public boolean hasPrivateRoom​(User user)
      Checks if user has a private room
      Parameters:
      user - - the user whose private room existence is to be checked
      Returns:
      boolean - true if the user has a private room else false
    • createPublicRoom

      public Room createPublicRoom​(String locationName, String roomName, RoomType roomType, int totalNoOfSeats, int turnDurationInSecs, JsonObject additionalRoomConfig)
      Creates a public room.
      Parameters:
      locationName - - the name of the location where the room will be created
      roomName - - the name of the room
      roomType - - the type of the room (normal or fast)
      totalNoOfSeats - - the max number of players who can play in the room
      turnDurationInSecs - - duration of a turn in seconds
      additionalRoomConfig - - additional configuration actionData for the room in json format
      Returns:
      - the room that is created
    • newRoom

      protected abstract Room newRoom​(String roomName, RoomType roomType, int totalNoOfSeats, int turnDurationInSecs, JsonObject additionalRoomConfig)
      Factory method which is called to create a new room for the Game at runtime. This method should be overridden in the Game class. Can return null
      Parameters:
      roomName - - the name of the room
      roomType - - the type of the room
      totalNoOfSeats - - the max number of players who can play in the room
      turnDurationInSecs - - duration of a turn in seconds
      additionalRoomConfig - - additional configuration data for the room in json format
      Returns:
      Room - the new room that is created
    • newGameUserData

      protected abstract CompressibleData newGameUserData()
      Factory method for creating GameUserData for a first time player of the Game. This method should be overridden in the Game class
      Returns:
      CompressibleData - the new instance of GameUserData
    • onEnterGame

      protected abstract void onEnterGame​(Session session, boolean firstTime)
      Event-Handler/Callback - called when a client session enters the Game (i.e. selects the game)
      Parameters:
      session - - the client session
      firstTime - - if the user selected the game for the first time
    • onExitGame

      protected abstract void onExitGame​(Session session)
      Event-Handler/Callback - called when a client session exits the Game (i.e. deselects the game)
      Parameters:
      session - - the client session