CSE 1310 - Assignments - Programming Assignment 8

The assignments will be graded out of 100 points. Create a text document entitled answers.xxx (where you replace xxx with whatever extension is appropriate, depending on the file format you use). Acceptable file formats are plain text, Word document, OpenOffice document, and PDF. Put your name and UTA ID at the top. Your answers that are not part of a program will be added to this file. Each task below will instruct you where to put your answers.


Hangman (Tasks 1, 2, 3, 4)

You will be programming the game called hangman. If you are unfamiliar with the game, you can read about it here. In our version of the game, three play modes are supported:

  1. In the first mode, the secret word is hardcoded, and it is 'python'. The human player loses if they guess six times a letter that does not appear in the word.
  2. The second mode supports two human player. When the game starts, the first player is asked to enter the word that he/she chooses. Presumably the second player is not looking while the word is entered. After the first player enters the word, the computer prints a new line 100 times, to make sure that the word does not appear on the screen anymore. Then, the other player tries to guess it.

    The computer will handle the play and the answers once the first user has chosen the word. The second player loses if they guess six times a letter that does not appear in the word.

  3. In the third mode, the computer chooses the word: The file word_list.txt, contains a list of the 5014 most commonly used words in U.S. English. The computer will select one word at random from that file, but you should make sure that the chosen word is least 5 letters long (some words on that file are shorter than five letters). After the computer chooses the word, the human player tries to guess the word. As before, the human player loses if they guess six times a letter that does not appear in the word.

After selection of one of the modes of play, and after a word has been picked as described above, your program should work as follows:

  1. Print the hangman thus far. See below for details.
  2. Print the characters matched thus far (i.e. _ y _ _o n) The exact display format for matches is not important.
  3. Prompt the user for a letter.
  4. If the guessed letter is in the secret word, update the correct matches and go to to step 1.
  5. If the guessed letter is not in the word, update the number of errors and the hangman display and repeat.
  6. If the user guesses incorrectly six times, they lose.

This is the hangman graphic. Yours does not have to be exactly the same.

For 0 incorrect guesses:
________
       |
For 1 incorrect guesses:
________
       |
       O
For 2 incorrect guesses:
________
       |
       O
      /|\
For 3 incorrect guesses:
________
       |
       O
      /|\
     / | \
For 4 incorrect guesses:
________
       |
       O
      /|\
     / | \
      / \
For 5 incorrect guesses:
________
       |
       O
      /|\
     / | \
      / \
    _/   \_
For six incorrect guesses, print
YOU LOST, THE GAME IS OVER!

Task 1 (25 pts.)

In your answers.xxx file, describe all functions you use and specify their name, arguments and return values. Also, for each function, describe in English what the function computes.R emember that this is NOT the place to describe HOW a function will be implemented, just to describe WHAT the function does.


Task 2 (25 pts.)

Implement your functions and save them in hangman_functions.py.


Task 3 (25 pts.)

Write a program named hangman_tests.py that tests your individual functions with test cases you deem interesting. The strings, lists, or any other data structures you need to test your functions do not need to come from prompting the user. You can hard code anything you'd like. For example, if you had a display_hangman(errors) function and you were testing various numbers of errors, you do not need to get these from the user.


Task 4 (25 pts.)

Write a main program, named hangman.py that uses your functions to allow a user to play hangman.


Suggestions

Pay close attention to all specifications on this page, including file names and submission format. Even in cases where the program works correctly, points will be taken off for non-compliance with the instructions given on this page (such as wrong file names, wrong compression format for the submitted code, and so on). The reason is that non-compliance with the instructions makes the grading process significantly (and unnecessarily) more time consuming. Contact the instructor or TA if you have any questions.

How to submit

The assignment should be submitted via Blackboard. Submit a ZIPPED directory called assignment8.zip (no other forms of compression accepted, contact the instructor or TA if you do not know how to produce .zip files). The zipped directory should contain your answers.xxx document and all the Python code files.

Submission checklist