我正在使用 gamecenter 编写一个基于回合的 iOS 游戏,并且在找到当前坐在部分填充游戏中的每个人时遇到问题。我应该如何穿过我的比赛的参与者阵列并拉出坐着的球员?任何时候游戏中都会有 [1,8] 名玩家,我正在尝试用那些被填满的人填充大厅。
问问题
162 次
2 回答
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
于 2013-05-10T10:47:40.940 回答