![](/img/trans.png)
[英]Trouble with GKTurnBasedMatch endTurnWithNextParticipants:turnTimeout:matchData:completionHandler:
[英]GKTurnBasedMatch: Trouble Getting/Setting the matchOutcome
我正在開發基於Game Center的棋盤游戲。 似乎一切都在運行,並且到處都有一些錯誤和怪癖。 這些怪癖中最讓人討厭的是,當觀看一場比賽已經結束時,似乎總是認為觀看者已經輸了。
當我以獲勝的棋局結束比賽時,運行以下命令:
// 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!";
}
好吧,我只是通過實際布局解決了自己的問題。
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.