2012-12-11 37 views
1

如何識別多人遊戲是由自動匹配還是邀請朋友發起?如何識別多人遊戲由自動匹配開始

當比賽開始我有這個方法叫:

- (void)matchmakerViewController:(GKMatchmakerViewController *)viewController didFindMatch:(GKMatch *)theMatch { 

    [presentingViewController dismissModalViewControllerAnimated:YES]; 
    self.match = theMatch; 
    match.delegate = self; 
    if (!matchStarted && match.expectedPlayerCount == 0) { 
     NSLog(@"Ready to start match!"); 
     [self lookupPlayers]; 
    } 
} 

基本上我想這(請查看此鏈接) - how to sync data in multiplayer game(game-center ios)

+1

請檢查這個答案的評論,使用時間戳似乎是在「自動匹配」中選擇主機的最合理的解決方案:http://stackoverflow.com/a/12741018/792677如果我只需要選擇地圖你引用的問題,我寧願把它作爲AV OTE。 –

+0

如果需要,請隨時發佈答案或更新問題。 –

回答

2

我檢查,如果本土球員的playerID包含在比賽的參賽者名單。我發現如果他們被邀請或自動匹配,他們不會被列出。我相信這是因爲他們還沒有接受比賽。

+ (BOOL) isLocalPlayerActiveParticipantInMatch:(GKTurnBasedMatch *)aMatch 
{ 
    for (GKTurnBasedParticipant *participant in aMatch.participants) 
    { 
     if ([participant.playerID isEqualToString:[GKLocalPlayer localPlayer].playerID]) 
      return YES; 
    } 

    return NO; 
} 

如果付款人決定打比賽,我稱之爲的比賽:

GKTurnBasedMatch acceptInviteWithCompletionHandler 

如果他們拒絕,我稱此爲比賽:

GKTurnBasedMatch declineInviteWithCompletionHandler