Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Need Help With Code!!
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
P-Nut311




PostPosted: Sun Jan 02, 2005 7:56 pm   Post subject: Need Help With Code!!

I'm making a trivia game, but I'm having a problem with my code. How do I make it so that if the user gets the question wrong, it will go to a different screen saying "You Lose" or something along those lines? My programs keeps the question on screen and just inputs the next question over-top the previous one. How do I topple this?

Here's the code where the problem occurs:

code:

%History Question 1
    loop
        randomize
        var history : array 1 .. 5 of string
        var fonthistory1 : int := Font.New ("Cooperplate Gothic Bold:14:bold")
        Font.Draw ("What did World War II have that World War I didn't have?", 95, 400, fonthistory1, yellow)
        delay (1000)
        var fontairplanesandtanks : int := Font.New ("Cooperplate Gothic Bold:14:bold")
        Font.Draw ("1. Airplanes and Tanks", 50, 350, fontairplanesandtanks, yellow)
        delay (1000)
        var font10000moresoliders : int := Font.New ("Cooperplate Gothic Bold:14:bold")
        Font.Draw ("2. 10,000 More Soldiers", 400, 350, font10000moresoliders, yellow)
        delay (1000)
        var fontatomicbombs : int := Font.New ("Cooperplate Gothic Bold:14:bold")
        Font.Draw ("3. Atomic Bombs", 50, 250, fontatomicbombs, yellow)
        delay (1000)
        var fontmustardgas : int := Font.New ("Cooperplate Gothic Bold:14:bold")
        Font.Draw ("4. Mustard Gas", 400, 250, fontmustardgas, yellow)
        delay (1000)
        var fonthistory1answer : int := Font.New ("Cooperplate Gothic Bold:14:bold")
        Font.Draw ("Answer: ", 0, 200, fonthistory1answer, yellow)
        locate (19, 12)
        put "" ..
        get historyanswer1
        case historyanswer1 of
            label 1 :
                var fontincorrect : int := Font.New ("Cooperplate Gothic Bold:14:bold")
                Font.Draw ("Incorrect!", 300, 100, fontincorrect, yellow)
            label 2 :
                var fontincorrect : int := Font.New ("Cooperplate Gothic Bold:14:bold")
                Font.Draw ("Incorrect!", 300, 100, fontincorrect, yellow)
            label 3 :
                var fontcorrect : int := Font.New ("Cooperplate Gothic Bold:14:bold")
                Font.Draw ("Correct!", 300, 100, fontcorrect, yellow)
            label 4 :
                var fontincorrect : int := Font.New ("Cooperplate Gothic Bold:14:bold")
                Font.Draw ("Incorrect!", 300, 100, fontincorrect, yellow)
            label :
                var fontnotvalid : int := Font.New ("Cooperplate Gothic Bold:14:bold")
                Font.Draw ("That is not a choice.", 250, 100, fontnotvalid, yellow)
                delay (1000)
        end case
        delay (1000)
        if historyanswer1 = 3 then
            counter := counter + 1
            cls
            drawline (645, 0, 645, 755, red)
            Font.Draw ("1.              $100", 650, 10, font50, black)
            Font.Draw ("2.              $200", 650, 30, font100, cyan)
            Font.Draw ("3.              $300", 650, 50, font200, red)
            Font.Draw ("4.              $400", 650, 70, font300, red)
            Font.Draw ("5.              $500", 650, 90, font500, green)
            Font.Draw ("6.           $1,000", 649, 110, font1000, red)
            Font.Draw ("7.           $2,000", 649, 130, font2000, red)
            Font.Draw ("8.           $4,000", 649, 150, font4000, red)
            Font.Draw ("9.           $8,000", 649, 170, font8000, red)
            Font.Draw ("10.       $16,000", 648, 190, font16000, green)
            Font.Draw ("11.       $32,000", 648, 210, font32000, red)
            Font.Draw ("12.       $64,000", 648, 230, font64000, red)
            Font.Draw ("13.     $125,000", 647, 250, font16000, red)
            Font.Draw ("14.     $500,000", 647, 270, font500000, red)
            Font.Draw ("15.  $1,000,000", 646, 290, font1million, yellow)
            if historyanswer1 = 1 or historyanswer1 = 2 or historyanswer1 >= 4 then
                cls
                %History Question #2
                var fonthistory2 : int := Font.New ("Cooperplate Gothic Bold:14:bold")
                Font.Draw ("Who was Sir Wilfred Laurier?", 200, 400, fonthistory2, yellow)
                delay (1000)
                var fontcanadianprimeminister : int := Font.New ("Cooperplate Gothic Bold:14:bold")
                Font.Draw ("1. Canadian Prime Minister", 50, 350, fontcanadianprimeminister, yellow)
                delay (1000)
                var fontgovernor : int := Font.New ("Cooperplate Gothic Bold:14:bold")
                Font.Draw ("2. Governor", 400, 350, fontgovernor, yellow)
                delay (1000)
                var fontmayor : int := Font.New ("Cooperplate Gothic Bold:14:bold")
                Font.Draw ("3. Mayor", 50, 250, fontmayor, yellow)
                delay (1000)
                var fontsenator : int := Font.New ("Cooperplate Gothic Bold:14:bold")
                Font.Draw ("4. Senator", 400, 250, fontsenator, yellow)
                delay (1000)
                var fonthistoryanswer2 : int := Font.New ("Cooperplate Gothic Bold:14:bold")
                Font.Draw ("Answer: ", 0, 200, fonthistoryanswer2, yellow)
                locate (19, 12)
                put "" ..
                get historyanswer2
                case historyanswer2 of
                    label 1 :
                        var fontcorrect : int := Font.New ("Cooperplate Gothic Bold:14:bold")
                        Font.Draw ("Correct!", 300, 100, fontcorrect, yellow)
                        delay (1000)
                    label 2 :
                        var fontincorrect : int := Font.New ("Cooperplate Gothic Bold:14:bold")
                        Font.Draw ("Incorrect!", 300, 100, fontincorrect, yellow)
                        delay (1000)
                    label 3 :
                        var fontincorrect : int := Font.New ("Cooperplate Gothic Bold:14:bold")
                        Font.Draw ("Incorrect!", 300, 100, fontincorrect, yellow)
                        delay (1000)
                    label 4 :
                        var fontincorrect : int := Font.New ("Cooperplate Gothic Bold:14:bold")
                        Font.Draw ("Incorrect!", 300, 100, fontincorrect, yellow)
                        delay (1000)
                    label :
                        var fontnotvalid : int := Font.New ("Cooperplate Gothic Bold:14:bold")
                        Font.Draw ("That is not a choice.", 250, 100, fontnotvalid, yellow)
                        delay (1000)
                end case
                if historyanswer2 = 1 then
                    counter := counter + 1
                    cls
                    drawline (645, 0, 645, 755, red)
                    Font.Draw ("1.              $100", 650, 10, font50, black)
                    Font.Draw ("2.              $200", 650, 30, font100, black)
                    Font.Draw ("3.              $300", 650, 50, font200, cyan)
                    Font.Draw ("4.              $400", 650, 70, font300, red)
                    Font.Draw ("5.              $500", 650, 90, font500, green)
                    Font.Draw ("6.           $1,000", 649, 110, font1000, red)
                    Font.Draw ("7.           $2,000", 649, 130, font2000, red)
                    Font.Draw ("8.           $4,000", 649, 150, font4000, red)
                    Font.Draw ("9.           $8,000", 649, 170, font8000, red)
                    Font.Draw ("10.       $16,000", 648, 190, font16000, green)
                    Font.Draw ("11.       $32,000", 648, 210, font32000, red)
                    Font.Draw ("12.       $64,000", 648, 230, font64000, red)
                    Font.Draw ("13.     $125,000", 647, 250, font16000, red)
                    Font.Draw ("14.     $500,000", 647, 270, font500000, red)
                    Font.Draw ("15.  $1,000,000", 646, 290, font1million, yellow)
                    exit when historyanswer2 >= 2
end if
end if
end if
end if
end loop
Sponsor
Sponsor
Sponsor
sponsor
SuperGenius




PostPosted: Sun Jan 02, 2005 8:27 pm   Post subject: (No subject)

i would suggest that you make a prodecure for your "you loose screen"

something like this:
code:

procedure lose()
cls
Font.Draw ("YOU LOSE!", 400, 350, losefont, red
end lose

where answer is a boolean var:

code:

loop
%main loop
     if answer = false then
          lose
          exit loop
     end if
end loop


what this will do is when the answer is false, clear the screen and print "you Lose"
when that is done it will exit the main loop so the program will stop but the message will still remain on the screen.
AsianSensation




PostPosted: Sun Jan 02, 2005 8:37 pm   Post subject: (No subject)

I should leave the professional lecture about bad programming style to McKenzie, but I really have to say something right now.

I suggest change your program structure right now before you go any further.

The problem you asked shouldn't be that hard to fix, but it's that you are nesting each question inside cases, loops, and if statements. Don't declare variables inside loops.

To actually fix the problem, all you need is a variable and an if statement.

if variable = correctans then
you win
else you lose
end if

where variable takes on different values, and correctans takes on different values base on what your question is.

There are a couple of trivia game that's open sourced in the turing source section, I suggest you check it out.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: