# Another java coding problem: text-based hangman woes



## AtreideS (Aug 20, 2001)

I've just spent a few hours struggling with this java problem. Here's exactly what I have to do:
"The Hangman Game -
The hangman game is a game of guessing words. You will be playing this game with the computer in charge of the game. Suppose the word you have to guess is:
programming
The computer would start by displaying the word with each letter replaced by an asterisk:
***********
Number of mistakes = 0 
Wrongly guessed letters = 
Letters available = abcdefghijklmnopqrstuvwxyz

That display means that so far you have not made any mistake and the set Wrongly guessed letters is empty.
You are then asked to play a letter. Suppose you play letter m. The computer would display:
******mm***
Number of mistakes = 0 
Wrongly guessed letters = 
Letters available = abcdefghijklnopqrstuvwxyz
Next suppose you play letter e which is not one of the letters of the word. Then the computer would display:
******mm***
Number of mistakes = 1 
Wrongly guessed letters = e
Letters available = abcdfghijklnopqrstuvwxyz

And so on until you successfully guess all the letters in the word, or until you make, say, eight mistakes. 
You are required to do the following:
(NOTE: You may assume all input is in lowercase and all input is correct.)

	First, design and create a class called HangMan to represent a game. (If you freeze the game at a point in time and observe its state, then what do you see? What would constitute the state of the game? How would the game change its state?)

	Second, provide a launcher program called HangManTest that will allow the user to play the game. The program should use the class you create in step 1. It will ask for a word to guess (that is entered at the keyboard), and then carry out a dialog with the user as shown above.

	Finally, make a copy of your HangManTest launcher program using the Unix command:

cp HangManTest.java HangManQuiz.java

Now edit the HangManQuiz.java file using your favourite editor, vim. Make this program behave exactly like the previous one, except that it will read a list of words from a text file, and select one at random for the user to guess. (The Java code to read the list of words from a text file and select one at random is provided for you in the AP3Utility class. See the end of this document for instructions to obtain source code and a sample list of words in a text file.)"

I'm completely stuck on where to begin. I found an example on the internet, and tried to work out where to go from there. But I still can't figure it all out. Please help! I've spent soooo long on this and I feel I haven't gotten anywhere. 
Thanks.


----------



## AtreideS (Aug 20, 2001)

Please help me. I've been working on this for so long, but I just can't get anywhere.  I think my main problem is just working out what needs to be in the Hangman.class, and what goes in the HangmanTest.class. Can someone please help a newbie learn some basic Java? Thanks.


----------



## AtreideS (Aug 20, 2001)

Ok its all ok now. I've worked out how to get going by myself.


----------



## bobguy (May 24, 2003)

i just typed in hangman into google and this was one of the first sites listed. if you had received the answer here, don't you think kinh or mary or whoever it is that may do the checking, would come across this. it's only going to take a few sec's for them to cross reference the code here with code submitted by ooj students...

ps, thanks for sharing you code, how are the rest of us supposed to learn???

is you name a reference to dune?


----------



## Svenmonkey (Mar 29, 2003)

I made this type of hangman game for my programming class a few days ago. It doesn't tell the player the number guessed wrong or the letters guessed, though (I have it print a picture made of asterisks and such that shows a gallows and your man instead). I think I might add those now.


----------



## AtreideS (Aug 20, 2001)

bobguy, I never asked for the actual code solution. I have used this section of TSG to ask for coding help before, but never just for the answer in code. I don't just see any reason to get the answer with not knowing how it works. I prefer to learn things for myself, which is why I posted here.Recently I've had help from a TSG forum user named codejockey, who was very helpful in giving me hints and things on how to solve a problem. Never once have I just wanted the answer. I had simply planned to ask for help on where to begin, so I could start the question.
However I figured it out for myself, and so I no longer required help on the problem.
Svenmonkey, it's good too see others are doing the same sort of things.


----------



## AtreideS (Aug 20, 2001)

bobguy, in your earlier post I forgot to answer your 2 questions.
Yes, Atreides is a reference to Dune. I was always a big fan of Duke Leto. 
And as for learning without my code. Well here are some great sites I've found very helpful:
http://www.javacoffeebreak.com/tutorials/index.html
http://www.javaforstudents.co.uk/
http://sepwww.stanford.edu/sep/josman/oop/oop1.htm 
the latter was a good one in helping me fully understand classes and things. I was really stuck when I began working on Hangman, but then I finally cracked it all open and got it working.
Good luck with your coding.

P.S Just so you don't think I'm stupid. You said "if you had received the answer here, don't you think kinh or mary or whoever it is that may do the checking, would come across this." Well I never intended to get a full coded solution, just some helpful advice on where to begin. Of course your absolutely right about the cross-checking. But I'm here to learn, not just submit the correct code.


----------



## bobguy (May 24, 2003)

Good work!

definately the hardest part of understanding java for the first time is getting your head around the relationship objects have with classes and how to use methods. And then being able to construct a working program with this knowledge. after this point the only real struggle is syntax. damn pedantic compiler.

cheers for the links i'll check em out.

hope i didn't come across as too negative, i just needed to expell some energy in the form of light relief sarcasm as all java and no fun makes bobguy a dull boy/gal...


----------



## AtreideS (Aug 20, 2001)

Don't worry, you didn't come across as too negative. Although you did freak me out. 
" i just needed to expell some energy in the form of light relief sarcasm " I know exactly what you mean, I've never been as stressed as last week when I was still trying to complete Hangman and Question 4 at the same time. Once I had it done I just let out a big sigh of relief.


----------

