Win a copy of The Java Performance Companion this week in the Performance forum!
    Bookmark Topic Watch Topic
  • New Topic

Hangman type game

 
Ben Kwait
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Goodbye!

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
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Report post to moderator
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.

Mark
 
Fletcher Estes
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Report post to moderator
I will do your homework if you give me $800. Make that $900. Still interested?
 
Ben Kwait
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Posts: 815
  • Mark post as helpful
  • send pies
  • Report post to moderator
wow... you spent a long time typing that, eh?
 
Neeru Misra
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Posts: 55
  • Mark post as helpful
  • send pies
  • Report post to moderator
Let me know if original poster is interested in offshoring this problem.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Report post to moderator
Closing this topic. Re ask the question in the right forum with code that you have written.

Eric
 
    Bookmark Topic Watch Topic
  • New Topic