Project #18807 - Java

Write a program that plays an interactive game of Hangman with its user. In general, the

rules of Hangman are as follows:

? The object of the game is for the user to guess a secret word, given the number of

letters in the word. The number of letters is presented as a series of dashes or

underscores, like this: _ _ _ _ _ _

? At each turn, the user guesses one letter. If the guess is correct, the letter is

displayed in the correct position for the user to observe, like this: M _ _ M _ _

? If the guess is incorrect, the user’s number of chances to “live” is decreased.

Initially, the user has 6 chances. If all 6 chances are exhausted before the user

guesses all the letters correctly, the user loses the game. If the user guesses all the

letters, making the correct word, the user wins.

Program requirements:

? You are required to use methods and parameter passing appropriately. Each

separate task should be done by a separate method

? Use an array of String objects to hold a library of at least 20 guessable words

? One of your methods should be responsible for choosing a different word from

the library each time a game is to be played. This method should be written so as

to ensure that no single word is used twice until all words have been used at least

once. Words should be chosen at random, so that the next time the program is

run, different words might be chosen. Hint: use a frequency-counting array.

? Display words in progress using underscores with spaces between them to

represent the missing letters (see sample run of the program, below)

? The user should be able to play as many games as s/he wishes to during a single

run of the program.

? The program should keep track of the user’s incorrect guesses. The user should

not be penalized for making the same wrong guess twice. Instead, the program

should inform the user that s/he has already tried that letter. Again: frequency

counting!

Extra credit options (worth 10 points each):

? Instead of hard-coding a library of words into your program, read words from a

dictionary file containing a word list. For this option, provide a dictionary file

along with your source code when you turn in the program.

? Add a graphical user interface (GUI) that draws the hangman figure and changes

the drawing each time the user guesses a wrong letterComputer Science I Fall 2013

Sheller Page 2

Sample program run: (with user responses)

Your word: _ _ _ _ _ _ You have 6 guess(es) left. Your guess: E

Your word: _ _ _ _ _ _ You have 5 guess(es) left. Your guess: S

Your word: _ _ _ _ _ _ You have 4 guess(es) left. Your guess: M

Your word: M _ _ M _ _ You have 4 guess(es) left. Your guess: O

Your word: M _ _ M _ _ You have 3 guess(es) left. Your guess: E

You already guessed E. Try again.

Your word: M _ _ M _ _ You have 3 guess(es) left. Your guess: Y

Your word: M _ _ M _ _ You have 2 guess(es) left. Your guess: N

Your word: M _ _ M _ _ You have 1 guess(es) left. Your guess: R

Your word: M _ R M _ R You have 1 guess(es) left. Your guess: I

Sorry, you’re dead. The word was MURMUR

Play again? (Y/N): Y

Your word: _ _ _ _ _ _ You have 6 guess(es) left. Your guess: A

Your word: A _ _ _ _ _ You have 6 guess(es) left. Your guess: O

Your word: A _ _ _ _ _ You have 5 guess(es) left. Your guess: I

Your word: A _ _ I _ _ You have 5 guess(es) left. Your guess: E

Your word: A _ _ I _ _ You have 4 guess(es) left. Your guess: S

Your word: A _ _ I _ S You have 4 guess(es) left. Your guess: N

Your word: A N _ I _ S You have 4 guess(es) left. Your guess: D

Your word: A N _ I _ S You have 3 guess(es) left. Your guess: C

Your word: A N _ I _ S You have 2 guess(es) left. Your guess: L

Your word: A N _ I L S You have 2 guess(es) left. Your guess: V

Your word: A N V I L S You got it! Congratulations, you live!

Play again? (Y/N): N

Goodbye

Subject Computer
Due By (Pacific Time) 12/05/2013 12:00 am
Report DMCA
TutorRating
pallavi

Chat Now!

out of 1971 reviews
More..
amosmm

Chat Now!

out of 766 reviews
More..
PhyzKyd

Chat Now!

out of 1164 reviews
More..
rajdeep77

Chat Now!

out of 721 reviews
More..
sctys

Chat Now!

out of 1600 reviews
More..
sharadgreen

Chat Now!

out of 770 reviews
More..
topnotcher

Chat Now!

out of 766 reviews
More..
XXXIAO

Chat Now!

out of 680 reviews
More..
All Rights Reserved. Copyright by AceMyHW.com - Copyright Policy