我正在制作一款游戏,但我无法尝试设置分数并将它们保存在表格中。我所做的是我已经做到了,我的游戏在每个级别的末尾运行一个方法来检查分数是否应该保存,但我不确定如何保存并对它们进行排序从最高到最低。如何在iPhone应用程序中保留用户分数?
这是我的表应包括:
- #:
- 名称:
- 得分:
- 时间:
按照这个顺序,我也对它进行了排序,只包含14行。
我在XIB上有一个带有图像的滚动视图,显示图表和顶部字段[#:,Name:,Score:,Time:]。我不知道如何显示字段的文本。
如果有人能向我解释,我将非常感谢,我将如何去做这个,并跟上排序和所有事情,以便在表格中显示它们。
这里是我到目前为止的代码,但它随时更改,所以随时纠正我在哪里,我错了,还是我提供不同的解决方案。
在此先感谢!
-(void) mGameScoreSelected {
if (![sGameScoresScore isEqualToString:@""]) {
sScoresRowCurrent = [NSString stringWithFormat:@"%i | %@ | %@ | %@", iGameScoresPlace,sGameScoresName, sGameScoresScore, sGameScoresTime];
kLog(@"%@", sScoresRowCurrent);
}
}
-(void) mGameScoreDetermine {
bGameScoreSetFinished = TRUE;
for (int x = 0; x <= 3*14; x++) {
if ([sGameScoresScore intValue] > [sScoresScores [x-1] intValue] && bGameScoreSetFinished == TRUE) {
[self mGameScoreSelected];
bGameScoreSetFinished = FALSE;
} else {
sGameScoresScore = @"";
sGameScoresTime = @"";
}
}
}
-(void) mGameScoreSet {
sGameScoresScore = [NSString stringWithFormat:@"%i", iGameScoreCurrent];
sGameScoresTime = [NSString stringWithFormat:@"%i", iGameTimeTotal - iGameTimeCurrent];
kLog(@"Score: %@", sGameScoresScore);
kLog(@"Time: %@", sGameScoresTime);
[self mGameScoreDetermine];
}
-(void) mGameEnded {
[self mGameScoreSet];
}
我会建议CoreData。不应该像这样使用'NSUserDefaults'。 – Legolas