Package io.sockit.gameserver
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
-
Constructor Summary
-
Method Summary
Modifier and Type Method Description void
addNewLocation(String locationName)
This method adds a new location to the GameRoom
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 gamevoid
deleteLocation(String locationName)
Deletes a location of the specified name from the gamevoid
destroyPrivateRoom(User user)
This method destroys the private room of the user if one existsLocation
getLocation(String locationName)
gets Location by NameList<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 existsstatic Room
getRoom(Long roomId)
Returms the room with the specified room IDboolean
hasPrivateRoom(User user)
Checks if user has a private roomprotected 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.
-
Field Details
-
gameName
the game Name
-
-
Constructor Details
-
Game
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 NameisPlayerDataSameForAllClients
- - 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
This method adds a new location to the Game- Parameters:
locationName
- - the location name. eg "Mumbai" or "Las Vegas"
-
deleteLocation
Deletes the specified location from the game- Parameters:
location
- - the location to be deleted
-
deleteLocation
Deletes a location of the specified name from the game- Parameters:
locationName
- - the name of the location to be deleted
-
getLocation
gets Location by Name- Parameters:
locationName
- - the name of the location- Returns:
- Location - the location with the given Name
-
getRoom
Returms the room with the specified room ID- Parameters:
roomId
- - the room Id- Returns:
- Room - the room with the specified roomId
-
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 createdtotalNoOfSeats
- - the max number of players who can play in the roomturnDurationInSecs
- - the duration of 1 turn in secondsadditionalRoomConfig
- - 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
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, GamePlayInProgressExceptionReconfigures a private room for a user if one exists.- Parameters:
user
- - the user for whom the private room is createdtotalNoOfSeats
- - the max number of players who can play in the roomturnDurationInSecs
- - the duration of 1 turn in secondsadditionalRoomConfig
- - additional configuration data for the room in json format- Throws:
GamePlayInProgressException
- - if this method is invoked while gamePlay is in progresSeatsNotEmptyException
- - if this method tries to change the totalNoOfSeats and the seats are not empty
-
destroyPrivateRoom
This method destroys the private room of the user if one exists- Parameters:
user
- - the user who owns the private room
-
hasPrivateRoom
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 createdroomName
- - the name of the roomroomType
- - the type of the room (normal or fast)totalNoOfSeats
- - the max number of players who can play in the roomturnDurationInSecs
- - duration of a turn in secondsadditionalRoomConfig
- - 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 roomroomType
- - the type of the roomtotalNoOfSeats
- - the max number of players who can play in the roomturnDurationInSecs
- - duration of a turn in secondsadditionalRoomConfig
- - additional configuration data for the room in json format- Returns:
- Room - the new room that is created
-
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
Event-Handler/Callback - called when a client session enters the Game (i.e. selects the game)- Parameters:
session
- - the client sessionfirstTime
- - if the user selected the game for the first time
-
onExitGame
Event-Handler/Callback - called when a client session exits the Game (i.e. deselects the game)- Parameters:
session
- - the client session
-