Special

Introducing the “Welcome to Xojo” Bundle!

New to Xojo and looking for guidance? We've put together a terrific bundle to welcome you! Xojo Bundle

This bundle includes six back issues of the magazine -- all of year 21 in printed book and digital formats -- plus a one-year subscription (beginning with 22.1) so you'll be learning all about Xojo for the next year. It's the perfect way to get started programming with Xojo. And you save as much as $35 over the non-bundle price!

This offer is only available for a limited time as supplies are limited, so hurry today and order this special bundle before the offer goes away!

Article Preview


Buy Now

Issue 12.6 ('Cheap Web App Hosting')
Instant purchase and download via GumRoad!

FEATURE

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
Resource File(s):

Download Icon 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 GKGameKitMBS event 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 Matches button with code GKTurnBasedMatchMBS.loadMatches in its Action event.

When this action is completed, the MyGameKitMSB.loadMatchesCompleted event 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.