Computer Science Canada

need help with playing the game again...

Author:  yingmu [ Sun Mar 06, 2005 7:35 pm ]
Post subject:  need help with playing the game again...

ok i made a questionaire game from ifs, wat do you do that can ask the player if he/she wants to play again and then let them replay the game?

Author:  Cervantes [ Sun Mar 06, 2005 7:41 pm ]
Post subject: 

Put your whole program in a loop (or, not your whole program. Everything but the variables etc. Then, ask if they want to play again. If they say no, exit the loop. If they say yes, don't exit the loop. Instead, go back to the top of the loop, and do everything over again.

code:

%variables, procs, functions, etc.
var playAgain : string (1)
loop
    % main code.  Probably a lot of if statements ;)
    put "Would you like to play again?  y/n" ..
    getch (playAgain)
    if playAgain = "n" or playAgain = "N" then
        exit
    end if
end loop

Note that that has some problems in that the user can enter "q" and it will restart. You'll have to fix that. Wink

Author:  Delos [ Sun Mar 06, 2005 7:41 pm ]
Post subject: 

Put the whole thing in a loop. before the end of the loop, insert a part asking whether a repition is req'd. If it is not, then exit the loop.


: