Thanks for the help, again. First the code
NSInteger endOfQuiz = [theQuiz count]; <-- Here i get this warning: Unused variable 'endOfQuiz'
if (answerCount >= 30)
{
answerCount =0;
{
Otherwise it works great, if i put the >=30 it stops at 15, and if i put the <=4 it stops at 2. So i don't think it runs properly but i got it working. if you want it to stop after 10 questions make the >= 20.
Going to look at the link now
Here is my .m file
@implementation FodboldQuizSuperligaViewController
- (void)viewDidLoad {
questionLive = NO;
restartGame = NO;
theQuestion.text = @"Er du klar, til den ultimative Quiz?";
theScore.text = @"Score:0";
theLives.text = @"";
questionNumber = 0;
myScore = 0;
myLives = 0;
[answerOne setTitle:@"Lad os gå igang" forState:UIControlStateNormal];
[answerTwo setHidden:YES];
[answerThree setHidden:YES];
[answerFour setHidden:YES];
[appstore setHidden:NO];
[appstorelabel setHidden:NO];
[self loadQuiz];
[super viewDidLoad];
[showachievements setHidden:YES];
[ShowLeader setHidden:NO];
[submitScore setHidden:YES];
[sendsms setHidden:YES];
counter=0;
count.text = @"0/15";
answerCount=0;
self.currentLeaderBoard= kEasyLeaderboardID;
if ([GameCenterManager isGameCenterAvailable]) {
self.gameCenterManager= [[[GameCenterManager alloc] init] autorelease];
[self.gameCenterManager setDelegate: self];
[self.gameCenterManager authenticateLocalUser];
}
}
-(void)askQuestion
{
// Unhide all the answer buttons.
[answerOne setHidden:NO];
[answerTwo setHidden:NO];
[answerThree setHidden:NO];
[answerFour setHidden:NO];
[appstore setHidden:YES];
[appstorelabel setHidden:YES];
[sendsms setHidden:YES];
[ShowLeader setHidden:YES];
[animation setHidden:YES];
[animationsmiley setHidden:YES];
[count setHidden:NO];
counter=counter + 1;
count.text = [NSString stringWithFormat:@"%i/15",counter];
answerCount=answerCount + 1;
// Set the game to a "live" question (for timer purposes)
questionLive = YES;
// Set the time for the timer
time = 15.0;
// Go to the next question
questionNumber = questionNumber + 1;
// THIS IS REALLY TERRIBLE CODE!!!
// We get the question from the questionNumber * the row that we look up in the array.
// This is absolutely horrible, just a placeholder until the right way.
// I cannot even begin to describe how wrong this solution is.
// Set the question string, and set the buttons the the answers
int i;
int j;
NSInteger row = 0;
i = 20; //i > 1;
{
j = arc4random()%i;
questionNumber = j + 1;
if(questionNumber == 1)
{
row = questionNumber - 1;
answerCount ++;
}
else
{
row = ((questionNumber - 1) * 6);
answerCount ++;
}}
// Set the question string, and set the buttons the the answers
NSString *selected = [theQuiz objectAtIndex:row];
NSString *activeQuestion = [[NSString alloc] initWithFormat:@"%@", selected];
[answerOne setTitle:[theQuiz objectAtIndex:row+1] forState:UIControlStateNormal];
[answerTwo setTitle:[theQuiz objectAtIndex:row+2] forState:UIControlStateNormal];
[answerThree setTitle:[theQuiz objectAtIndex:row+3] forState:UIControlStateNormal];
[answerFour setTitle:[theQuiz objectAtIndex:row+4] forState:UIControlStateNormal];
rightAnswer = [[theQuiz objectAtIndex:row+5] intValue];
// Set theQuestion label to the active question
theQuestion.text = activeQuestion;
// Start the timer for the countdown
timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(countDown) userInfo:nil repeats:YES];
[selected release];
}
-(void)updateScore
{
// If the score is being updated, the question is not live
questionLive = NO;
[timer invalidate];
// Hide the answers from the previous question
[ShowLeader setHidden:YES];
[sendsms setHidden:YES];
[appstore setHidden:YES];
[appstorelabel setHidden:YES];
[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];
[count setHidden: YES];
// END THE GAME.
NSInteger endOfQuiz = [theQuiz count];
if (answerCount >= 15)
{
answerCount =0;
{
// Game is over.
if(myScore < 400)
{
NSString *finishingStatement = [[NSString alloc] initWithFormat:@"Du havde fået en fyring hvis du var træner\nDu fik %i point!", myScore];
theQuestion.text = finishingStatement;
[finishingStatement release];
}
if(myScore == 450)
{
NSString *finishingStatement = [[NSString alloc] initWithFormat:@"Ikke acceptabelt, det må du kunne gøre bedre\nDu fik kun %i point!", myScore];
theQuestion.text = finishingStatement;
[finishingStatement release];
}
if(myScore == 500)
{
NSString *finishingStatement = [[NSString alloc] initWithFormat:@"Færdig!Ok resultat, men langt fra det bedste\nDu fik kun %i point!", myScore];
theQuestion.text = finishingStatement;
[finishingStatement release];
}
if(myScore == 550)
{
NSString *finishingStatement = [[NSString alloc] initWithFormat:@"Du burde nok se lidt mere superliga\nDu fik %i point!", myScore];
theQuestion.text = finishingStatement;
[finishingStatement release];
}
if(myScore == 600)
{
NSString *finishingStatement = [[NSString alloc] initWithFormat:@"Du er ved at være der, men mangler lidt endnu.\nDu fik %i point.", myScore];
theQuestion.text = finishingStatement;
[finishingStatement release];
}
if(myScore == 650)
{
NSString *finishingStatement = [[NSString alloc] initWithFormat:@"Vis nu lige, at du er en rigtig fan!\nDu fik %i point.", myScore];
theQuestion.text = finishingStatement;
[finishingStatement release];
}
if(myScore > 700)
{
NSString *finishingStatement = [[NSString alloc] initWithFormat:@"Du er en ægte dansk fodbold fan!!\nDu fik %i point. Tillykke!", myScore];
theQuestion.text = finishingStatement;
[finishingStatement release];
}
theLives.text = @"";
// Make button 1 appear as a reset game button
restartGame = YES;
[answerOne setHidden:NO];
[appstore setHighlighted:NO];
[answerOne addTarget:self action:@selector(reset)forControlEvents:
UIControlEventTouchDown];
[answerOne setTitle:@"
Prøv igen!" forState:UIControlStateNormal];
[showachievements setHidden:NO];
[ShowLeader setHidden:NO];
[submitScore setHidden:NO];
[appstore setHidden:YES];
[appstorelabel setHidden:YES];
[sendsms setHidden:NO];
[animation setHidden:YES];
[animationsmiley setHidden:YES];
}
}
else
{
// Give a short rest between questions
time = 3.5;
// Initialize the timer
timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(countDown) userInfo:nil repeats:YES];
}
}
-(void)reset {
[answerOne removeTarget:self action:@selector(reset)forControlEvents:UIControlE ventTouchDown];
[self viewDidLoad];
}
-(void)countDown
{
// Question live counter
if(questionLive==YES)
{
time = time - 1;
theLives.text = [NSString stringWithFormat:@"Tid tilbage: %i!", time];
if(time == 0)
{
// Loser!
questionLive = NO;
theQuestion.text = @"Desværre, tiden løb fra dig!";
myScore = myScore - 50;
[timer invalidate];
[self updateScore];
}
}
// In-between Question counter
else
{
time = time - 1;
theLives.text = [NSString stringWithFormat:@"Næste spørgsmål..%i!", time];
if(time == 0)
{
[timer invalidate];
theLives.text = @"";
[self askQuestion];
}
}
if(time < 0)
{
[timer invalidate];
}
}