2012-10-06 52 views
0

我正在開發基於Game Center的棋盤遊戲。所有似乎都在運行,隨着一些錯誤和怪癖在這裏和那裏增長。這些怪癖中最令人討厭的是,當觀看已經結束的比賽時,似乎總是認爲觀看球員已經輸了。GKTurnBasedMatch:問題獲取/設置matchOutcome

當我結束了連勝的舉動一場比賽,我運行此:

// 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

嗯,我解決我自己的問題只是真的鋪設出來。

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!"; 
}