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 に答える