Computer Science Canada

Help Me Please Im Stuck! (hangman)

Author:  manmanman [ Sat Jan 24, 2009 7:22 pm ]
Post subject:  Help Me Please Im Stuck! (hangman)

code:
proc play2
    var playAgain : string (1)          % gets 'y' or 'n'
    locate (maxrow - 3, 1)
    PutCenter ("Play Again? (Y/N)")

    View.Update

loop
        getch (playAgain)
        exit when (playAgain = "Y" or playAgain = "y") or (playAgain = "N" or playAgain = "n")
        BlinkMessage (maxrow - 2, 2, "Must be 'Y' or 'N'", yellow)
   

    View.Update

    if playAgain = "Y" or playAgain = "y" then
        var input : string (1)              % User's guess
        % var puzzle : string := ""               % Phrase to guess
        var unString, unDisplay : string := "" % Phrase with underlines, To display

        var bodyCount : int := 0       % # of errors

        var lettersUsed : string := "" % contains all letters entered
        var choiceDisplay : string := "" % Centerable string or letters avail.


    end if
    View.Update
end loop

    cls
    locate (4, 1)
    PutCenter ("Thanks for playing!")
    DrawHangman (335, 190, 15, 40, 50, 15, 10, -20, 6, 2)
    View.Update
end play2



Im making hangman and im trying to figure out how to reset all the varialbe if i wanna play more than once. im using includes in 1 main files so i cant really provide all the code. thanks in adavanced if you can help

Author:  Homer_simpson [ Sat Jan 24, 2009 7:34 pm ]
Post subject:  Re: Help Me Please Im Stuck! (hangman)

Turing:
exit when (playAgain = "Y" or playAgain = "y") or (playAgain = "N" or playAgain = "n")

why?

shouldn't it be

Turing:
exit when (playAgain = "N" or playAgain = "n")



Mod Edit: Remember to use syntax tags! Thanks Smile
code:
[syntax="turing"]Code Here[/syntax]

Author:  manmanman [ Sun Jan 25, 2009 4:07 pm ]
Post subject:  Re: Help Me Please Im Stuck! (hangman)

Homer_simpson @ Sat Jan 24, 2009 7:34 pm wrote:
Turing:
exit when (playAgain = "Y" or playAgain = "y") or (playAgain = "N" or playAgain = "n")

why?

shouldn't it be

Turing:
exit when (playAgain = "N" or playAgain = "n")



Mod Edit: Remember to use syntax tags! Thanks Smile
code:
[syntax="turing"]Code Here[/syntax]


i tried that but then i does not get the Y or y so that make it really difficult.

Author:  TheGuardian001 [ Sun Jan 25, 2009 5:36 pm ]
Post subject:  Re: Help Me Please Im Stuck! (hangman)

it will still get y or Y... it just won't use it. that exit when statement causes the game to end even if they say they want to play again.

as for the resetting of variables:

Turing:

var myString : string := "hello!"
myString := "" %it no longer has a value!
var myInt : int := 5
myInt := -1 %ints are a bit trickier. just set it to a value that will never happen unless you have reset it, or to its default value.
var myReal : real := 5.5
myReal := -1 %same as an int. just set it to a value that should never happen OR to the default value you gave it the first time.

etc etc etc.

just set it to either the original value, or a value that will never happen unless you reset it.


: