Reputation: 881
I am completely new to game center ,I have already managed to invite friends and managed turns on button's IBAction.
I am using GKTurnbasedMatch for managing the turns but for multiplayer how to show the cards to all player whose category is selected by the player who is inviting.
How would i get this ?
Upvotes: 3
Views: 192
Reputation: 7541
Here is a great tutorial on Gamecenter / turn based:
http://www.raywenderlich.com/5509/beginning-turn-based-gaming-with-ios-5-part-2
specifcly this part:
If we find that lastTurn is null, we’ll assume that we’re dealing with a new match, otherwise we’ll assume that we already have matchData that we’ll be dealing with. So open up GCTurnBasedMatchHelper.m and replace the didFindMatch method as follows:
-(void)turnBasedMatchmakerViewController:
(GKTurnBasedMatchmakerViewController *)viewController
didFindMatch:(GKTurnBasedMatch *)match {
[presentingViewController
dismissModalViewControllerAnimated:YES];
self.currentMatch = match;
GKTurnBasedParticipant *firstParticipant =
[match.participants objectAtIndex:0];
if (firstParticipant.lastTurnDate) {
NSLog(@"existing Match");
} else {
NSLog(@"new Match");
}
}
What you want to do, is send all the data to all players each turn, so when the player is first going (and dealing) they should send the hands to all the players. When they are not dealing, you do not have to send all the data, so instead you can send a different type of message. To send information:
BOOL success = [[GameCenterManager sharedInstance].Match sendDataToAllPlayers:data withDataMode:GKMatchSendDataReliable error:&error];
Just make sure that the data has a type, this is usually the first byte of the message, then on the client side, read the first byte to determine what type of message it is, then use a switch statement or whatever you like to deal with the different types of messages.
Upvotes: 2