Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

[Tutorial] Quiz Game

123457

Replies

  • David-TDavid-T Posts: 4New Users
    edited May 2012
    alessign wrote: »
    Are you running two versions of the same app? Try delete all contents in iPhone Simulator, than go to xCode and Product -> Clean. Try to run it again...

    That was probably the reason yeah..

    I decided to recreate the program from scratch using the old as reference, except I relied on ARC instead of the old memory method. That alone removed most of my crashing problems.

    Btw I recommend anyone in here who uses the original source code, to pick the code a part and recreate it in a new project, instead of just editing the old. You learn a lot more doing that :)


    Btw alessign, your randomizer code was brilliant, I've learned so much from this thread, but that part I couldn't find a solution for myself, now it works perfectly, thank you!

    I was wondering, do you know how to have the program show you the "Correct/Wrong" answer for the last question on the array?

    Here it just jumps to the last screen without showing whether you got it right or wrong :S

    I assume it's because there is zero delay from answering the last question - to showing the final results..
  • alessignalessign Posts: 48Registered Users @
    edited May 2012
    David-T wrote: »
    That was probably the reason yeah..

    I decided to recreate the program from scratch using the old as reference, except I relied on ARC instead of the old memory method. That alone removed most of my crashing problems.

    Btw I recommend anyone in here who uses the original source code, to pick the code a part and recreate it in a new project, instead of just editing the old. You learn a lot more doing that :)


    Btw alessign, your randomizer code was brilliant, I've learned so much from this thread, but that part I couldn't find a solution for myself, now it works perfectly, thank you!

    I was wondering, do you know how to have the program show you the "Correct/Wrong" answer for the last question on the array?

    Here it just jumps to the last screen without showing whether you got it right or wrong :S

    I assume it's because there is zero delay from answering the last question - to showing the final results..

    Yes I am aware of that issue. Watching the console, I think the problem is in the "if" statement here
    // END THE GAME.
       
        if ([indexes count] == 0) 	
        {
            
    		// Game is over.
    		if(myScore > 0)
    		{
    			NSString *finishingStatement = [[NSString alloc] initWithFormat:@"You scored %i!", myScore];
    			theQuestion.text = finishingStatement;
    
    

    When the Array indexes has no number in it left, it terminates the app as requested. That means with immediate affect when the last number was drawn. Little bug. You will need to come up with different "if" statement to fix this I think. I am using 250 random questions and no score, so it works for me. Include more NSLogs to monitor the app behaving and watch it in the console when in process, it will help you to understand it better.

    I am glad it was useful for somebody!
  • David-TDavid-T Posts: 4New Users
    edited May 2012
    alessign wrote: »
    Yes I am aware of that issue. Watching the console, I think the problem is in the "if" statement here
    // END THE GAME.
       
        if ([indexes count] == 0) 	
        {
            
    		// Game is over.
    		if(myScore > 0)
    		{
    			NSString *finishingStatement = [[NSString alloc] initWithFormat:@"You scored %i!", myScore];
    			theQuestion.text = finishingStatement;
    
    

    When the Array indexes has no number in it left, it terminates the app as requested. That means with immediate affect when the last number was drawn. Little bug. You will need to come up with different "if" statement to fix this I think. I am using 250 random questions and no score, so it works for me. Include more NSLogs to monitor the app behaving and watch it in the console when in process, it will help you to understand it better.

    I am glad it was useful for somebody!

    Interesting, that's exactly where I tried to fix it, with no luck though.

    I tried a lot of things back & fourth, (resulting in a lot of crashes :P) the one that seemed the most simple was to just add 'time'

    if ([indexes count] == 0)
    {
    time = 8.0;


    I thought that would add secs before the end screen.
    It made a lot of sense to me, but my logic is very flawed I realize :o

    Damn this is so annoying!

    I think I need some sort of delay function?
  • alessignalessign Posts: 48Registered Users @
    edited May 2012
    David-T wrote: »
    Interesting, that's exactly where I tried to fix it, with no luck though.

    I tried a lot of things back & fourth, (resulting in a lot of crashes :P) the one that seemed the most simple was to just add 'time'

    if ([indexes count] == 0)
    {
    time = 8.0;


    I thought that would add secs before the end screen.
    It made a lot of sense to me, but my logic is very flawed I realize :o

    Damn this is so annoying!

    I think I need some sort of delay function?

    Maybe you should do something like
    if ([indexes count] == 0 && time ==0) 
    {
    ...
    
    Not sure if this exact code will work, but to give you an idea for the logic. It needs to let the count down finish also. Plus I am not sure what happens after you press any button...
  • David-TDavid-T Posts: 4New Users
    edited May 2012
    alessign wrote: »
    Maybe you should do something like
    if ([indexes count] == 0 && time ==0) 
    {
    ...
    
    Not sure if this exact code will work, but to give you an idea for the logic. It needs to let the count down finish also. Plus I am not sure what happens after you press any button...

    Thanks alessign , I do understand what you're getting at.. unfortunately that code also makes my app crash.

    The thing is, I do want to learn how to do it myself, but I'm afraid I'm way too inexperienced to come up with a solution on my own.

    I will keep trying, but I'm also moving on to some tutorials so I keep my motivation high, it sucks to be stock!

    I've gone through Lynda.com's Objective C Essential Training & iOS5 SDK Essential Training, great courses for learning the basics of the language, but it didn't touch on that many practical examples.

    I'll keep trying :)
  • loki-eloki-e Posts: 15New Users
    edited June 2012
    My question: In my quiz not show the number of the right button if the answer is incorrect, which right has been, but the right answer text from the Button.

    He said now Button "1" is right or Button "2", "3", "4".
    but i need the Answer Text from the right Button if is wrong.

    -(void)checkAnswerint)theAnswerValue
    {
    if(rightAnswer == theAnswerValue)
    {

    theQuestion.text = @Right! \nnice;

    myScore = myScore + 50;


    [rightAnswerLabel setHidden:YES];
    }


    else
    {
    theQuestion.text = @wrong;
    myScore = myScore - 50;

    [rightAnswerLabel setHidden:NO];
    rightAnswerLabel.text = [NSString stringWithFormat:@Answer %d is right,rightAnswer];
    }
    [self updateScore];
    }

    this is my question from the quiz

    @what is the color of the sun?,
    @blue,@green,@purple,@yellow,
    @4,

    the right Answer here is Answer 4. Now show me the Quiz this Number "4" as correct. I will get the Answer Text, all so right answer is "yellow" not "4".

    my example comes from
    iPhone Dev SDK Forum - Powered by vBulletin
  • ryanlawrence171ryanlawrence171 Posts: 24Registered Users
    edited June 2012
    Your game is good, I suggest you to make some changes by taking example of “Logos quiz”...
    <a href="http://www.hbiphonelabs.com/">iPhone Application Development | Apps Developers India</a>
  • crowded42crowded42 Posts: 4New Users
    Does anyone have the original zip file for this quiz game tutorial? If so can you forward the fiIe? I am not able to download the zip file at the beginning of this thread. I appreciate it. Thanks.
  • mgpwrmgpwr Posts: 7New Users
    Thanks for this. Going to start going through it now. :)
    iPhone Development Tutorials: http://ios-blog.co.uk/tutorials
  • scourgyscourgy Posts: 4New Users
    crowded42 said:

    Does anyone have the original zip file for this quiz game tutorial? If so can you forward the fiIe? I am not able to download the zip file at the beginning of this thread. I appreciate it. Thanks.

    I need that file too. Can anybody send it to me?
  • alessignalessign Posts: 48Registered Users @
    Crowded42/scourgy: The old build has some issues in new sdk, so it is better to read through the subjects and develop your project in new sdk build. By going through this forum and building the project step by step will makes you to understand the logic behind it. It was vey helpful to me to start from scratch...
  • scourgyscourgy Posts: 4New Users
    I am working on Xcode 3.2, so it will be very useful to me. If you have that code, would you be so kind to send it to me, because I need it. I know that if I go through the project step by step I will understand the logic, but I don't have time now to do this. :(
  • pash62pash62 Posts: 1New Users
    Thanks for the tuto but I cannot download the source codes. I'm redirected to iCloud.com when I click on Quiz_Game.zip! Could you help me please?
    Actually the main thing I was interested in was to find out how you coded the main game loop & unfortunately I see no where talking about it in extracted part of codes available here...
  • alessignalessign Posts: 48Registered Users @
    edited March 2013
    David-T, I was recently thinking about the little bug in the random function and here is the solution for it. You need to implement new 'if' statement in the existing function to check the time. Remove last terminating bit of the code from the same function and create new 'void' for it. Call this void after the time run out like such:

    -(void)endTheGame{ // Game is over. if(myScore > 0) { NSString *finishingStatement = [[NSString alloc] initWithFormat:@"You scored %i!", myScore]; [theQuestion setText:finishingStatement]; } else { NSString *finishingStatement = [[NSString alloc] initWithFormat:@"You scored %i.", myScore]; [theQuestion setText:finishingStatement]; } [theLives setText:@""]; if (time < 1) { [self veryEnd]; } } -(void)veryEnd{ restartGame = YES; [answerOne setHidden:NO]; [answerTwo setHidden:YES]; [answerThree setHidden:YES]; [answerFour setHidden:YES]; [quitGame setHidden:YES]; [timer invalidate]; timer = nil; }

    Hope that helps! Regards A.
    Post edited by alessign on
  • prem19902prem19902 Posts: 11New Users *
    edited May 2014
    Source code download link not working.......
    please update link..........
    Thanx.
  • alessignalessign Posts: 48Registered Users @
  • prem19902prem19902 Posts: 11New Users *
    edited October 2014
    How to make correct Answer display Green and wrong answer Red(as like below image)
    running_app_selecting_answer-e1363027547620-255x500.png
    Post edited by prem19902 on
  • alessignalessign Posts: 48Registered Users @
    Prem - check the iOS 8 version - I have included similar effect in ''Learn the answer'' mode. It lowers the alpha instead. You can change it to different color in classic mode with the same code...
  • prem19902prem19902 Posts: 11New Users *
    Thanx alessign for reply,
    I am trying to make app as like this website https://www.testkrok.org.ua
    Again, i want to add explanation of each question(How and why this option is correct ) so where to add this stuff and how to make it possible...
    waiting for your kind response......
  • alessignalessign Posts: 48Registered Users @
    I got that, but you should check the code as I suggested. I created method, where if user selects UISegemntedControl, it will reveal the answer and lower the opacity of the other buttons to make it stand up. What you should do is to get rid of the segmented control, but keep the method or rename it:


    -(void)segmentSelected{

    if ([segment selectedSegmentIndex] == 1 && answerOne.tag != rightAnswer){
    self.answerOne.alpha = 0.4;
    }
    else {
    self.answerOne.alpha = 1.0;
    }

    if ([segment selectedSegmentIndex] == 1 && answerTwo.tag != rightAnswer){
    self.answerTwo.alpha = 0.4;
    }
    else {
    self.answerTwo.alpha = 1.0;
    }

    if ([segment selectedSegmentIndex] == 1 && answerThree.tag != rightAnswer){
    self.answerThree.alpha = 0.4;
    }
    else {
    self.answerThree.alpha = 1.0;
    }

    if ([segment selectedSegmentIndex] == 1 && answerFour.tag != rightAnswer){
    self.answerFour.alpha = 0.4;
    }
    else {
    self.answerFour.alpha = 1.0;
    }
    }

    Then you get rid of [segment selectedSegmentIndex] == 1 and change the alpha method to something else, the stuff you need to do. You need to call this function when you want to make it display with [self segmentSelected];


    If you want to display it after the answer was selected, you need to do it in this method below I believe and implement [self segmentSelected] method :

    -(void)checkAnswer:(int)theAnswerValue
    {
    if(rightAnswer == theAnswerValue)
    {
    theQuestion.text = @Correct answer!;
    myScore = myScore + 1;

    }
    else
    {
    theQuestion.text = @Wrong answer!;

    }
    [self updateScore];
    }

    There is a timer, so don't forget to stop it, to be displayed long enough or get rid of it completely...

    Hope that helps
  • sxcheemsxcheem Bangalore, IndiaPosts: 4New Users Noob
    Dave,
    the link to download the sample code isn't working.
    Please check and help.
    Thanks
    Subbu
  • alessignalessign Posts: 48Registered Users @
    It is working, it's just in the description area
    http://www.olasz-studios.com/QuizGame.zip
  • sxcheemsxcheem Bangalore, IndiaPosts: 4New Users Noob
    Thanks so much... the link is working. One help i need. I need to display the working/analysis behind an answer as well.... along with Wrong or Right Answer. Please advise how to do that. Thanks.
  • alessignalessign Posts: 48Registered Users @
    That's simple, in the:

    -(void)checkAnswer:(int)theAnswerValue
  • sxcheemsxcheem Bangalore, IndiaPosts: 4New Users Noob
    Thanks alessign so much. Actually I want to display different detailed answers for each question. Along with 'Wrong Answer'. Please advise. Thanks.
This discussion has been closed.