联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp

您当前位置:首页 >> Java编程Java编程

日期:2018-12-16 09:44

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/hangman.php

https://www.hangman.org.uk/how-to-play.htm

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.

1. 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).

2. Duplicate Word Removal

The input text file may contain duplicate words. Your program should identify the

duplicates and remove them.

3. 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”).

4. 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.

5. 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 J


版权所有:编程辅导网 2021 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp