Class: GKTurnBasedMatch

Inherits:
NSObject show all

Overview

The GKTurnBasedMatch class allows your game to implement turn-based matches between sets of players on Game Center. A turn-based match uses a store-and-forward approach to share data between the participants. When a player participating in the match performs actions that advance the state of the match, your game describes the new state of the match and decides which player acts next. The next player to act is notified by a push notification. Later, when the next player launches your game, you download the match data from Game Center and continue the match. Players take turns acting (based on whatever internal logic your game implements) until the match ends. One advantage of turn-based matches is that a player may participate in multiple matches simultaneously.

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from NSObject

#!, #!=, #!~, #, #==, #===, #=~, #Rational, #__callee__, #__method__, #__send__, #__type__, `, alloc, allocWithZone:, #autoContentAccessingProxy, autoload, autoload?, autorelease_pool, #awakeAfterUsingCoder:, binding, block_given?, caller, cancelPreviousPerformRequestsWithTarget:, cancelPreviousPerformRequestsWithTarget:selector:object:, catch, class, classFallbacksForKeyedArchiver, #classForCoder, #classForKeyedArchiver, classForKeyedUnarchiver, #clone, conformsToProtocol:, #copy, copyWithZone:, #dealloc, #define_singleton_method, description, display, #doesNotRecognizeSelector:, #dup, #enum_for, #eql?, #equal?, #extend, fail, #finalize, format, #forwardInvocation:, #forwardingTargetForSelector:, framework, #freeze, #frozen?, getpass, gets, global_variables, #init, initialize, #initialize_clone, #initialize_copy, #initialize_dup, #inspect, instanceMethodForSelector:, instanceMethodSignatureForSelector:, #instance_eval, #instance_exec, #instance_of?, #instance_variable_defined?, #instance_variable_get, #instance_variable_set, #instance_variables, instancesRespondToSelector:, isSubclassOfClass:, #is_a?, iterator?, #kind_of?, lambda, load, load_bridge_support_file, load_plist, local_variables, loop, #method, #methodForSelector:, #methodSignatureForSelector:, #methods, #mutableCopy, mutableCopyWithZone:, new, #nil?, open, p, #performSelector:onThread:withObject:waitUntilDone:, #performSelector:onThread:withObject:waitUntilDone:modes:, #performSelector:withObject:afterDelay:, #performSelector:withObject:afterDelay:inModes:, #performSelectorInBackground:withObject:, #performSelectorOnMainThread:withObject:waitUntilDone:, #performSelectorOnMainThread:withObject:waitUntilDone:modes:, print, printf, #private_methods, proc, #protected_methods, #public_method, #public_methods, #public_send, putc, puts, raise, rand, readline, readlines, #replacementObjectForCoder:, #replacementObjectForKeyedArchiver:, require, resolveClassMethod:, resolveInstanceMethod:, #respond_to?, #respond_to_missing?, select, #send, setVersion:, #singleton_methods, sprintf, srand, superclass, #taint, #tainted?, #tap, test, throw, #to_plist, #to_s, trace_var, trap, #trust, #untaint, untrace_var, #untrust, #untrusted?, version

Constructor Details

This class inherits a constructor from NSObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class NSObject

Instance Attribute Details

- (NSDate) creationDate (readonly)

The date that the match was created. (read-only)

Returns:

- (GKTurnBasedParticipant) currentParticipant (readonly)

The participant whose turn it is to act next. (read-only) The current participant is the only participant that is allowed to update the match data.

- (NSData) matchData (readonly)

Game-specific data that reflects the details of the match. (read-only) Although Game Center knows who is participating in the match and who is expected to act next, it does not know anything about your game’s internal logic. Your game provides the match data and all the programming logic required to interpret it. This data should include the current state of the game and provide any necessary details about what actions the current player is expected to take. It can also be helpful for your game to record information about recent moves made by other players. The game can then replay those moves visually for the player to show exactly how the match reached the state it is in now.Your game never directly updates the match state associated with this property. Instead, when the data is updated to reflect the actions of the current player, your game serializes the updated state into memory and calls one of the match’s instance methods that transmit the updated state to Game Center.The value of this property is nil until after your game calls the loadMatchDataWithCompletionHandler: method and the load task is complete. After this task completes, the matchData property holds the data that the last player to act transmitted to Game Center.

Returns:

- (Integer) matchDataMaximumSize (readonly)

Returns the limit the Game Center servers place on the size of the match data. (read-only) Game Kit returns an error if your game sends updated data larger than this value.

Returns:

- (String) matchID (readonly)

A string that uniquely identifies the match. (read-only) This string is not intended to be displayed to players. Your game should use this string whenever it needs to identify a specific match. For example, if you want your game to store additional information on a device or in iCloud, it might store it in a database using the match ID as a key.

Returns:

- (String) message

A message displayed to all players in the match. The message property is displayed by the standard user interface; this allows your game to use the message to inform players of the current state of the match.Important: This property can be changed only by an instance of your game associated with the current player. If an instance of your game associated with another player in the match attempts to write to this property, an exception is thrown.

Returns:

- (Array) participants (readonly)

Information about the players participating in the match. (read-only) The elements of this array are GKTurnBasedParticipant objects representing each participant in the match. Your game uses these objects to retrieve more information about the participants in the match. Your game also uses one of the objects in this array as a parameter whenever it calls a method that sets a different participant to act in the match.The size of the array and the order in which the participants appear in the array are set when the match is first created, and never changes. When a match is first created, some participants may not hold actual players yet. Game Center searches for a player to fill that spot in the match only after your game sets that participant as the current player.

Returns:

- (GKTurnBasedMatchStatus) status (readonly)

The current state of the match. (read-only)

Returns:

  • (GKTurnBasedMatchStatus)

Class Method Details

+ (Object) findMatchForRequest(request, withCompletionHandler:completionHandler)

Programmatically searches for a new match to join. When this method is called, it creates a background task to handle the request. The method then returns control to your game. Later, when the task is complete, Game Kit calls your completion handler. Keep in mind that the completion handler may be called on a thread other than the one originally used to invoke the method. This means that the code in your block needs to be thread-safe.This method may either create a new match or it may place the player into an existing match that needs a new player to advance the match further. Regardless of how the player is placed in the match, the local player is always the current participant in the returned match. Your game should immediately display the match in its user interface and allow the player to take a turn.

Parameters:

  • request

    A match request that specifies the properties that the new match must fulfill.

  • completionHandler

    A block to be called after the match is successfully created.The block receives the following parameters:matchA newly initialized match object that contains a list of players for the match. If an error occurred, this value is nil.errorIf an error occurred, this error object describes the error. If the operation was completed successfully, the value is nil.

  • match

    A newly initialized match object that contains a list of players for the match. If an error occurred, this value is nil.

  • error

    If an error occurred, this error object describes the error. If the operation was completed successfully, the value is nil.

Returns:

+ (Object) loadMatchesWithCompletionHandler(completionHandler)

Loads the set of turn-based matches involving the local player and creates a match object for each match. When this method is called, it creates a new background task to handle the request. The method then returns control to your game. Later, when the task is complete, Game Kit calls your completion handler. Keep in mind that the completion handler may be called on a thread other than the one originally used to invoke the method. This means that the code in your block needs to be thread-safe.

Parameters:

  • completionHandler

    A block to be called after the matches are retrieved from the server.The block receives the following parameters:matchesAn array of match objects that hold the requested matches. If an error occurred, this value may be non-nil. In this case, the array holds whatever match data could be retrieved from Game Center before the error occurred.errorIf an error occurred, this error object describes the error. If the operation was completed successfully, the value is nil.

  • matches

    An array of match objects that hold the requested matches. If an error occurred, this value may be non-nil. In this case, the array holds whatever match data could be retrieved from Game Center before the error occurred.

  • error

    If an error occurred, this error object describes the error. If the operation was completed successfully, the value is nil.

Returns:

+ (Object) loadMatchWithID(matchID, withCompletionHandler:completionHandler)

Loads a specific match. When this method is called, it creates a new background task to handle the request. The method then returns control to your game. Later, when the task is complete, Game Kit calls your completion handler. Keep in mind that the completion handler may be called on a thread other than the one originally used to invoke the method. This means that the code in your block needs to be thread-safe.

Parameters:

  • matchID

    The identifier for the turn-based match.

  • completionHandler

    A block to be called after the match is retrieved from the server.The block receives the following parameters:matchIf the operation completed successfully, this parameter holds the match. If an error occurred, the value is nil.errorIf an error occurred, this error object describes the error. If the operation was completed successfully, the value is nil.

  • match

    If the operation completed successfully, this parameter holds the match. If an error occurred, the value is nil.

  • error

    If an error occurred, this error object describes the error. If the operation was completed successfully, the value is nil.

Returns:

Instance Method Details

- (Object) acceptInviteWithCompletionHandler(completionHandler)

Programmatically accept an invitation to a turn-based match. When this method is called, it creates a background task to handle the request. The method then returns control to your game. Later, when the task is complete, Game Kit calls your completion handler. Keep in mind that the completion handler may be called on a thread other than the one originally used to invoke the method. This means that the code in your block needs to be thread-safe.

Parameters:

  • completionHandler

    A block to be called after the match is successfully created.The block receives the following parameters:matchA newly initialized match object that contains a list of players for the match. If an error occurred, this value is nil.errorIf an error occurred, this error object describes the error. If the operation was completed successfully, the value is nil.

  • match

    A newly initialized match object that contains a list of players for the match. If an error occurred, this value is nil.

  • error

    If an error occurred, this error object describes the error. If the operation was completed successfully, the value is nil.

Returns:

- (Object) declineInviteWithCompletionHandler(completionHandler)

Programmatically decline an invitation to a turn-based match. When this method is called, it creates a background task to handle the request. The method then returns control to your game. Later, when the task is complete, Game Kit calls your completion handler. Keep in mind that the completion handler may be called on a thread other than the one originally used to invoke the method. This means that the code in your block needs to be thread-safe.

Parameters:

  • completionHandler (Object)

    A block to be called after the match is successfully created.The block receives the following parameter:errorIf an error occurred, this error object describes the error. If the operation was completed successfully, the value is nil.

  • error (NSError *error)

    If an error occurred, this error object describes the error. If the operation was completed successfully, the value is nil.

Returns:

- (Object) endMatchInTurnWithMatchData(matchData, completionHandler:completionHandler)

Ends the match. Calling this method ends the match for all players. This method may only be called by the current participant. Before your game calls this method, the matchOutcome property on each participant object stored in the participants property must have been set to a value other than GKTurnBasedMatchOutcomeNone.When this method is called, it creates a new background task to handle the request. The method then returns control to your game. Later, when the task is complete, Game Kit calls your completion handler. Keep in mind that the completion handler may be called on a thread other than the one originally used to invoke the method. This means that the code in your block needs to be thread-safe.

Parameters:

  • matchData (NSData)

    A serialized blob of data reflecting the end state for the match.

  • completionHandler (Object)

    A block to be called after the match is successfully ended.The block receives the following parameters:errorIf an error occurred, this error object describes the error. If the operation was completed successfully, the value is nil.

  • error (NSError *error)

    If an error occurred, this error object describes the error. If the operation was completed successfully, the value is nil.

Returns:

- (Object) endTurnWithNextParticipants(nextParticipants, turnTimeout:timeout, matchData:matchData, completionHandler:completionHandler)

Updates the data stored on Game Center for the current match. If the next player to act does not take their turn in the specified interval, the next player in the array receives a notification to act. This process continues until a player takes a turn or the last player in the list is notified.When this method is called, it creates a new background task to handle the request. The method then returns control to your game. Later, when the task is complete, Game Kit calls your completion handler. Keep in mind that the completion handler may be called on a thread other than the one originally used to invoke the method. This means that the code in your block needs to be thread-safe.

Parameters:

  • nextParticipants (Array)

    An array of participant objects reflecting the order in which the players should act next. Each object in the array must be one of the objects stored in the match’s participants property.

  • timeout (NSTimeInterval)

    The length of time the next player has to complete their turn.

  • matchData (NSData)

    A serialized blob of data reflecting the game-specific state for the match.

  • completionHandler (Object)

    A block to be called after the data is uploaded to Game Center.The block receives the following parameters:errorIf an error occurred, this error object describes the error. If the operation was completed successfully, the value is nil.

  • error (NSError *error)

    If an error occurred, this error object describes the error. If the operation was completed successfully, the value is nil.

Returns:

- (Object) loadMatchDataWithCompletionHandler(completionHandler)

Loads the game-specific data associated with a match. When this method is called, it creates a new background task to handle the request. The method then returns control to your game. Later, when the task is complete, Game Kit calls your completion handler. Keep in mind that the completion handler may be called on a thread other than the one originally used to invoke the method. This means that the code in your block needs to be thread-safe.

Parameters:

  • completionHandler

    A block to be called after the scores are retrieved from the server.The block receives the following parameters:matchDataThe data stored on Game Center that reflects the current state of the match. If an error occurred, this value is nil.errorIf an error occurred, this error object describes the error. If the operation was completed successfully, the value is nil.

  • matchData

    The data stored on Game Center that reflects the current state of the match. If an error occurred, this value is nil.

  • error

    If an error occurred, this error object describes the error. If the operation was completed successfully, the value is nil.

Returns:

- (Object) participantQuitInTurnWithOutcome(matchOutcome, nextParticipants:nextParticipants, turnTimeout:timeout, matchData:matchData, completionHandler:completionHandler)

Resigns the current player from the match without ending the match. Your game calls this method on an instance of your game that is processing the current player’s turn, but that player has left the match. For example, the player may have willingly resigned from the match or that player may have been eliminated by the other players (based on your game’s internal logic).If the next player to act does not take their turn in the specified interval, the next player in the array receives a notification to act. This process continues until a player takes a turn or the last player in the list is notified.When this method is called, it creates a new background task to handle the request. The method then returns control to your game. Later, when the task is complete, Game Kit calls your completion handler. Keep in mind that the completion handler may be called on a thread other than the one originally used to invoke the method. This means that the code in your block needs to be thread-safe.

Parameters:

  • matchOutcome (GKTurnBasedMatchOutcome)

    The end outcome of the current player in the match.

  • nextParticipants (Array)

    An array of participant objects reflecting the order in which the players should act next. Each object in the array must be one of the objects stored in the match’s participants property.

  • timeout (NSTimeInterval)

    The length of time the next player has to complete their turn.

  • matchData (NSData)

    A serialized blob of data reflecting the game-specific state for the match.

  • completionHandler (Object)

    A block to be called after the data is uploaded to the server.The block receives the following parameters:errorIf an error occurred, this error object describes the error. If the operation was completed successfully, the value is nil.

  • error (NSError *error)

    If an error occurred, this error object describes the error. If the operation was completed successfully, the value is nil.

Returns:

- (Object) participantQuitOutOfTurnWithOutcome(matchOutcome, withCompletionHandler:completionHandler)

Resigns the player from the match when that player is not the current player. This action does not end the match If the local player decided they wanted to resign from the match but is not the current participant in the match, your game calls this method.When this method is called, it creates a new background task to handle the request. The method then returns control to your game. Later, when the task is complete, Game Kit calls your completion handler. Keep in mind that the completion handler may be called on a thread other than the one originally used to invoke the method. This means that the code in your block needs to be thread-safe.

Parameters:

  • matchOutcome (GKTurnBasedMatchOutcome)

    The end outcome of the current player in the match.

  • completionHandler (Object)

    A block to be called after the player’s status is updated on Game Center.The block receives the following parameters:errorIf an error occurred, this error object describes the error. If the operation was completed successfully, the value is nil.

  • error (NSError *error)

    If an error occurred, this error object describes the error. If the operation was completed successfully, the value is nil.

Returns:

- (Object) rematchWithCompletionHandler(completionHandler)

Create a new turn-based match with the same participants as an existing match. When this method is called, it creates a background task to handle the request. The method then returns control to your game. Later, when the task is complete, Game Kit calls your completion handler. Keep in mind that the completion handler may be called on a thread other than the one originally used to invoke the method. This means that the code in your block needs to be thread-safe.

Parameters:

  • completionHandler

    A block to be called after the match is successfully created.The block receives the following parameters:matchA newly initialized match object that contains a list of players for the match. If an error occurred, this value is nil.errorIf an error occurred, this error object describes the error. If the operation was completed successfully, the value is nil.

  • match

    A newly initialized match object that contains a list of players for the match. If an error occurred, this value is nil.

  • error

    If an error occurred, this error object describes the error. If the operation was completed successfully, the value is nil.

Returns:

- (Object) removeWithCompletionHandler(completionHandler)

Programmatically removes a match from Game Center. Even after a player’s participation in a match ends, the data associated with the match continues to be stored on Game Center. Storing the data on Game Center allows the player to continue to watch the match’s progress, or even see the final state of the match when it ends. However, players may also want to delete matches that they have finished playing. If you choose not to use the standard matchmaker user interface, your game should offer the ability to delete a finished match from Game Center. When a player chooses to delete a match from Game Center, call this method. It is a programming error to call this method on a match that has the local player as an active participant.When this method is called, it creates a new background task to handle the request. The method then returns control to your game. Later, when the task is complete, Game Kit calls your completion handler. Keep in mind that the completion handler may be called on a thread other than the one originally used to invoke the method. This means that the code in your block needs to be thread-safe.When the task completes, the match is no longer visible to the local player whose device made the call. Other players involved in the match still see the match.

Parameters:

  • completionHandler (Object)

    A block to be called after the scores are retrieved from the server.The block receives the following parameters:errorIf an error occurred, this error object describes the error. If the operation was completed successfully, the value is nil.

  • error (NSError *error)

    If an error occurred, this error object describes the error. If the operation was completed successfully, the value is nil.

Returns:

- (Object) saveCurrentTurnWithMatchData(matchData, completionHandler:completionHandler)

Update the match data without advancing the game to another player. This method updates the match data stored on Game Center. Call this method when the current player takes an action that advances the state of the match but does not end the player’s turn. For example, if your game has a fog-of-war mechanic, you might call this method when the player revealed new information on the map.When this method is called, it creates a new background task to handle the request. The method then returns control to your game. Later, when the task is complete, Game Kit calls your completion handler. Keep in mind that the completion handler may be called on a thread other than the one originally used to invoke the method. This means that the code in your block needs to be thread-safe.

Parameters:

  • matchData (NSData)

    A serialized blob of data reflecting the game-specific state for the match.

  • completionHandler (Object)

    A block to be called after the data is uploaded to Game Center.The block receives the following parameters:errorIf an error occurred, this error object describes the error. If the operation was completed successfully, the value is nil.

  • error (NSError *error)

    If an error occurred, this error object describes the error. If the operation was completed successfully, the value is nil.

Returns: