所以我正在制作游戏,我正在尝试实例化一个组合系统。我随机创建带有移动的数组,然后检查用户是否移动匹配它们。唯一的问题是[array1 isEqualToArray:array2]即使它们相同也不会返回true。这是日志和代码:
日志:
2014-02-14 16:43:18.689 FlickTheBean[4878:60b] Combos: (
(
6,
2,
1,
1
),
(
8,
5,
2,
8
),
(
5,
2,
2,
1
),
(
8,
2,
8,
5
),
(
4,
4,
1,
1
)
)
2014-02-14 16:43:48.046 FlickTheBean[4878:60b] Check Combo: (
6,
2,
1,
1
)
2014-02-14 16:43:48.048 FlickTheBean[4878:60b] User Move: (
4,
4,
1,
1
)
2014-02-14 16:43:48.051 FlickTheBean[4878:60b] no match
2014-02-14 16:43:48.052 FlickTheBean[4878:60b] Check Combo: (
8,
5,
2,
8
)
2014-02-14 16:43:48.054 FlickTheBean[4878:60b] User Move: (
4,
4,
1,
1
)
2014-02-14 16:43:48.055 FlickTheBean[4878:60b] no match
2014-02-14 16:43:48.057 FlickTheBean[4878:60b] Check Combo: (
5,
2,
2,
1
)
2014-02-14 16:43:48.058 FlickTheBean[4878:60b] User Move: (
4,
4,
1,
1
)
2014-02-14 16:43:48.060 FlickTheBean[4878:60b] no match
2014-02-14 16:43:48.061 FlickTheBean[4878:60b] Check Combo: (
8,
2,
8,
5
)
2014-02-14 16:43:48.064 FlickTheBean[4878:60b] User Move: (
4,
4,
1,
1
)
2014-02-14 16:43:48.065 FlickTheBean[4878:60b] no match
2014-02-14 16:43:48.067 FlickTheBean[4878:60b] Check Combo: (
4,
4,
1,
1
)
2014-02-14 16:43:48.069 FlickTheBean[4878:60b] User Move: (
4,
4,
1,
1
)
2014-02-14 16:43:48.070 FlickTheBean[4878:60b] no match
比较代码:
if([self.possibleCombo count] == IS_COMBO_LENGTH){
for (NSArray *checkCombo in self.combos){
NSLog(@"Check Combo: %@", checkCombo);
NSLog(@"User Move: %@", self.possibleCombo);
if([self.possibleCombo isEqualToArray:checkCombo]){
NSLog(@"match");
multiplier *= 2;
} else {
NSLog(@"no match");
multiplier = 1;
}
}
[self.possibleCombo removeAllObjects];
}