3

私はゲーム センターを使用してターン ベースの iOS ゲームに取り組んでおり、現在、テスト アカウントでゲーム センターの 6 つのゲームに参加していますが、スワイプして 1 つを終了しようとするたびに (実際にはゲームが終了するはずです。 test アカウントはその中の唯一のものです) テーブルからゲームを一瞬削除し、すぐに置き換えて終了しません。

これが私の playerQuitForMatch 関数です:

// Handle players leaving the match in and out of turn.
- (void)turnBasedMatchmakerViewController:(GKTurnBasedMatchmakerViewController *)viewController
                      playerQuitForMatch:(GKTurnBasedMatch *)match
{
    // If the player was the current participant, remove them from the next participants array.
    if ([match.currentParticipant.playerID isEqualToString:GKLocalPlayer.localPlayer.playerID])
    {
        NSMutableArray* nextParticipants = [NSMutableArray arrayWithArray:[match participants]];
        [nextParticipants removeObjectIdenticalTo:[match currentParticipant]];

        // If they were the last player, end the match because it is empty.
        if ([nextParticipants count] == 0)
        {
            [match endMatchInTurnWithMatchData:match.matchData completionHandler:nil];
        }
        // Otherwise, remove them from the match and pass priority.
        else
        {
            [match participantQuitInTurnWithOutcome:GKTurnBasedMatchOutcomeQuit
                                   nextParticipants:nextParticipants
                                        turnTimeout:0.0f
                                          matchData:match.matchData
                                  completionHandler:nil];
        }
    }
    // If they weren't the current participant, just remove them from the match.
    else
    {
        NSMutableArray* nextParticipants = [NSMutableArray arrayWithArray:[match participants]];
        [nextParticipants removeObjectIdenticalTo:[match currentParticipant]];

        // The player can't be the last person in the game if they aren't the active player.
        [match participantQuitOutOfTurnWithOutcome:GKTurnBasedMatchOutcomeQuit withCompletionHandler:nil];
    }

    NSLog(@"playerquitforMatch, %@, %@", match, match.currentParticipant);
}

コンソール出力は次のとおりです。

2013-05-04 13:16:13.180 XYZ Mobile[7799:c07] Authenticating local user...
2013-05-04 13:16:13.587 XYZ Mobile[7799:c07] Authentication changed: player authenticated.
May  4 13:16:13 folsom-wireless-153.dynamic2.rpi.edu XYZ Mobile[7799] <Info>: 13:16:13.597120 com.apple.AVConference: GKSConnSettings: set server: {
        "gk-cdx" = "17.173.254.218:4398";
        "gk-commnat-cohort" = "17.173.254.220:16386";
        "gk-commnat-main0" = "17.173.254.219:16384";
        "gk-commnat-main1" = "17.173.254.219:16385";
    }
2013-05-04 13:16:21.380 XYZ Mobile[7799:c07] 101
2013-05-04 13:16:58.150 XYZ Mobile[7799:c07] New Game Button Pressed
2013-05-04 13:17:00.146 XYZ Mobile[7799:c07] playerquitforMatch, <GKTurnBasedMatch 0x949ece0    id:0a8b8246-1872-410e-b9ae-819a9a00d4ff status:Open message:(null) taken:(null) created:2013-04-24 23:32:35 +0000
current:<GKTurnBasedParticipant 0x949ad50 - id:(null) status:Matching outcome:None lastTurn:(null)>
participants:
        <GKTurnBasedParticipant 0x949ad40 - id:G:1759434517 (local player) status:Done outcome:Quit lastTurn:(null)>
        <GKTurnBasedParticipant 0x949ad50 - id:(null) status:Matching outcome:None lastTurn:(null)>
        <GKTurnBasedParticipant 0x949f2b0 - id:(null) status:Matching outcome:None lastTurn:(null)>
        <GKTurnBasedParticipant 0x949f2c0 - id:(null) status:Matching outcome:None lastTurn:(null)>
        <GKTurnBasedParticipant 0x949f650 - id:(null) status:Matching outcome:None lastTurn:(null)>
        <GKTurnBasedParticipant 0x949f660 - id:(null) status:Matching outcome:None lastTurn:(null)>
        <GKTurnBasedParticipant 0x949bc20 - id:(null) status:Matching outcome:None lastTurn:(null)>
        <GKTurnBasedParticipant 0x949bc30 - id:(null) status:Matching outcome:None lastTurn:(null)>
    >, <GKTurnBasedParticipant 0x949ad50 - id:(null) status:Matching outcome:None lastTurn:(null)>
2013-05-04 13:17:08.523 XYZ Mobile[7799:c07] has cancelled
4

2 に答える 2

0

上記の回答 1 のヒントに感謝します。2 人のプレーヤーの試合の開始者が自分の番になる前に終了したが、プレーヤー 2 が試合を終了したプレーヤーを受け取ったときに、同様の問題が発生しました。「ターン機能」で次のことを行い、プレイヤー 2 がゲーム センター ビューからマッチを削除できるようにしました。多くのコードが投稿されていますが、重要なことは次のとおりです。

1-現在情報が不足している可能性があるため、ゲームセンターにデータを送信します。

2-プログラムですべてのプレイヤーをマッチから終了

プログラムで試合を 3 エンドにする

4-プログラムでゲーム センターから試合を削除します。

//CHECKING IF PLAYER HAS QUIT.

NSUInteger currentIndex = [match.participants indexOfObject:match.currentParticipant];

//find the next participant in the match
GKTurnBasedParticipant *nextParticipant;

//Note if player 1's turn result is (0+1) % 2 = 0 remainder 1, therefore nextIndex = 1 (i.e. player 2 on a zero based index)
//Note if player 2's turn result is (1+1) % 2 = 1 remainder 0, therefore nextIndex = 0 (i.e. player 1 on a zero based index)

NSUInteger nextIndex = (currentIndex + 1) % [match.participants count];

nextParticipant = [match.participants objectAtIndex:nextIndex];

//check to see if any of the participants has quit.
for (int i = 0; i < [match.participants count]; i++)
{
    nextParticipant = [match.participants objectAtIndex:((currentIndex + 1 + i) % [match.participants count ])];

    if (nextParticipant.matchOutcome != GKTurnBasedMatchOutcomeQuit)
    {
        NSLog(@"Player %@ has not quit", nextParticipant);
        break;
    }
    else
    {
        NSLog(@"Next participant %@ has quit", nextParticipant);

        //because the initiator has quit before playing, player "2 i.e current player index 1" should send dummy data to game centre
        //to allow them to delete this from their game centre view otherwise the match cannot be deleted from their game centre
        if(currentIndex == 1)
        {

             //send dummy data as is no turn has been taken. This allows the functions below to be carried out.
            [self CallToSendPlayerTurnData];

            for (GKTurnBasedParticipant *part in match.participants)
            {
                 part.matchOutcome = GKTurnBasedMatchOutcomeQuit;
            }

            //then end the match
            [match endMatchInTurnWithMatchData:match.matchData completionHandler:^(NSError *error)
             {
                 if (error)
                 {
                     NSLog(@"Erro ending quit match %@", error.localizedDescription);
                     {

                     }
                 }
              }
             ];

          //then remove the match programatically otherwise players GC viewer cannnot do this.
            NSLog(@"%@", match.matchID);
            [match removeWithCompletionHandler:^(NSError *error)
             {
                 NSLog(@"%@", error.localizedDescription);
             }
             ];

            //disable player buttons
            [self disablePlayerButtons ];

            //stop timing either player.
            self.playerTimerTurn = 0;

            self.playerturn = 3; //when player has quit

            [statusLabel setString:[NSString stringWithFormat:@"Sorry, the intiator quit the match so it will now be deleted."]];


        }
        else
        {

            //disable player buttons
            [self disablePlayerButtons ];

            //stop timing either player.
            self.playerTimerTurn = 0;

            self.playerturn = 3; //when player has quit

            [statusLabel setString:[NSString stringWithFormat:@"Sorry, a player has quit the match so it cannot be progressed."]];

        }


        return;
    }
}
///IF PLAYER HAS QUIT EXIT MATCH ELSE CONTINUE BELOW
于 2013-06-02T19:09:05.380 に答える