CS102B Course Project: The Hangman Game
Fall 2018, SUSTech
Background
Hangman is a paper and pencil guessing game for two or more players. One player
thinks of a word and the other(s) tries to guess it by suggesting letters within a certain
number of guesses. In this project, we restrict the number of players to two.
The word to guess is represented by a row of dashes, representing each letter of the
word. If the guessing player (or guesser) suggests a letter which occurs in the word,
the other player writes it in all its correct positions. If the suggested letter does not
occur in the word, the other player draws one element of a hanged man stick figure as
a tally mark. The guesser can win by guessing all the letters that appear in the word,
thereby completing the word, before the diagram is completed.
The following example illustrates a player (the guesser) trying to guess the word
“hangman”, which is selected by the other player, using a strategy based solely on
letter frequency. As the player continues, a part of the stick figure on the noose is
added. Once a full body is drawn, the game is over, and the guesser loses the game.
1
Word:
Misses:
Guess:
_ _ _
E
2
Word:
Misses:
Guess:
_ _ _
E
T
3
Word:
Misses:
Guess:
_ _ _
E, T
A
4
Word:
Misses:
Guess:
A _ A
E, T
O
5
Word:
Misses:
Guess:
A _ A
E, O, T
I
6
Word:
Misses:
Guess:
A _ A
E, I, O, T
S
7
Word:
Misses:
Guess:
A _ A
E, I, O, S, T
N
8
Word:
Misses:
Guess:
A N _ A N
E, I, O, S, T
R
Game
Over
Word:
Misses:
Guess:
A N _ A N
E, I, O, R, S, T
The guessing player has lost this game as the diagram had been completed before all
the letters were guessed. Learn more about the hangman game via the links below:
https://www.webhangman.com/ha...
https://www.hangman.org.uk/ho...
Project Requirements
Your task is to implement the two-player hangman game. The computer will think of
a word and the user will guess the word. You should find a team mate to finish the
project. It is also fine if you work alone. Below are the detailed requirements.
- File Processing
We provide a list of English words as a text file (words.txt). Each line of the file
contains exactly one word. Your program should be able to read the file and load the
words into memory. The file name and path should be customizable, meaning that
your program should be able to process any given text file conforming to our format
(each line contains one English word). - Duplicate Word Removal
The input text file may contain duplicate words. Your program should identify the
duplicates and remove them. - Word Ranking and Categorization
Classify the loaded words into three categories according to the length and letter diversity
of the words: (1) easy words, (2) words of medium-level difficulty, (3) hard
words. Below are formulas for estimating the difficulty of a given word .
:∈<
In the second formula, measures the frequency of each letter in the word .
The steps below illustrate how to calculate the uncertainty of the word “genetic”.
Suppose the highest and lowest scores are and, respectively. Your program
should categorize the words whose score is within the range C??,
EF
G - 2 ×
:F
GI as
“easy words”, the words whose score is within range C
EF
G - 2 ×
:F
G , 2 ×
EF
G - :F
G I as
“words of medium-level difficulty”, and the words whose score is within range
C2 ×
EF
G - :F
G ,J as “hard words”. After categorization, your program should rank the
words in ascending order according to their difficulty score. If two words have the
same score, your program should rank them according to the lexicographical order.
Your program should also write the ranked results into a text file rankedWords.txt,
in which each line contains a word, its difficulty score, and its difficulty level separated
by a comma (e.g., “one, 6, easy”). - Level and Word Selection
The program should allow the user to choose a difficulty level: (1) easy, (2) medium,
or (3) hard. After the user chooses a level, the program should randomly select a word
of the corresponding difficulty level as the word to guess and tell the user the number
of letters in the word to start the game. - The Game Details
Each time the user makes a guess, he or she can choose among all letters except the
missed letters in the previous guesses. Your program should display previous missed
letters to the user to ease the guessing process. After each guess, your program should
judge if the guess is correct or wrong. If it is a correct guess (the guessed letter is in
the word), your program should display all occurrences of the letter in the word. Otherwise,
your program should add a new part to the hangman. The hanged man has six
parts: head, body, left arm, right arm, left leg, and right leg. So the user can only make
six wrong guesses. If the user successfully guesses all letters before making six wrong
guesses, your program should display “Congratulations! You win the game J” on the
console. Otherwise, your program should display “Sorry! Game Over L”. Please note
that drawing the hanged man on the console is not mandatory. It is fine if your program
only displays simple texts to interact with the user like the example below.
You made a wrong guess.
All misses so far: E, I, O, S, T
You can only make one more wrong guess(es).
Bonus
If your program satisfies all the basic requirements above, you will get 80% of the
total score of this project. The remaining 20% will be given as bonus. You are encouraged
to go beyond our requirements. Below are some possible ways to get bonus.
Draw the hanged man on the console. We provide a project (DrawingDemo.zip,
which can be imported into Eclipse) that can draw different shapes such as rectangles
(you can draw the head of the hanged man as a rectangle) and lines on console.
You can follow our demo to draw the hanged man.
Play sound by invoking Java APIs
Novel ranking mechanisms (our basic ranking mechanisms must be implemented)
Graphical user interfaces with Swing, JavaFX etc.
Be creative and have fun
WX:codehelp
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。