2013-05-10 23 views
2

我正在使用gamecenter編寫一個基於回合的iOS遊戲,並且遇到問題時發現目前所有人都坐在部分填充的遊戲中。我應該如何穿過我的比賽的參與者陣列並拉出坐着的球員?任何時候在遊戲中都會有[1,8]個玩家,而我正試圖用那些已經填滿的遊戲填充大廳。如何在iOS Gamecenter match.participants中查找填充席位?

+0

我不得不說,我不知道你爲什麼被否決/投票決定關閉。這個問題對我來說似乎很合理,可惜我沒有足夠的經驗來回答Gamecenter的回答。你可能想要添加一些示例代碼或其他東西。 – 2013-05-10 04:36:48

+0

謝謝。我不知道他們爲什麼會低估這一點。這真的令人沮喪。我似乎無法可靠地確定我的遊戲中究竟有誰。 – 2013-05-10 04:39:53

+0

@LoganShire請參閱編輯 – 2013-05-10 06:17:33

回答

1

編輯:

按照教程在這兩個環節上,你應該準備就緒..

Part 1 - Part 2

總之,每一個GKTurnBasedMatch對象都有一個NSArray屬性調用participants充滿GKTurnBasedMatchParticipant對象。您可以遍歷這個數組並查看遊戲中的每個參與者。查看status這些實例的屬性(類型GKTurnBasedParticipantStatus)以查看參與者是否被主動就坐或拒絕等是明智的。希望這有助於。

+0

OOOPS - 我剛剛重讀了您的問題,並認爲我回答了一個完全不同的問題 - 將在幾個小時內完成編輯 – 2013-05-10 05:10:15

2

這裏有兩個方便的方法我寫了一個「GKTurnBasedMatch」類別:

@implementation GKTurnBasedMatch (Convenience) 

- (NSArray *) remainingPlayingParticipants; 
{ 
    NSMutableArray *participants = [NSMutableArray array]; 

    // start searching at the current player 
    NSUInteger currentIndex = [self.participants indexOfObject:self.currentParticipant]; 

    for (int i = 0; i < [self.participants count]; i++) 
    { 
     GKTurnBasedParticipant *part = [self.participants objectAtIndex:(currentIndex + 1 + i) 
                     % self.participants.count]; 
     if (part.matchOutcome == GKTurnBasedMatchOutcomeNone) 
     { 
      [participants addObject:part]; 
     } 
    } 

    return [NSArray arrayWithArray:participants]; 
} 


- (NSArray *) remainingPlayingAndMatchedOpponents; 
{ 
    NSMutableArray *participants = [NSMutableArray array]; 
    GKTurnBasedParticipant *localParticipant = [self localParticipant]; 

    // start searching at the current player 
    NSUInteger currentIndex = [self.participants indexOfObject:self.currentParticipant]; 

    for (int i = 0; i < [self.participants count]; i++) 
    { 
     GKTurnBasedParticipant *part = [self.participants objectAtIndex:(currentIndex + 1 + i) 
             % self.participants.count]; 
     if (part.matchOutcome == GKTurnBasedMatchOutcomeNone 
      && part.status == GKTurnBasedParticipantStatusActive 
      && part != localParticipant) 
     { 
      [participants addObject:part]; 
     } 
    } 

    return [NSArray arrayWithArray:participants]; 
} 
@end