Question: USE THE JAVA LANGUAGE AND DO NOT USE BUFFERED READER The dictionary file is too big to include so please use a sample file of
USE THE JAVA LANGUAGE AND DO NOT USE BUFFERED READER
The dictionary file is too big to include so please use a sample file of your choosing in its place
Objective:
Write a game of Hangman. The player will guess one letter at a time until the word is finally revealed. Also there are a limited number of guesses allowed before the game is over. I advise using two classes. The first class will have all the back end data and will contain:
- Member Variables
--The secret word
-- The disguised word where each unknown letter is replaced by a question mark (?). For example, if the word is abracadabra and the letters a,b,e have been guessed, the disguised word would be ab?a?a?ab?a
-- The number of guesses made
-- The number of incorrect guesses
-- Dictionary of words
- Constructors
-- A default constructor initializing each value to a default value and resets the game.
- Accessors and Mutators for all member variables. Make sure they check for valid values!
- Methods
-- loadDictionary This method loads dictionary file. This file has each word on a separate line
-- resetGame Picks a new word from the dictionary and resets all of the values.
-- makeGuess this returns a Boolean value if the letter was found in the secret word. Case does not matter. Also it passes a character as a parameter. This will add to the number of guesses made, check to see if the letter was found, and if the letter was found it replaces the question marks in the disguised word with that letter. Keep in mind this may be decomposable into a couple of methods, but that is up to you.
-- isFound returns a true if the hidden word has been completely uncovered.
Next write another class that runs the game. This can be done in several different ways, but some points I do expect to see is
- At each update the user is shown the disguised word and the number of guesses they have made.
- Also they should be shown a little diagram of a person. Initially it shows the gallows, then for every missed letter the picture adds this in the following order
-- Head
-- Body
-- One Arm
-- Both Arms
-- Left Leg
-- Right Leg
- After the user is shown their current state, they are then prompted to enter a letter or type something to quit the game
- Once the user has successfully guessed the secret word, or has more than 7 unsuccessful guesses the game is over and the user is prompted whether or not they want to play again. If they do the process starts all over.
Example Dialog:
Welcome to Hangman!
You have made 0 guesses
???????
_______
| |
|
|
|
|
|
Enter a letter
R
You have made 1 guesses
???????
_______
| |
| O
|
|
|
|
Enter a letter
S
You have made 2 guesses
???????
_______
| |
| O
| |
| |
|
|
Enter a letter
T
You have made 3 guesses
???????
_______
| |
| O
| \|
| |
|
|
Enter a letter
E
You have made 4 guesses
??????e
_______
| |
| O
| \|
| |
|
|
Enter a letter
A
You have made 5 guesses
?a??a?e
_______
| |
| O
| \|
| |
|
|
Enter a letter
L
You have made 6 guesses
?a??a?e
_______
| |
| O
| \|/
| |
|
|
Enter a letter
N
You have made 7 guesses
?a??a?e
_______
| |
| O
| \|/
| |
| /
|
Enter a letter
B
You have made 8 guesses
?abba?e
_______
| |
| O
| \|/
| |
| /
|
Enter a letter
G
You have made 9 guesses
?abbage
_______
| |
| O
| \|/
| |
| /
|
Enter a letter
Z
You have made 10 guesses
?abbage
_______
| |
| O
| \|/
| |
| / \
|
Enter a letter
Q
You have made 11 guesses
?abbage
_______
| |
| O
| \|/
| |
| / \
|
GAME OVER!
The word was cabbage.
Would you like to play again? (Yes/No)
No
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
