Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

Hangman type game

 
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.
 
ranger
Posts: 17344
11
Mac IntelliJ IDE 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
 
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.
 
Ranch Hand
Posts: 815
  • Mark post as helpful
  • send pies
  • Report post to moderator
wow... you spent a long time typing that, eh?
 
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.
 
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.
 
author
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
 
A day job? In an office? My worst nightmare! Comfort me tiny ad!
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!