0

私はこれに関する情報を見つけるのに少し苦労しました、そして私が出くわすすべてのコードサンプルはすべてのプレーヤーのための引き分けで終わる試合に基づいています。2人のターン制のゲームでは、勝者と敗者で試合を終了できるようにしたいと考えています。私が書いた以下のコードでは、試合は常に両方のプレーヤーで同じ結果で終了します。勝った場合はプレーヤー1と2の両方が勝ち、負けた場合はプレーヤー1と2の両方が負けます...何か助けはありますか?ありがとうございました。

    if (gameOver == true) {
    if (GameWinner == 0) {
        GKTurnBasedParticipant *player0 = [currentMatch.participants objectAtIndex:0];
        player0.matchOutcome = GKTurnBasedMatchOutcomeWon;
        GKTurnBasedParticipant *player1 = [currentMatch.participants objectAtIndex:1];
        player1.matchOutcome = GKTurnBasedMatchOutcomeLost;

        [currentMatch endMatchInTurnWithMatchData:data completionHandler:^(NSError *error) {
            if (error) {
                NSLog(@"%@", error);
            }
        }];  
        testlabel.text = @"Player 1 Wins!";
    } else if (GameWinner == 1) {
        GKTurnBasedParticipant *player0 = [currentMatch.participants objectAtIndex:0];
        player0.matchOutcome = GKTurnBasedMatchOutcomeLost;
        GKTurnBasedParticipant *player1 = [currentMatch.participants objectAtIndex:1];
        player1.matchOutcome = GKTurnBasedMatchOutcomeWon;

        [currentMatch endMatchInTurnWithMatchData:data completionHandler:^(NSError *error) {
            if (error) {
                NSLog(@"%@", error);
            }
        }];
        testlabel.text = @"Player 2 Wins!";
    } else if (GameWinner == 2) {
        for (GKTurnBasedParticipant *part in currentMatch.participants) {
            part.matchOutcome = GKTurnBasedMatchOutcomeTied;
        }
        [currentMatch endMatchInTurnWithMatchData:data completionHandler:^(NSError *error) {
            if (error) {
                NSLog(@"%@", error);
            }
        }];
        testlabel.text = @"Tie Game!";
    } else {
        testlabel.text = @"Your turn is over.";
    }
4

1 に答える 1

1

これはこのSOの質問に似ているように聞こえます、試してみてください:

GKTurnBasedParticipant *curr = currentMatch.currentParticipant;
    NSUInteger currentIndex = [currentMatch.participants indexOfObject:currentMatch.currentParticipant];
    NSUInteger nextIndex = (currentIndex + 1) % [currentMatch.participants count];
    GKTurnBasedParticipant *next = [currentMatch.participants objectAtIndex:nextIndex];

    if (currScore < otherScore)
    {
        // Curr player lost
        curr.matchOutcome = GKTurnBasedMatchOutcomeLost;
        next.matchOutcome = GKTurnBasedMatchOutcomeWon;
    }
    else if (currScore == otherScore)
    {
        // Tied
        curr.matchOutcome = GKTurnBasedMatchOutcomeTied;
        next.matchOutcome = GKTurnBasedMatchOutcomeTied;
    }
    else 
    {
        // Won
        curr.matchOutcome = GKTurnBasedMatchOutcomeWon;
        next.matchOutcome = GKTurnBasedMatchOutcomeLost;
    }
于 2012-06-19T06:02:20.437 に答える