我正在我的游戏中编写撤消选项。这个游戏是一个简单的三消游戏,每个单元格都包含一个球,可以是 1-4 种颜色,所以我的想法是保存整个整数网格,我将它们全部放入 NSMutableArray 中,像这样...
NSMutableArray *currentGrid = [[NSMutableArray alloc] init];
for (int i=0; i<(mapWidth*(mapHeight*2)); i++)
{
[currentGrid addObject:[NSNumber numberWithInt:0]];
}
for (int iy=(mapHeight*2)-1; iy>=0; iy--)
{
for (int ix=mapWidth-1; ix>=0; ix--)
{
int index = (iy*mapWidth)+ix;
Ball *ball = [self valueAtRowWithArray:tilesArray andColumn:ix andRow:iy];
[currentGrid setObject:[NSNumber numberWithInt:ball.ballType] atIndexedSubscript:index];
}
}
[levelStateArray addObject:currentGrid];
这很好,但我想知道有更好/更有效的方法来做到这一点。我对序列化一无所知,但我想知道是否可以以某种方式使用它来保存数组?