我正在开发基于游戏中心的棋盘游戏。所有似乎都在运行,随处可见一些错误和怪癖。最令人讨厌的是,当观看已经结束的比赛时,似乎总是认为观看者已经输了。
当我结束与比赛获胜的比赛时,我运行:
// 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];
}
但是,我怀疑真正的问题在于我检索了matchOutcome。
当加载一个匹配时,如果它不是当前的玩家,则运行它:
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!";
}
答案 0 :(得分:0)
嗯,我只是通过真正解决问题来解决我自己的问题。
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!";
}