Java程序辅导

C C++ Java Python Processing编程在线培训 程序编写 软件开发 视频讲解

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439
CS 152 Computer Programming Fundamentals
Lab 5: Hangman∗
Fall 2016
1 Game Rules
Players: 2, the knower and the guesser (in our version, the computer is the knower)
Object: The guesser attempts to determine the knower’s word in a limited number of
guesses.
Play: The knower secretly chooses a word and writes down that many blanks. On each of
the guessers turns, she guesses a letter. The knower indicates all locations where that
letter appears in the word; if there are none, the knower instead draws another part
on a diagram of a hanged man: head, torso, left arm, right arm, left leg, right leg.
(Our version will keep count of how many guesses are left and draw a ASCII art stick
figure.)
Victory: The guesser wins if all letters in the word are guessed. The knower wins if the
hanged man is completed (that is, if the guesser runs out of guesses).
2 Program description
I have provided you with some starter code in a file named Hangman.java. There are three
methods you must complete to be able to play the hangman game.
In addition, I have provided you with testing code in HangmanTester.java. Place this
file in the same project as Hangman.java and you will be able to test your methods without
playing the game. This is particularly useful when you haven’t fully implemented them yet.
3 Turning in your assignment
Submit your Hangman.java file to the Lab 5 assignment in UNM Learn. Do not attach
.class files or any other files.
∗This lab is based on the project at http://ljing.org/games/snowman/
1
4 Sample game transcripts
The ASCII art was omitted to save space. Try playing the actual game to see it.
Welcome to Hangman! Try to guess my word.
Guesses remaining: 6
Word: __________
Guess a letter: a
Guesses remaining: 6
Word: _a_a_a____
Guess a letter: s
Guesses remaining: 6
Word: sa_a_a____
Guess a letter: e
Guesses remaining: 6
Word: sa_a_a__e_
Guess a letter: r
Guesses remaining: 6
Word: sa_a_a__er
Guess a letter: w
Sorry, there is no w
Guesses remaining: 5
Word: sa_a_a__er
Guess a letter: l
Guesses remaining: 5
Word: sala_a__er
Guess a letter: m
Guesses remaining: 5
Word: salama__er
Guess a letter: d
Guesses remaining: 5
Word: salama_der
Guess a letter: n
Word: salamander
Hooray! You win!
Welcome to Hangman! Try to guess my word.
Guesses remaining: 6
Word: ____
Guess a letter: a
Guesses remaining: 6
Word: __a_
Guess a letter: e
Sorry, there is no e
Guesses remaining: 5
Word: __a_
Guess a letter: s
Sorry, there is no s
Guesses remaining: 4
Word: __a_
Guess a letter: r
Sorry, there is no r
Guesses remaining: 3
Word: __a_
Guess a letter: t
Guesses remaining: 3
Word: t_a_
Guess a letter: l
Sorry, there is no l
Guesses remaining: 2
Word: t_a_
Guess a letter: n
Sorry, there is no n
Guesses remaining: 1
Word: t_a_
Guess a letter: i
Sorry, there is no i
Word: t_a_
You lose. The word was: toad
2