首页 文章

没有找到游戏中心的玩家 . 我测试我的游戏错了吗?

提问于
浏览
0

我让游戏在Xcode模拟器和我的iPhone上运行 . 当我点击搜索时,它们都被放入单独的游戏中,而不是一个玩家加入现有游戏 . 这是一个回合制游戏,玩家可以在游戏中心自动匹配时进行第一次转弯 . 我正在使用两个单独的Game Center帐户和Sandbox设置 . 知道我可能做错了吗?对于那些开发了游戏中心支持的游戏的人来说,你是如何测试它的?谢谢您的帮助!

一些代码:

- (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];
    }
    }
}

1 回答

  • 0

    您是否在开始/加入新测试的匹配之前删除了在测试期间生成的部分填充的参与者列表的旧匹配?您可以从游戏中心应用程序中手动删除旧匹配项,或在代码中的适当时间使用 loadMatchesWithCompletionHandler "loads the turn-based matches involving the local player and creates a match object for each match"来识别要删除的匹配项 . 请参阅Apple的文档以确定正确保留,结束和删除匹配的步骤 .

相关问题