0

Xcode シミュレーターと iPhone でゲームを実行しています。検索を押すと、1 人のプレーヤーが既存のゲームに参加するのではなく、両方とも別々のゲームに入れられます。これはターン制のゲームで、Game Center が自動対戦している間にプレイヤーは最初のターンを行うことができます。サンドボックス設定をオンにして、2 つの別々の Game Center アカウントを使用しています。私が間違っているかもしれないことは何ですか?Game Center 対応のゲームを開発したことがある方へ、どのようにテストしましたか? 助けてくれてありがとう!

いくつかのコード:

- (void)findMatchWithMinPlayers:(int)minPlayers maxPlayers:(int)maxPlayers // view controller calls to find match - nothing if GC unavaiable
             viewController:(UIViewController *)viewController {


if (!_enableGameCenter) return;


_matchStarted = NO; // Match not started yet
self.currentMatch = nil;
[viewController dismissViewControllerAnimated:NO completion:nil];

GKMatchRequest *request = [[GKMatchRequest alloc] init]; // Set number of players
request.minPlayers = minPlayers;
request.maxPlayers = maxPlayers;

GKTurnBasedMatchmakerViewController *mmvc = // new instance of the GKMatchmakerViewController with the given request, sets its delegate to the GameKitHelper object, and uses the passed-in view controller to show it on the screen. Shows the user to search for a random player and start a game.
[[GKTurnBasedMatchmakerViewController alloc] initWithMatchRequest:request];
mmvc.turnBasedMatchmakerDelegate = self;

[viewController presentViewController:mmvc animated:YES completion:nil];
}

#pragma mark GKTurnBasedMatchmakerViewControllerDelegate

// A peer-to-peer match has been found, the game should start
- (void)turnBasedMatchmakerViewController:(GKTurnBasedMatchmakerViewController *)viewController didFindMatch:(GKTurnBasedMatch *)match {
[viewController dismissViewControllerAnimated:YES completion:nil];
self.currentMatch = match;
GKTurnBasedParticipant *firstParticipant = [match.participants objectAtIndex:0];
if (firstParticipant.lastTurnDate == NULL) {
    // It's a new game!
    [delegate enterNewGame:match];
} else {
    if ([match.currentParticipant.player isEqual:[GKLocalPlayer localPlayer].playerID]) {
        // It's your turn!
        [delegate takeTurn:match];
    } else {
        // It's not your turn, just display the game state.
        [delegate layoutMatch:match];
    }
    }
}
4

1 に答える 1

0

新しいテストの試合を開始/参加する前に、テスト中に生成された部分的に入力された参加者リストで古い試合を削除していますか? ゲーム センター アプリから古いマッチを手動で削除するかloadMatchesWithCompletionHandler、コード内の適切なタイミングで「ローカル プレイヤーが関与するターンベースのマッチをロードし、各マッチのマッチ オブジェクトを作成する」を使用して、削除するマッチを特定することができます。一致を適切に終了、終了、削除する手順については、Apple のドキュメントを参照してください。

于 2015-07-21T11:53:29.527 に答える