Writing OS X Apps for Game Center
Part 3: Turn-Based Games
Issue: 12.6 (November/December 2014)
Author: Tom Baumgartner
Author Bio: Tom is retired and enjoys programming in Xojo (at XDC 2014 he was one of the attendees recognized for 15 years of using RealBasic/Xojo). Along with curling, Xojo fills the Canadian winter when Tom can’t golf, fish, or play tennis.
Article Description: No description available.
Article Length (in bytes): 29,637
Starting Page Number: 24
Article Number: 12604
12604project.zip Updated: 2014-11-03 13:57:05
Related Link(s): None
Excerpt of article text...
My Game Center article in the previous issue covered requesting a real-time game because real-time gaming seemed simpler than turn-based games. That article did not actually complete the match request and play the game. This issue will discuss designing a turn-based game, requesting a match from Game Center, and playing the game. Though this is heavy with implementation code, none of it is complex.
First, a reminder that Game Center interactions are asynchronous. Your program initiates some action and it is completed at a later time when a
GKGameKitMBSevent is fired, indicating that Game Center has replied. The reply is usually very fast. But it can take minutes for Game Center to forward player turn messages to the opponent. From experience, I have concluded that the Game Center server has a tiered service model for dealing with turn messages. Usually the response is quick when the two players are making moves back and forth within a few seconds. The response is slow after the first player’s move for a new match and when a player has taken some time to send a move. Be patient when you are testing your new turn-based game. To aid in understanding what is happening in this asynchronous environment and to help in debugging, almost every event or operation logs to the listbox in the example project that you can download. To illustrate this asynchronous operation look at the
Load Existing Matchesbutton with code
When this action is completed, the
MyGameKitMSB.loadMatchesCompletedevent fires with an array of existing matches belonging to the local player. The following code deals with any error and passes the array of matches to the game for processing.
Sub loadMatchesCompleted(matches() as GKTurnBasedMatchMBS, error as NSErrorMBS, tag as variant)
dim count as integer
...End of Excerpt. Please purchase the magazine to read the full article.