Quote:
Originally Posted by phillipie99
Got the reset working
All you have to do is copy the new update score method just the last few line before the else are changed. Then add the to the Quiz game view controller.h file and finally add the reset method below to the Quiz game view controller.m file. There you go a working reset!!
Code:
-(void)updateScore
{
// If the score is being updated, the question is not live
questionLive = NO;
[timer invalidate];
// Hide the answers from the previous question
[answerOne setHidden:YES];
[answerTwo setHidden:YES];
[answerThree setHidden:YES];
[answerFour setHidden:YES];
NSString *scoreUpdate = [[NSString alloc] initWithFormat:@"Score: %d", myScore];
theScore.text = scoreUpdate;
[scoreUpdate release];
// END THE GAME.
NSInteger endOfQuiz = [theQuiz count];
if((((questionNumber - 1) * 6) + 6) == endOfQuiz)
{
// Game is over.
if(myScore > 0)
{
NSString *finishingStatement = [[NSString alloc] initWithFormat:@"That's game!\nNice going \nYou scored %i!", myScore];
theQuestion.text = finishingStatement;
[finishingStatement release];
}
else
{
NSString *finishingStatement = [[NSString alloc] initWithFormat:@"That's game!\nWow. You're terrible! \nYou scored %i.", myScore];
theQuestion.text = finishingStatement;
[finishingStatement release];
}
theLives.text = @"";
// Make button 1 appear as a reset game button
restartGame = YES;
[answerOne setHidden:NO];
[answerOne addTarget:self action:@selector(reset)forControlEvents:UIControlEventTouchDown];
[answerOne setTitle:@"Restart the game" forState:UIControlStateNormal];
}
else
{
// Give a short rest between questions
time = 3.0;
// Initialize the timer
timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(countDown) userInfo:nil repeats:YES];
}
}
// RESET METHOD
-(void)reset {
[self viewDidLoad];
}
|
Did not work for me. Could you please help?
(Quiz game view controller.h):
-(void)checkAnswer

int)theAnswerValue;
-(void)askQuestion;
-(void)updateScore;
-(void)loadLevelOne;
-(void)countDown;
-(void)reset;
@end
Quiz game view controller.m file:
-(void)updateScore
{
questionLive = NO;
[timer invalidate];
[answerOne setHidden:YES];
[answerTwo setHidden:YES];
[answerThree setHidden:YES];
[answerFour setHidden:YES];
NSString *scoreUpdate = [[NSString alloc] initWithFormat:@"%i", myScore];
theScore.text = scoreUpdate;
[scoreUpdate release];
// END THE GAME.
NSInteger endOfQuiz = [theQuiz count];
if((((questionNumber - 1) * 6) + 6) == endOfQuiz)
{
if(myScore > 0)
{
NSString *finishingStatement = [[NSString alloc] initWithFormat:@"You scored %i!", myScore];
theQuestion.textColor = [UIColor colorWithRed:0 green:0.2 blue:0 alpha:1.0];
theQuestion.text = finishingStatement;
[finishingStatement release];
}
else
{
NSString *finishingStatement = [[NSString alloc] initWithFormat:@"You scored %i.", myScore];
theQuestion.textColor = [UIColor redColor];
theQuestion.text = finishingStatement;
[finishingStatement release];
}
theLives.text = @"";
restartGame = YES;
[answerTwo setHidden:NO];
[answerTwo setTitle:@"Restart" forState:UIControlStateNormal];
}
else
{
time = 3.0;
timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(countDown) userInfo:nil repeats:YES];
}
}
// RESET METHOD
-(void)reset {
[self viewDidLoad];
}