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 the AppWarp S2 turn based room. 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.

Customizing the Turn based game behaviour

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 you need to define your own TurnBasedRoomAdaptor and override its methods to alter the behavior. This is illustrated in the Rummy Cards game sample provided in the download section.

For server-side control, you will need to use ITurnBasedRoom interface and add your extension by setting your implementation of the BaseTurnRoomAdaptor.

Client side usage of the turn-based room APIs

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()