我正在为iPad做一个纸牌游戏(恐慌,紧张崩溃,压力)。为了赢得比赛,你需要有一套完整的4张匹配卡,我正在尝试获得一个IF语句,它将确保所有4张牌都是相等的。下面是我当前的代码:
if ([cards objectAtIndex:4] && [cards objectAtIndex:5] && [cards objectAtIndex:6] && [cards objectAtIndex:7] == [cards objectAtIndex:5]) {
//Deck one is good!
NSLog(@"P1D1, all clear");
}卡片是一个NSMuatableArray。如果我有一个2x2数组,数据为4:3:2:1
我只需要匹配插槽4和2中的卡,上面的语句就会返回true。
发布于 2012-04-24 02:08:27
尝试:
if([[cards objectAtIndex:4] isEqual:[cards objectAtIndex:5]] && [[cards objectAtIndex:6] isEqual:[cards objectAtIndex:5]] && [[cards objectAtIndex:7] isEqual:[cards objectAtIndex:5]]){
//Deck one is good!
NSLog(@"P1D1, all clear");
}希望这能有所帮助!
发布于 2012-04-24 02:15:34
或者,您可以这样做:
NSSet *distinctCardSet = [NSSet setWithArray:[cards subarrayWithRange:NSMakeRange(3, 4)]];
if (distinctCardSet.count == 1)
{
//Deck one is good!
NSLog(@"P1D1, all clear");
}https://stackoverflow.com/questions/10285772
复制相似问题