クイズゲームを作っています。ここに私のコードの一部があります:
- (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」が再度呼び出されます。ということで、レベル完成です。
すべてがうまく機能します。
情報/レベルを保存するのを手伝ってください。IF レベルが完了すると、ユーザーがゲームを起動するときに、保存されたレベルから開始する必要があります。
これは私がすでに試したことです:
- (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]];
...
}
しかし、機能しません..この方法を使用して、スコアを保存しようとしましたが、それも機能します..
助けてください。ありがとう