Actually, the "next level" display is brought up when this occurs, so it's a perfect place to advance the start and end quiz numbers.
So, on the NextLevelViewController, I'll call a new utils method;
[Utils incrementQuizRange];
Here are the utils methods:
+ (void) incrementQuizRange {
NSInteger startNum = [Utils getStartNum];
NSInteger endNum = [Utils getEndNum];
NSInteger diff = endNum - startNum;
startNum = endNum + 1;
endNum = endNum + diff + 1;
[Utils setStartNum: startNum];
[Utils setEndNum: endNum];
}
+ (void) setJlptLevel:(NSInteger)jlptLevel
{
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
[prefs setInteger:jlptLevel forKey:@"jlptLevel"];
[prefs synchronize];
}
+ (void) setStartNum:(NSInteger) startNum
{
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
[prefs setInteger:startNum forKey:@"startNum"];
[prefs synchronize];
}
+ (void) setEndNum:(NSInteger) endNum
{
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
[prefs setInteger:endNum forKey:@"endNum"];
[prefs synchronize];
}
- (IBAction)openQuestionController
{
NSLog(@"openQuestionController");
// todo - check how state was orignally saved
// reset index of shuffled array to zero
appState.shuffledArrayIndex = 0;
NSInteger startNum = [Utils getStartNum];
NSInteger endNum = [Utils getEndNum];
// create an array of keys to the list of question
// this will only contain keys starting from start num and a
// ending with end number
NSMutableArray* questionDictKeys = [NSMutableArray array];
// loop from start number to end number
for (int i = startNum; i <= endNum; i++){
// convert the integer to an object
NSNumber *myKey = [NSNumber numberWithInt:i];
// add the number to the list of keys
[questionDictKeys addObject:myKey];
}
// shuffle the list of keys and put them
// into the app state list of shuffled keys
appState.shuffledQuestionDictKeyList = [questionDictKeys shuffledArray];
// print the keys for debugging
for (int i = 0; i < [appState.shuffledQuestionDictKeyList count]; i++){
NSLog(@"shuffledQuestionDictKeyList[i]: %d", [[appState.shuffledQuestionDictKeyList objectAtIndex: i] intValue]);
}
// reset correct answers to zero
appState.correctAnswers = 0;
// send control to the question controller
questionController = [[QuestionController alloc] init];
[self.navigationController pushViewController:questionController animated:YES];
[questionController release];
}
Actually, the debugger is showing the end number as 2, when it should be like 205 or something. What happened?
Oh. Here's what I meant to do in the end quiz number calculation:
endNum = endNum + diff + 1;
Ok, now let's try it.
Ok, one more thing - we've got to fix the bad data. We can do that with the settings display.
And, voila - that part is complete.
No comments:
Post a Comment