Computer Science Canada Hangman |
Author: | Gackt [ Tue Mar 10, 2009 5:48 pm ] |
Post subject: | Hangman |
Hey, Im kind of stuck on my hangman game. Im looking for help on the basic coding. I created a .txt file to load all the words from. I just have no clue how to select a random word from it and guess each indivual letter. Could anyone possibly throw a basic coding line at me that I can work with? |
Author: | metachief [ Tue Mar 10, 2009 6:23 pm ] |
Post subject: | RE:Hangman |
Code line: put "Hello!" Work with it! |
Author: | DemonWasp [ Tue Mar 10, 2009 6:40 pm ] |
Post subject: | RE:Hangman |
Do you know arrays yet? Do you know file I/O yet (input specifically, though output is also useful)? Do you know how to display stuff on the screen and ask for user input? That's all you need. |
Author: | Tony [ Tue Mar 10, 2009 6:40 pm ] |
Post subject: | RE:Hangman |
The simplest way is to read everything into an array, and pick a random element of that array. |
Author: | Gackt [ Wed Mar 11, 2009 7:17 am ] |
Post subject: | RE:Hangman |
I don;'t have time to learn arrays. |
Author: | hossack [ Wed Mar 11, 2009 7:51 am ] |
Post subject: | Re: RE:Hangman |
metachief @ Tue Mar 10, 2009 6:23 pm wrote: Code line: put "Hello!"
Work with it! Come on, post something that will help! |
Author: | Tallguy [ Wed Mar 11, 2009 7:55 am ] |
Post subject: | RE:Hangman |
like tony said, the easiest way to do this is to have arrays, if the user picks a letter that is in the array, then have a counter or something, and store used letters in an array by themselves with another counter for numbert if guesses this is just how i would do it . . . |
Author: | DemonWasp [ Wed Mar 11, 2009 8:12 am ] |
Post subject: | RE:Hangman |
You do have time to learn arrays. They really aren't that hard, and they are absolutely necessary for anything more than a trivial program. |
Author: | Gackt [ Wed Mar 11, 2009 8:55 am ] |
Post subject: | RE:Hangman |
If I use arrays then Im going to lose marks for not using the coding she taught us. Edit: Okay, really all I need to know is how to randomize a string? |
Author: | Tallguy [ Wed Mar 11, 2009 9:02 am ] |
Post subject: | RE:Hangman |
what is she teaching you?? arrays are basic programming |
Author: | Gackt [ Wed Mar 11, 2009 9:11 am ] | ||||
Post subject: | Re: Hangman | ||||
Were doing crap like this. Im so lost.
Thats to search for a word. Im using that to start off. And we have to do crap like
or what ever. Mod Edit: Your forgot the add syntax tags for one block of code |
Author: | Gackt [ Wed Mar 11, 2009 4:05 pm ] |
Post subject: | Re: Hangman |
Actually, What I should start out with is just Guess a word and working from there. I'll post up my .Zip file. What I mainly need help on is.. I can only guess the first word of my .txt file. Any other word that I have in there and try to guess, it says its not there. |
Author: | Tony [ Wed Mar 11, 2009 5:05 pm ] |
Post subject: | RE:Hangman |
you should trace through the flow of your program. Read it out-loud -- it's doing things in order that I'm sure wasn't your intention. Also, you might want to review what index actually does. |
Author: | Gackt [ Thu Mar 12, 2009 7:17 am ] |
Post subject: | RE:Hangman |
Its just the coding that my teacher gave me. She we had to use index for like searching for words. |
Author: | Tony [ Thu Mar 12, 2009 11:19 am ] |
Post subject: | RE:Hangman |
Well one of you is not understanding something. index is used to search inside a word, not for the whole word. |
Author: | Gackt [ Thu Mar 12, 2009 12:13 pm ] |
Post subject: | RE:Hangman |
I really dont understand anything, I just do what she tells us. |
Author: | crysis [ Thu Mar 12, 2009 5:19 pm ] |
Post subject: | RE:Hangman |
I started a hangman game Tuesday and I'm stuck where u are i don't understand how to get a random word out of a file but i understand how to replace a blank space with a letter. |
Author: | Tony [ Thu Mar 12, 2009 5:48 pm ] |
Post subject: | RE:Hangman |
If you guys don't want to use arrays, then you can just read a random number of lines from a text file, and then use the last word read. This might require having to read the file twice, to first figure out how long it is. |
Author: | Gackt [ Thu Mar 12, 2009 7:54 pm ] | ||
Post subject: | Re: Hangman | ||
Right now, I just have an assigned word to guess. How can i get it so that when I guess it it checks to see if the letter I guess is correct and in the word and how wuold I get it to show up?
|
Author: | Tony [ Thu Mar 12, 2009 8:01 pm ] |
Post subject: | Re: Hangman |
Gackt @ Thu Mar 12, 2009 7:54 pm wrote: How ... it checks to see if the letter I guess is correct and in the word
Tony @ Thu Mar 12, 2009 11:19 am wrote: index is used to search inside a word
it will also tell you the (first!) position in the word, where it's located, so you know where to draw the letter. You'd have to think about what you can do to the word, so that index will skip over the first found location (for cases where a word has some letters more than once). |
Author: | Gackt [ Mon Mar 23, 2009 9:16 am ] |
Post subject: | RE:Hangman |
Uhh.. what? |
Author: | Gackt [ Mon Mar 23, 2009 4:48 pm ] |
Post subject: | Re: Hangman |
OKay, I've gotten farther. Few things I would like to know, How come when I guess a letter, it says "You have already guessed that letter" when I havent. And how would I make it to that when the Word is fully guessed, it recongnizes (spelt wrong) that It is correct? |
Author: | Gackt [ Wed Mar 25, 2009 9:54 am ] | ||
Post subject: | Re: Hangman | ||
Okay, wtf. Why is it trying Reading past the EOF. All the other files are in the Zip file above.
|
Author: | Gackt [ Thu Mar 26, 2009 1:02 pm ] |
Post subject: | RE:Hangman |
Thanks for the Help! |