Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In Java create a word guessing game called Hangman . The game is played between the computer and one player . The player needs to

In Java create a word guessing game called Hangman. The game is played between the computer and one player. The player needs to guess the correct word by guessing a single character each time. The player is allowed upto 8 lives in one game. Every incorrect guess costs the player one life. The player loses the game if all 8 lives were used up, and wins if the complete word is guessed any time before that. (please include comments in your code)

Level 1

Choose a specific word of your liking and hardwire it in your code so you already know the size of the word.

Notify the player

Number of characters in the word

8 lives left

In each turn

Prompt the player to enter a char

If the entered char is exists in the word, the player is notified about the number of times the char appears in the word.

If the entered char is not present in the word, the player is notified of its absence from the word.

Stop the game when all 8 lives are used up.

Game should end immediately, if the player has guessed the correct word

Output should display the correct word

Output should also display whether the game was a win or a loss.

Sample output is shown below

image text in transcribed

Sample output word to guess is "program" Your Word has 7 characters You have 8 lives. Let's play! Enter a char sorry! d is not a character in this word. Try again! You have 7 lives left Enter a char sorry! e is not a character in this word. Try again! You have 6 lives left. Enter a char Yes, the character o appears once in your word. You have 6 lives left Enter a char Yes, the character p appears once in your word. You have 6 lives left Enter a char Yes, the character appears twice in your word. You have 6 lives left Enter a char Yes, the character g' appears once in your word. You have 6 lives left Enter a char Yes, the character a appears once in your word. You have 6 lives left Enter a char Yes, the character m' appears once in your word. You have 6 lives left That is it! You win! The correct word is "program If the player used up all 8 lives, your output must say- Sorry, you have no lives left. You lose! The correct word is javg 2/22/2017

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

MySQL/PHP Database Applications

Authors: Brad Bulger, Jay Greenspan, David Wall

2nd Edition

0764549634, 9780764549632

More Books

Students also viewed these Databases questions