我在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];
}
}
}
答案 0 :(得分:0)
您是否在开始/加入新测试的匹配项之前删除了在测试期间生成的部分填充参与者列表的旧匹配项?您可以从游戏中心应用程序手动删除旧匹配,或使用loadMatchesWithCompletionHandler
加载涉及本地玩家的回合制匹配,并为每场比赛创建一个匹配对象。在代码中的适当时间识别要删除的匹配项。请参阅Apple的文档,以确定正确离开,结束和删除匹配的步骤。