我创建了一个问答游戏。这是我的代码的一部分:
- (void) viewDidLoad
{
logos = [[NSMutableArray alloc] init];
[logos addObject:@"adidas"];
[logos addObject:@"nike"];
[logos addObject:@"puma"];
[self showLogo];
}
int currentQuestionIndex;
- (void) showLogo
{
currentQuestionIndex++;
NSString *question = [logos objectAtIndex:currentQuestionIndex];
[_questionImage setImage:[UIImage imageNamed:question]];
...
}
如果用户选择了正确的答案,“showLogo”将被再次调用到下一个问题。至此,Level 完成。
一切都很好。
请帮我保存信息/关卡。如果关卡完成,当用户启动游戏时,他必须从保存的关卡开始。
这是我已经尝试过的:
- (void) checkAnswer
{
///... if user answered right
[[NSUserDefaults standardUserDefaults] setInteger:currentQuestionIndex forKey:@"currentLevel"];
[self showLogo];
/// so, I tried to save "currentQuestionIndex" forKey currentLevel, and call "showLogo"
}
这里是修改的“showLogo”
- (void) showLogo
{
int savedLevel = [[NSUserDefaults standardUserDefaults] integerForKey:@"currentLevel"];
currentQuestionIndex = savedLevel+1 ;
NSString *question = [logos objectAtIndex:currentQuestionIndex];
[_questionImage setImage:[UIImage imageNamed:question]];
...
}
但不起作用..使用这种方法,我试图保存分数,它也有效..
请帮忙。谢谢