-
Notifications
You must be signed in to change notification settings - Fork 9
Turn based gaming
AppWarp provides out of the box APIs for real-time turn based games. This eliminates the client-side effort required for the following
- distributed timer management
- distributed turn management
- distributed state management
All the management is done on the server side by AppWarp cloud when a turn based room is created. Notifications are sent to clients when a move is made or a player's turn expires. Player's turns are assigned in the order in which the room is joined. Developers have the flexibility of defining the maximum turn time to be allotted for each turn. If a player fails to send its move in the allotted time or leaves the room, its turn expires and the turn is passed to the next player. All the timer and turn management logic is implemented on the server by AppWarp and clients simply need to react to the events.
Sending a move is simple and developers can send any string data up to 500 characters.
Here is a summary of the APIs (Java for example below - similar APIs are available for all supported platforms)
public void createTurnRoom(String name, String owner, int maxUsers, Hashtable<String, Object> tableProperties, int turnTime)
This is similar to the creation of dynamic rooms with the addition of a turn time.
public void startGame()
This tells the server that room is ready for game play and players will now start getting turns in order and with the time allotted. The result of the request is provided in the onStartGameDone callback of the TurnBasedRoomListener. If successful, it also triggers the following notification to all subscribed clients
public void onGameStarted(String sender, String roomid, String nextTurnUser);
It informs the users of who sent the request, the id of the room concerned and whose turn it is now.
public void stopGame()
This tells the server that room is stopped. The result of the request is provided in the onStopGameDone callback of the TurnBasedRoomListener. When a room is in stopped state, it will not accept sendMove requests and the turn timer will be suspended. It triggers the following notification to all subscribed clients
public void onGameStopped(String sender, String roomid);
It informs the users of who sent the request and the id of the room concerned.
public void sendMove(String moveData)
This API is used to send the player's move and will result in onMoveCompleted notification to all the subscribed users of the room.
public void onMoveCompleted(MoveEvent moveEvent);
This is the event raised on the registered notification listener when a player successfully makes a move or a turn expires. The move event object contains the following information
- moveData - The associated move data.
- sender - The sender of the move.
- RoomId - The id of the room in which the move was sent
- nextTurn - The username of the user whose turn it is now
getMoveHistory()
This sends a move history request to the server. The result will be available in the onGetMoveHistoryDone callback of the TurnBasedRoomListener object. The server will send up to the last 5 moves.