File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programming Diversions and the fly likes Hangman type game Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Other » Programming Diversions
Reply locked New topic

Hangman type game

Ben Kwait

Joined: Feb 01, 2005
Posts: 2
This is a sample input from the directions:
Do you want to play a game? y

I am thinking of a secret word. Try to guess it.

_ _ _ _ _ _ _ _ What's your guess? a
_ _ _ _ _ a _ _ What's your guess? e
_ e _ _ _ _ _ _ What's your guess? i
_ _ _ _ _ _ _ _ What's your guess? o
_ _ _ _ o _ _ _ What's your guess? s
_ _ _ _ _ _ _ _ What's your guess? t
_ _ _ _ _ _ _ _ What's your guess? r
_ _ _ _ _ _ r _ What's your guess? seaboard

"seaboard" is the wrong guess.

_ _ _ _ _ _ _ _ What's your guess? k
k _ _ _ _ _ _ _ What's your guess? keyboard

You've got it in 10 guesses. That was ok!

Do you want to play another game? y

I am thinking of a secret word. Try to guess it.

_ _ _ _ _ What's your guess? a
_ _ _ _ _ What's your guess? e
_ _ _ _ _ What's your guess? i
i _ _ _ _ What's your guess? o
_ _ _ _ _ What's your guess? u
_ _ _ u _ What's your guess? c
_ _ _ _ _ What's your guess? t
_ _ _ _ t What's your guess?

The word is "input".
You gave up after 7 guesses. What happened?

Do you want to play another game? n

The program repeatedly performs the following actions:

Ask the user if he/she wants to play a game; if the user enters anything but 'y', the program terminates; otherwise

Pick a secret word (see below for how to do that), and print a message to communicate that to the user;

Repeatedly ask the user for a guess:
if the user enters a single letter, show all the places in the secret word where that letter occurs (or an '_' in those places where another letter occurs);
if the user enters a word (more than one letter), check if it is the correct word and, if it is not, print an appropriate message;
if the user just presses the Enter key (i.e., enters an empty string), it means he/she is giving up and you should reveal the secret word and report the number of guesses.

When the user finally guesses the correct word, print a message stating how many guesses were needed, and a message assessing the user's performance according to the following table:

Number of guesses Message
1 That was lucky!
2-4 That was amazing!
5-9 That was really good!
10-14 That was ok!
15-19 That was pretty bad!
20 or more This is not your game!

Go back to the beginning to see if the user wants to play another game.
Picking a secret word
To select a secret word and assign the value to a variable secretWord, you can use the following Java statement:
String secretWord = Words.getWord();

Words.getWord is a function that returns a word randomly picked from those in the words.txt file. Feel free to add your own words to the given words.txt file.

We are using a weird system so just give me the basics of what the code would be please.
Mark Spritzler

Joined: Feb 05, 2001
Posts: 17276

Hmmm, sounds like a homework assignment.

But, this is forum is for the Cattle Drive, and unfrotunately your post isn't about the Cattle Drive, so I am going to move this thread to the Programming Diversions forum.


Perfect World Programming, LLC - iOS Apps
How to Ask Questions the Smart Way FAQ
Fletcher Estes
Ranch Hand

Joined: Jul 01, 2004
Posts: 108
I will do your homework if you give me $800. Make that $900. Still interested?
Ben Kwait

Joined: Feb 01, 2005
Posts: 2
i dont want anyone to do it for me but im having trouble getting all my stuff organized properly. i cant get the Whats your guess to show up after the dashes and i cant get it to where you can input on the first line.
Nick George
Ranch Hand

Joined: Apr 04, 2004
Posts: 815
wow... you spent a long time typing that, eh?

I've heard it takes forever to grow a woman from the ground
Neeru Misra
Ranch Hand

Joined: Feb 03, 2005
Posts: 78
Wow...this is what I was looking for...I am hanged, man I am hanged. No more mortal after reading this post.
Manmohan Singhania
Ranch Hand

Joined: Feb 19, 2004
Posts: 55
Let me know if original poster is interested in offshoring this problem.

Jayalalitha is my girl friend. KarunaNidhi is my boy friend
Eric Pascarello

Joined: Nov 08, 2001
Posts: 15385
Closing this topic. Re ask the question in the right forum with code that you have written.

I agree. Here's the link:
subject: Hangman type game
It's not a secret anymore!