【问题标题】:Display same cards to all players using Game center使用游戏中心向所有玩家显示相同的卡片
【发布时间】:2012-12-01 14:15:44
【问题描述】:

我是游戏中心的新手,我已经设法邀请朋友并成功打开按钮的IBAction。

我使用 GKTurnbasedMatch 来管理回合,但对于多人游戏,如何向邀请的玩家选择类别的所有玩家显示卡片。

我怎么会得到这个?

【问题讨论】:

    标签: iphone objective-c ios xcode game-center


    【解决方案1】:

    这是关于 Gamecenter / 回合制的精彩教程:

    http://www.raywenderlich.com/5509/beginning-turn-based-gaming-with-ios-5-part-2

    特别是这部分:

    如果我们发现 lastTurn 为空,我们会假设我们正在处理 一个新的匹配,否则我们会假设我们已经有了 matchData 我们将要处理的。所以打开 GCTurnBasedMatchHelper.m 和 替换 didFindMatch 方法如下:

    -(void)turnBasedMatchmakerViewController: 
      (GKTurnBasedMatchmakerViewController *)viewController 
      didFindMatch:(GKTurnBasedMatch *)match {
        [presentingViewController 
          dismissModalViewControllerAnimated:YES];
        self.currentMatch = match;
        GKTurnBasedParticipant *firstParticipant = 
          [match.participants objectAtIndex:0];
        if (firstParticipant.lastTurnDate) {
            NSLog(@"existing Match");
        } else {
            NSLog(@"new Match");
        }
    }
    

    您想要做的是每回合将所有数据发送给所有玩家,因此当玩家第一次去(和发牌)时,他们应该将手牌发送给所有玩家。当他们不交易时,您不必发送所有数据,因此您可以发送不同类型的消息。发送信息:

    BOOL success = [[GameCenterManager sharedInstance].Match sendDataToAllPlayers:data  withDataMode:GKMatchSendDataReliable error:&error];
    

    只要确保数据有一个类型,这通常是消息的第一个字节,然后在客户端,读取第一个字节以确定它是什么类型的消息,然后使用 switch 语句或任何你想要的喜欢处理不同类型的消息。

    【讨论】:

    • 非常感谢,但我想要的是我必须选择一个类别,然后邀请或玩游戏。在下一个视图中,我现在有 10 张基于该类别的卡片,我如何为所有玩该游戏的玩家获得相同的卡片。你能帮我解决这个问题吗
    • 还有另一个链接来帮忙:stackoverflow.com/questions/12104041/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多