[英]GKTurnBasedMatch: Trouble Getting/Setting the matchOutcome
I am working on a Game Center based board game. 我正在开发基于Game Center的棋盘游戏。 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. 但是,我怀疑真正的问题出在我对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. 好吧,我只是通过实际布局解决了自己的问题。
if ([((GKTurnBasedParticipant*)[match.participants objectAtIndex:0]).playerID isEqualToString:[GKLocalPlayer localPlayer].playerID]) {
if ([board playerHasWon:1]) statusLabel.text = @"You won!";
else statusLabel.text = @"You lost!";
}
else {
if ([board playerHasWon:2]) statusLabel.text = @"You won!";
else statusLabel.text = @"You lost!";
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.