I am working on a Game Center based board game. All seems to be running grew with a few bugs and quirks here and there. The most annoying of those quirks is that when viewing a match that has ended, it always seems to think that the viewing player has lost.
When I end a match with a game winning move, I run this:
// Act if the game is over because of that move
if ([board playerHasWon:activePlayer]) {
board.canMove = NO;
match = [CNFTurnBasedMatchHelper sharedInstance].currentMatch;
NSUInteger currentIndex = [match.participants indexOfObject:match.currentParticipant];
NSUInteger nextIndex = (currentIndex == 0 ? 1 : 0);
GKTurnBasedParticipant *nextParticipant = [match.participants objectAtIndex:nextIndex];
match.currentParticipant.matchOutcome = GKTurnBasedMatchOutcomeWon;
nextParticipant.matchOutcome = GKTurnBasedMatchOutcomeLost;
[match endMatchInTurnWithMatchData:[[board stringValue] dataUsingEncoding:NSUTF8StringEncoding] completionHandler:nil];
}
However, I suspect the real problem lies in my retrieval of that matchOutcome.
When loading a match I run this if the it’s not the current players turn:
if (match.status == GKTurnBasedMatchStatusEnded) {
// These lines get the board to show the winning line
[board playerHasWon:1];
[board playerHasWon:2];
board.canMove = NO;
if (match.currentParticipant.matchOutcome == GKTurnBasedMatchOutcomeWon) statusLabel.text = @"You won!";
else statusLabel.text = @"You lost!";
}
Well, I solved my own problem just by really laying it out.