Saint Louis University |
Computer Science 150
|
Dept. of Math & Computer Science |
Your goal is to provide an implementation of the classic game Hangman, as outlined in Exercise 5.36 on page 201 of the text. More detailed requirements are given below.
For this assignment, you are allowed to work with one other student if you wish (in fact, we suggest that you do so). If any student wishes to have a partner but has not been able to locate one, please let the instructor know so that we can match up partners.
Please make sure you adhere to the policies on academic integrity in this regard.
The text gives an overview of the game. Here we make the following requirements explicit:
When displaying the current puzzle, you should show all non-alphabetic characters in their original form, and you should show any of the previously-guessed letters in their original case. All unguessed letters should be replaced by the undescrore character (_).
For example, here is an example of a partially completed puzzle.
(any guesses???)
Before each of the player's guesses, display the following information to the player:
If the user guesses a letter that was previously guessed, do not count this against their score. Instead, given an appropriate error message and let them make a new guess.
After a new letter is guessed, the user should either be informed that it is not in the puzzle, or the puzzle should be re-displayed with all occurrences of the guessed character uncovered.
You may safely assume that the underscore character (_) does not appear in any of the secrets, and that each secret has at least one alphabetic character.
When originally developing your program, it will probably help for you to debug your software while relying on a known answer. That way you will be able to monitor whether the software behaves as is expected.
For the final product, we want a user to play the game without knowing the secret in advance. We offer the following function that allows the software to pick a secret uniformly at random from an underlying file of possibilities (assumed to have one entry per line).
We also offer a data file that contains the titles of over 1800 movies. We have placed the file on turing, or you may download it (movies.txt), if working on your own machine.
from random import randrange def pickSecret(filename='/Public/goldwasser/150/programs/hangman/movies.txt'): secret = '' linenum = 0 for word in file(filename): linenum += 1 if randrange(0,linenum)==0: secret = word.strip() return secret
Note: the default filename used here is presuming that you want the movie list and that you are working on turing. You can provide some other filename by sending an explicit parameter.
You should create a new file, hangman.py, that contains all of the code. This file must be submitted electronically.
You should also submit a separate 'readme' text file, as outlined in the general webpage on programming assignments. For this assignment, please explain any interesting design decisions that you made about the user interface or about your implementation techniques. If you worked as a pair, please make this clear and briefly describe the contributions of each person in the effort.
Please see details regarding the submission process from the general programming web page, as well as a discussion of the late policy.
The assignment is worth 10 points.
Use a graphical interface to animate a game in progress, rather than relying solely on the text-based interface.