如何在iOS Game Center TURN-Based App中排除丢失的玩家

时间:2012-06-28 14:19:22

标签: ios game-center

我在iOS游戏中心创建了一个回合制游戏, 游戏运行良好,数据从玩家传递到玩家。

我想知道:

你怎么能排除一个在另一个之前输了的球员呢?

我找不到任何参考 我该怎么办?

提前致谢并抱歉我的英文

安吉洛

编辑:

好的,我尝试了这个并且它有效(被排除的玩家也可以查看匹配)

    //When current player is excluded

GKTurnBasedMatch *currentMatch = [[GCTurnBasedMatchHelper sharedInstance] currentMatch];
currentMatch.currentParticipant.matchOutcome == GKTurnBasedMatchOutcomeQuit




//FOR SEND TURN : 

    NSUInteger currentIndex = [currentMatch.participants indexOfObject:currentMatch.currentParticipant];

    GKTurnBasedParticipant *nextParticipant;

    NSUInteger nextIndex = (currentIndex + 1) % [currentMatch.participants count];

    nextParticipant = [currentMatch.participants objectAtIndex:nextIndex];

    for (int i = 0; i < [currentMatch.participants count]; i++) {

        nextParticipant = [currentMatch.participants objectAtIndex:((currentIndex + 1 + i) % [currentMatch.participants count ])];

        if (nextParticipant.matchOutcome != GKTurnBasedMatchOutcomeQuit) {
            ///prossimo giocatore che NON è stato escluso
            break;
        } else {
            /////Prossimo giocatore perché questo è stato escluso
        }
    }



 [currentMatch endTurnWithNextParticipant:nextParticipant matchData:data completionHandler:^(NSError *error) {

            […]

        }];

1 个答案:

答案 0 :(得分:1)

我不是游戏中心的专家,​​但是从内存来看,您的代码可以选择下一个转弯的人。因此,您可以计算下一个转弯的对象,并简单地跳过已经输掉的任何球员。您可能应该更新他们的游戏数据,以便他们可以跟随游戏到最后。

Ray Wenderlich有几个关于Game Center回合制游戏的示例教程:Beginning turn-based gaming with iOS 5

没有要分享的示例代码 - 抱歉。