realtime-turn-based-gaming

Realtime 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.

Note that turns are allotted in a fixed order and can’t be altered from the client. If your game requires assigning turns in variable manner (such as repeating or skipping certain turns etc.) or variable turn time for each player, then the ready-made cloud APIs are not the way to go. Its best to either build your custom solution using a combination of chat/update messages and room properties on the cloud. Alternatively, you can use our on-premise AppWarpS2 solution which allows customization and extension of the server side as well.

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. Once the room has been created, the start API can be called. This will start the turn logic on the server and result in the notifications regarding moves and turn changes to be sent out to the subscribers of the room.
public void startGame()
Once the game is started (on receipt of onGameStarted), the client whose turn it is will use the sendMove API to update the turn and inform the other users of the move made.
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 moveData field of the event will be empty in case of turn expiry. 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
The game can also be stopped/suspended while its in progress. This is useful if in some cases you want to allow a client some more time to finish their move. Or also if one of the clients is experiencing connectivity issues and you want to pause the game. This is done using the stopGame API.
public void stopGame()
Once the game is stopped, you need to call startGame again to resume the state. The turn will be of the same user who had it when the game was stopped. Clients can also check the recent history of turns (up to 5). This is useful in cases where a client joins in late or misses some events while it is recovering from intermittent connectivity issues.
public void getMoveHistory()

Samples Using AppWarp Turn Based Room APIs


Corona Tic Tac Toe Tutorial
Windows Phone Catapult Wars Sample