Question

I have searched about everywhere and not found an anwer for this problem:

I have a 2 player game, turn based, via Game Center.

After a player has done his move, he has the ability in Game Center to quit the game. In my case, this automatically means the game has ended and the other player has won. However, I can not find a Game Centermethod to make this happen.

I can not use endMatchInTurnWithMatchData because it is not this players turn.

And if I try to use endMatchInTurnWithMatchData when it is the other player's turn, this isn't possible either, because there is no other player to send the endMatchInTurnWithMatchData to (because the other player already quit).

Is there anyone who knows the solution to this?

Thanks, Martyn

Was it helpful?

Solution

You have to implement turnBasedMatchmakerViewController:playerQuitForMatch: method of GKTurnBasedMatchmakerViewControllerDelegate. Here is an example code:

-(void)turnBasedMatchmakerViewController: (GKTurnBasedMatchmakerViewController *)viewController playerQuitForMatch:(GKTurnBasedMatch *)match {
    NSUInteger currentIndex = [match.participants indexOfObject:match.currentParticipant];
    GKTurnBasedParticipant *next = [match.participants objectAtIndex:(currentIndex + 1)%[match.participants count]];
    [match participantQuitInTurnWithOutcome:GKTurnBasedMatchOutcomeQuit nextParticipants:@[next] turnTimeout:MAXFLOAT matchData:match.matchData completionHandler:nil];
    [next setMatchOutcome:GKTurnBasedMatchOutcomeWon];
    [match endMatchInTurnWithMatchData:match.matchData completionHandler:nil];
}

OTHER TIPS

I was struggling with the same issue. What ended up working for me is to set yourself as the next participant when calling participantQuitInTurnWithOutcome.

Hope it helps!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top