0

我在 Xcode 模拟器和我的 iPhone 上运行游戏。当我点击搜索时,它们都被放入单独的游戏中,而不是一个玩家加入现有的游戏。这是一款回合制游戏,玩家可以在 Game Center 自动运行时进行第一次回合。我正在使用两个单独的 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 回答