7

我有一个使用游戏中心和 GKTurnbasedMatch 的 2 人 iOS 回合制游戏。

有没有办法在比赛结束后以编程方式重新匹配对手?

我想让玩家一键式地开始彼此的新比赛。

如果没有一键式方法,有哪些潜在的替代方案?

4

2 回答 2

4

事实上,Game Center 似乎忽略了一个完整的程序化解决方案。痛苦,毫无疑问。在您的 @selector(doRematchTap)... 或等效项中尝试以下操作:

    NSMutableArray *playerIds = [NSMutableArray array];
    GKTurnBasedParticipant *otherPlayer = /* Get the other player some way */;
    GKTurnBasedParticipant *myParticipant = /* Get yourself a very similar way*/;

    [playerIds addObject:myParticipant.playerID];
    if (otherPlayer.playerID) {
        [playerIds addObject:otherPlayer.playerID];
    }// sanity check

    GKMatchRequest *request = [[GKMatchRequest alloc] init];
    request.playersToInvite = playerIds;
    request.minPlayers = 2;
    request.maxPlayers = 2;

    GKTurnBasedMatchmakerViewController *tbmcv = [[GKTurnBasedMatchmakerViewController alloc] initWithMatchRequest:request];
    tbmcv.showExistingMatches = NO;
    tbmcv.turnBasedMatchmakerDelegate = /* Your normal delegate for the callbacks */;

    [self presentViewController:tbmcv
                       animated:YES
                     completion:^{
                      }];

重要的是要注意 showExistingMatches = NO,这会将视图控制器直接跳转到匹配模式,并预先选择了正确的用户(看起来),而不是显示用户现有的匹配项。

于 2012-09-07T03:04:37.380 回答
1

我没有完整的解决方案,但给你一个想法:

每个玩家都有一个唯一的玩家 ID,如果你在

didReceiveData:(NSData *)data fromPlayer:(NSString *)playerID

现在您可以以编程方式开始新比赛并邀请该玩家。系统会询问他是否想要复赛,然后您可以再次比赛。

我知道这不是很多代码或具体建议,但也许它足以在GameKit 类参考中找到其余信息。

我想知道你是否可以解决它,告诉我你是否做到了,祝你好运!

编辑:

我在参考资料中搜索并发现了这一点:

- (void) loadPlayerData: (NSArray *) identifiers

我自己没有尝试过,但是如果你将他的标识符存储在一个数组中并将它传递给这个函数,你应该再次以这种方式获取玩家。

我希望他们在 iOS6 中为 Game Center 带来了一些变化,你可以以自己的方式以编程方式进行比赛......

于 2012-09-06T12:45:02.327 回答