Computer Science Canada Hangman program |
Author: | Miko99 [ Fri Apr 11, 2003 9:20 pm ] |
Post subject: | Hangman program |
How would i write a hangman program that asks you what word will the other user be guessing. Each time the user guesses a correct letter it will say "Yes there are 4 E's!" or "Yes there are 2 W's!" and then shows the letters and in thr right position. i really need help with this! i havn'ty even got a clue where to start! all help is appreciated. THANKS!!!! |
Author: | Tony [ Fri Apr 11, 2003 9:36 pm ] | ||||||
Post subject: | |||||||
well you use standart input/output for the word the user will be guessing.
then you make an array of boolean to keep track of letters that were guessed.
and initialize them all to false since none of the letters were guessed yet then start a loop where user guesses letters compare guessed letter with all the letters in the word
if the guess is right, mark your boolean array as true and let user know he guessed right you can draw the letter in the correct spot using Font.Draw there're tutorials covering everything mentioned above in the tutorials section |
Author: | Miko99 [ Sat Apr 12, 2003 12:45 pm ] |
Post subject: | |
I need more help. I dont understand how to make the boolean false. I am still lost.....PLEASE I NEED HELP!! LoL |
Author: | Dan [ Sat Apr 12, 2003 2:54 pm ] |
Post subject: | |
letter(1) := false that will make the 1st one equal to false... |
Author: | Miko99 [ Sat Apr 12, 2003 9:17 pm ] |
Post subject: | |
code: var secretword, guess, wordguess, ans : string put "Enter the word to Guess!" get secretword cls var letter : array 1 .. length (secretword) of boolean put "Enter a letter!" get guess loop if (guess (1) := false) then put "Sorry there are no ", guess (1), " 's" else put "Yes there is at least 1 ", guess (1) end if put "would you like to guess the word now?" get ans if (ans = "yes") then put "Type in what you think the word is in Lower Case letters" get wordguess else put "Ok then guess your next word!" end if exit when wordguess = secretword end loop Whats wrong with this? |
Author: | Tony [ Sat Apr 12, 2003 9:53 pm ] |
Post subject: | |
variable guess is a string, not array. You dont need (1) after it. |
Author: | Martin [ Sat Apr 12, 2003 11:58 pm ] | ||
Post subject: | |||
Here's how I would do it.
Keep in mind, this is just a shell for finding matches, it's up to you to decide what to do next. If you don't understand, don't be afraid to ask (PM or otherwise) |
Author: | Miko99 [ Sun Apr 13, 2003 11:25 am ] |
Post subject: | |
Ok, i am getting an error saying that the " ! " is an illegal Character. Is this true? |
Author: | Asok [ Sun Apr 13, 2003 1:01 pm ] |
Post subject: | |
heh miko, you seem to have the problem of not sharing your code, we cannot help you if you're not completely specific, if there is an error in your code then we need to SEE your code. |
Author: | Miko99 [ Sun Apr 13, 2003 6:16 pm ] |
Post subject: | |
All thanks to Darkness, heres what i got: Code: var strMessage, ans, wordguess : string var strGuess : string (1) put "Enter the word!" get strMessage loop cls locate (1, 1) put "Please enter your guess" getch (strGuess) delay (500) for i : 1 .. length (strMessage) if strMessage (i) = strGuess then put "Yes! letter number ", i, " is a ", strGuess delay (800) else put "No, letter number ", i, " is not a ", strGuess delay (800) end if end for put "would you like to guess the word yet?" get ans exit when ans = "yes" end loop put "Enter your guess for the word!!!!" get wordguess cls if (wordguess = strMessage) then put "Correct!!! the word was ", strMessage else put "HAHAHAAHAHAHA!!! YOU SUCK!!!!! THE WORD WAS ", strMessage, " HAHAAHAHA!!!!" end if Now how would i modify that so that each time a letter is guessed correctly, it is displayed to the screen? |
Author: | Blade [ Sun Apr 13, 2003 6:46 pm ] | ||||
Post subject: | |||||
you could make an array of which ones you've guessed... like what was said ealier... and if that letter is guessed, display it at the top of the screen... ex:
this isnt supossed to work, its an example of what you could do so basicly what you would do, is set each letter guessed to false and when hte player guesses a right one, its set to true and displayed at the top, but of course you'll have to organize it so its displayed correctly... organize it by checking each letter, and if it the letter matches up.. then display it at a certian point using locate(x,y)
i think i explained it right... |