In Skillz+SyncPlay.h
, you will be able to find functions you can call for your synchronous tournaments, such as:
isMatchCompleted:
- Returns true if a player has started disconnect/ shutdown (on reporting score or aborting).
sendData:
- Explained in previous section <link here>.
getConnectedPlayerCount:
- Returns num players currently connected to the server.
getCurrentPlayerId:
- Returns current player ID as a long.
getServerTime:
- Returns server time in seconds as double (Prototype, Unreliable).
getTimeLeftForReconnection:
- 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 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:
- The first player returned from the Players array could go first.
- Use the Skillz Random class to implement a coin toss functionality.
Example:
SKZPlayer *firstPlayer = [self.matchInfo.players firstObject];
for (SKZPlayer *player in self.matchInfo.players) {
if (player.isCurrentPlayer) {
self.currentPlayer = player;
} else {
self.opponent = player;
}
}
if (firstPlayer.isCurrentPlayer) {
self.isGameHost = YES;
playerSymbol = @"x";
opponentSymbol = @"o";
[self.turnLabel setText:@"Your Turn"];
} else {
playerSymbol = @"o";
opponentSymbol = @"x";
[self.turnLabel setText:[NSString stringWithFormat:@"%@'s Turn", self.opponent.displayName]];
}
Step 2:
Reporting a score is still the same. You’ll just need to call displayTournameResultsWithScore
.
onMatchCompleted
method. This is called once a player has reported a score or aborted the match through the corresponding Skillz API methods.onDidReceiveData
& onMatchCompleted
: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.
Note: Without following the steps to handle disconnections, you may experience frozen game states as the disconnect logic is not yet being handled.