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

Username:   Password: 
 RegisterRegister   
 Hangman
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Gackt




PostPosted: 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?
Sponsor
Sponsor
Sponsor
sponsor
metachief




PostPosted: Tue Mar 10, 2009 6:23 pm   Post subject: RE:Hangman

Code line: put "Hello!"
Work with it!
DemonWasp




PostPosted: 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.
Tony




PostPosted: 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.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Gackt




PostPosted: Wed Mar 11, 2009 7:17 am   Post subject: RE:Hangman

I don;'t have time to learn arrays.
hossack




PostPosted: 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!
Tallguy




PostPosted: 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 . . .
DemonWasp




PostPosted: 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.
Sponsor
Sponsor
Sponsor
sponsor
Gackt




PostPosted: 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?
Tallguy




PostPosted: Wed Mar 11, 2009 9:02 am   Post subject: RE:Hangman

what is she teaching you?? arrays are basic programming
Gackt




PostPosted: Wed Mar 11, 2009 9:11 am   Post subject: Re: Hangman

Were doing crap like this. Im so lost.


Turing:

var stream : int
var word, search : string
var file : string


put "Enter the Name of a file, include the ending like .txt and crap."
get file

put "Enter a word to seach"
get search

open : stream, file, get
assert stream > 0



put "Words in file:"
put ""




loop
    exit when eof (stream)
    get : stream, word
    if index (word, search) > 0 then
        put word
        put "SHE'S THAR"
        delay (1000)
        exit
    else
        put "Its not thar"
        delay (1000)
        exit
    end if

end loop


close : stream







Thats to search for a word. Im using that to start off. And we have to do crap like

Turing:

    get : stream, skip
    exit when eof (stream)
    get : stream, word
    if length (word) > 2 and word (* -1 .. *) = "or" then
        word := word (1 .. * -2) + "our"


or what ever.

Mod Edit: Your forgot the add syntax tags for one block of code Smile
Gackt




PostPosted: 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.



HangmanWiP.zip
 Description:
The program

Download
 Filename:  HangmanWiP.zip
 Filesize:  12.64 KB
 Downloaded:  85 Time(s)

Tony




PostPosted: 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.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Gackt




PostPosted: 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.
Tony




PostPosted: 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.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
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 2  [ 24 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: