0

我正在开发基于游戏中心的棋盘游戏。一切似乎都在运行,到处都有一些错误和怪癖。这些怪癖中最令人讨厌的是,在观看已结束的比赛时,似乎总是认为观看的玩家输了。

当我以赢得比赛的举动结束比赛时,我运行以下命令:

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

1 回答 1

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!";
}
于 2012-10-06T17:33:11.497 回答