How to Handle Game States

In, you will be able to find functions you can call for your synchronous tournaments, such as:


  • Returns true if a player has started disconnect/ shutdown (on reporting score or aborting).


  • Explained in previous section <link here>.


  • Returns num players currently connected to the server.


  • Returns current player ID as long.


  • Returns server time in seconds as double (Prototype, Unreliable).


  • Returns the actual time a player has left to reconnect if they are disconnected. You’ll need to pass in the tournament player id of the player that lost connection. For the current player pass SkillzSync.getCurrentPlayerId.

Step 1:

Determine which player goes first. Since it’s a turn-based synchronous game, you will need to create logic on which player goes first. Here are some ideas:

  1. The first player returned from the Players array could go first.
  2. Use the Skillz Random class to implement a coin toss functionality.


public static void AssignPlayers() {
    List players = Skillz.GetMatchInfo(this).players;

if (players.size() < 2) {
       Log.d("Skillz”, “Non sync game");

   if (players.get(0).getUserId() < players.get(1).getUserId()) {
       SkillzPlayer PlayerOne = players.get(0);
       SkillzPlayer PlayerTwo = players.get(1);
   } else {
       SkillzPlayer PlayerOne = players.get(1);
       SkillzPlayer PlayerTwo = players.get(0);


Step 2: 

Reporting a score is still the same. You’ll just need to call Skillz.reportScore(activity, score).


When the game reaches a finishing state, it is important that both players are able to receive and resolve the final board state before reporting a score. To help with this, the SyncDelegate declares the onMatchCompleted method. This is called once a player has reported a score or aborted the match through the corresponding Skillz API methods.
Recommended: Only verify winning states and finalize the match in onDidReceiveData & onMatchCompleted
Note: Calls to report or abort a score will send an additional message that will trigger onMatchCompleted for the opponent player.

At this point, you have the tools necessary to develop the vast majority of your synchronous application. Spend time developing the game and data exchange in a manner that will fulfill the needs of the game. It is recommended that you greatly familiarize yourself with the data exchange flow before moving to the following advanced steps.


Next Step: Handle Disconnections

Note: Without following the steps to handle disconnections, you may experience frozen game states as the disconnect logic is not yet being handled.