PDA

View Full Version : Need help coding a simple Hangman game


Gertruid
01-11-2010, 08:46 PM
Hello everybody!

For a class project, I am creating a simple version of Hangman.
The phrase the user has to figure out will be "My teacher is the best."
When it starts out, it will print "-- ------- -- --- ----." Please enter a letter.

I am having some trouble, however, with the script being able to read the letter I enter and replace it with the corresponding hyphen.

So when you type in "e", the script prints out "-- -e---e- -- --e -e--."
And then they enter a "t", it will print out "-- te---e- -- t-e -e-t."
Until each letter is guessed

How do you do that?

brad211987
01-11-2010, 10:29 PM
You will have to be much more specific to get anywhere with your question.

Have you started the program?
What have you tried?
What part is giving you trouble?

I would start with a String that contains the actual key, and use the standard methods supported by the String class to read where and at what index each character resides.

Alternatively, you could use a character array and access the string as a standard array, but I would go with using a String.