在iOS中使用JSON读取游戏级数据
我想使用JSON来存储有关我的游戏的数据,以便读入我的Objective-C代码 因此,我的TwinstonesBoardModel.m文件有以下方法(这是在游戏开始时为了设置棋盘上对象的位置而调用的第一个方法)。我不知道为什么,但为了清晰起见,我将对象初始化分为多个方法在iOS中使用JSON读取游戏级数据,ios,objective-c,json,Ios,Objective C,Json,我想使用JSON来存储有关我的游戏的数据,以便读入我的Objective-C代码 因此,我的TwinstonesBoardModel.m文件有以下方法(这是在游戏开始时为了设置棋盘上对象的位置而调用的第一个方法)。我不知道为什么,但为了清晰起见,我将对象初始化分为多个方法 // sets the board positions for the stones - (void)setToInitialStateMain { // clear board so
// sets the board positions for the stones
- (void)setToInitialStateMain
{
// clear board so each level-load is free of previous data
[super clearBoard];
// set the state of two stone objects and their positions
[super setCellState:BoardCellStateStoneOne forColumn:0 andRow:0];
[super setCellState:BoardCellStateStoneTwo forColumn:2 andRow:3];
}
- (void)setToInitialStateHorizontal
{
[super clearBoard];
[super setHBarCellState:HorizontalState forHBarCol:0 andHBarRow:1];
}
我有3个额外的方法用于类似的用途,比如上面,只是设置位置。我想做的是在JSON文件中提供100个级别的位置和状态,以便根据级别选择进行读取。因此,如果我选择level54,将调用上述函数,并应用JSON文件level54中的位置和状态
我国是:
typedef NS_ENUM(NSUInteger, BoardCellState) {
BoardCellStateEmpty = 0,
BoardCellStateStoneOne = 1,
BoardCellStateStoneTwo = 2,
BoardCellStateTarget = 3,
HorizontalState = 4,
HorizontalStateEmpty = 5,
GhostHorizontalState = 6,
VerticalState = 7,
VerticalStateEmpty = 8,
GhostVerticalState = 9,
IntersectorState = 10
};
我处理的是位置值0-4
我该怎么做呢?我对从外部文件中读取级别非常陌生。我可以为比赛的所有位置进行硬编码,但这会占用大量时间,而且效率肯定非常低 为什么不使用plist?Xcode和iOS中对plist文件有本机支持。是否有任何特定于级别数据访问的文档可供我参考?此外,仅根据我对这些setter方法的了解,我的思维方式(使用plist存储位置和状态值)有意义吗?能做到吗?谢谢