Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create an object-oriented (OO) hangman game in Java. Use JOptionPanes message, input, and confirm dialogs to display messages, get user guesses, and get user options.

Create an object-oriented (OO) hangman game in Java. Use JOptionPanes message, input, and confirm dialogs to display messages, get user guesses, and get user options. Use at least twenty messages that the user has to guess, and randomly select between these messages for a secret word to guess. If the user guesses the same letter again, there is no penalty if the letter is part of the message, but there is a penalty if the letter is not in the message.

Use three classes: A hangman class, a Gallows class, and a Message class. The Hangman class should contain the main method and call methods in other classes. It should contain at least two private data members, one of type Message and one of type Gallows. JOptionPane static methods should be called from this class.

The Gallows class should depict the gallows, and incrementally show the hangman as a user guesses incorrectly. The Gallows class should have at least two methods, plus you should override the toString() method.

void incrementHangman() This class should increment the hangman. Thus, you should also have a private data member in the class that keeps track of the number of incorrect guesses.

boolean isDead() This method returns false if the user had made less than eight wrong guesses (seven body parts, plus a final guess) and true otherwise.

String toString() This method shows an ASCII art drawing of the gallows, with the appropriate number of body parts. Note that the JOptionPane character spacing differs from the command line, and you may need to add extra spaces to make the picture appear correctly.

The Message class contains information about the secret word to guess. In addition to the private data members you need, the Message class should have at least two methods, plus you should override the toString() method.

boolean guess(char c) This method returns true if the guess is part of the message and false otherwise. Note that guesses are case insensitive. This method should change a data member if the guess is correct.

boolean solved() This method returns true if the message is complete, and false otherwise.

String toString() This method returns a String which depicts the current state of the message. The String returned has an underscore for each unknown letter in the word, and the correct letters for the letters that have previously been guessed correctly. Separate the characters with spaces to make the number of letters to guess easier to determine.

After the user guesses the message correctly, or exceeds the number of guesses, show a win or lose dialog and ask the user if they want to play again. (This is done in the Hangman class.)

image text in transcribed

X Input ? Please guess a letter: : A_0 1 1 0 1 1 I OK Cancel X Input ? Please guess a letter: : A_0 1 1 0 1 1 I OK Cancel

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

Oracle 10g SQL

Authors: Joan Casteel, Lannes Morris Murphy

1st Edition

141883629X, 9781418836290

More Books

Students also viewed these Databases questions