Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Filename (driver): hangman_game.py Filename (functions module): hangman.py Filename (test suite): hangman_test.py For this assignment, youll write a game of Hangman. Rules: -The player is shown

Filename (driver): hangman_game.py

Filename (functions module): hangman.py

Filename (test suite): hangman_test.py

For this assignment, youll write a game of Hangman.

Rules:

-The player is shown several blank spaces to represent the letters in a word.

-The player attempts to figure out what the word is by guessing individual letters.

-For each incorrect guess, a new piece of the spaceship is assembled. On the fifth incorrect guess, the spaceship is complete and the round is over. If the user solves the word with fewer than 5 incorrect guesses, they win the round.

User's View:

A random word is shown to user, shown by a ___ for each letter.

User guesses a letter in the word. If user guesses correct letter, that letter appears in all its corresponding blank spots. If Im incorrect, a part is added to the hangman figure.

Ending the round:

If the user solves the word with fewer than 5 incorrect guesses, the user wins the round! The user earns one point for every word they guess correctly.

If the user makes 5 incorrect guesses, the entire hangman figure is constructed and the user loses the round

Once the round is over, I have the chance to play again.

When the user is ready to quit, then:

Ask the user their name, which they type in.

The user's name is stored for later use, along with my score, in a scores file.

The program exits.

Gameplay -- What Your Program Does

For each round, randomly choose one dictionary word to be the target word.

Draw space-separated blanks using Turtle, to indicate the number of letters in the word.

Prompt the user to guess a letter, on the terminal.

If the guess is correct, find all occurrences of the letter in your target word. Draw the letter on the screen in all the places it occurs in the word.

If the guess is incorrect, add the next part to the ship.

The user loses on the 5th incorrect guess. It goes: body, left rocket, right rocket, left flame, right flame (and over!).

Write the incorrect letters on the screen, so the player can see what theyve guessed.

Finishing the round:

The user wins by correctly guessing all the letters in the word. Announce they won.

The user loses with 5 incorrect guesses. Announce they lost, and what the word was.

Prompt the user to play again.

If they dont want to play again, prompt for their name and update the score file (users score: one point per correct word).

If they do want to play again, start over with another word.

This is the only way to exit the program. The user cant quit in the middle of a game, unless they center ctrl+C.

Scores File

Your program will prompt the user for their name at the end of gameplay and save their name and score (# of rounds won) in a file. The file is named scores.txt. The format is one score per line with a space between the users name and their score.

The highest score is always the first entry in the file. When a new high-scorer gives their name, they go first in the file. If the new person is not the high-scorer, they go at the end of the file.

Technical requirements. Your program must...

Read from the dictionary file (wordlist.txt), and write/append to the scores file (scores.txt). If theres an error for either one, exit gracefully using a try/except block. However, it is not an error if the scores file doesnt exist; in fact, we wouldnt expect it to exist the first time your game is played.

Close every file you open.

Update the scores file at the end of every game -- after the user has chosen to quit, regardless of how many rounds they have won/lost.

You can assume, when you prompt the user for their name, they enter something.

Select the dictionary word for each round at random. You are not required to ensure uniqueness (i.e., its OK if you end up repeating words if the user plays multiple rounds), but the words should not go alphabetically or follow any discernible pattern.

Process user guesses as follows:

The dictionary file is all lowercase. Allow the user to type in upper- or lower-case letters.

You dont need to check if the user has entered the guess already. They can end up losing by stupidly guessing the same incorrect letter over and over.

You dont need to check if the user enters a number, or some other non-alpha input. Thats fine, its just a wrong guess.

You DO need to check if the user has entered a string longer than 1 character. If so, repeatedly prompt them until they enter a single character.

When prompting the user to play again, you dont need to validate their input. Assume they type a Y or an N.

Use well-written functions. They should be concise, clear, and well-commented.

How do you get the AMAZING points for this program? (In addition to meeting the specs, writing good comments, and having good function structure):

Draw a cool spaceship. Weve provided some sample code below; improve or replace it with something better.

Write all of your functions in 30 lines or fewer.

Completely separate your graphics functions from your gameplay functions. Each function should be concerned with drawing on the screen, or with the functionality of the game, but never both.

Test Suite

You dont need to write test code for functions concerned with graphics, but you need to write test code for all other functions.

Each output from your test suite should include:

Which function is being tested

The test input

The expected output

Whether it passed or failed

Write a block comment at the top of of hangman_test.py describing:

Which functions you tested

What you set up as good and bad inputs for each function

Whether youre confident youve verified every possible eventuality

Drawing the hangman figure

The hangman figure must create a rocket ship

# Draw the body

ship.penup()

ship.goto(0,175)

ship.pendown()

ship.goto(-50,100)

ship.goto(-50,-100)

ship.goto(50,-100)

ship.goto(50,100)

ship.goto(0,175)

# Left rocket

ship.penup()

ship.goto(-70,-50)

ship.pendown()

ship.goto(-40,-130)

ship.goto(-100,-130)

ship.goto(-70,-50)

# Left flame

ship.penup()

ship.goto(-100,-130)

ship.pendown()

ship.goto(-90,-150)

ship.goto(-80,-130)

ship.goto(-70,-160)

ship.goto(-60,-130)

ship.goto(-50,-150)

ship.goto(-40,-130)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

5. Describe how contexts affect listening

Answered: 1 week ago