CS 340 - Project 4

Hangman

Due: November 13, 2008 at 11:59 pm

For this project, you are to use the Java Swing Libraries to create the word-guessing game of Hangman. In this game, a number of blank spaces are displayed. The number of blank spaces correspond to the number of letters in the word to be guessed. The player then guesses a letter. If the letter is in the word, all occurrences of that letter in the word are shown in their proper order. If the letter is not in the word, a body part is drawn on the gallows. The letter guessing continues until either all the letters in the word has been guessed (and the player wins) or the entire body is drawn on the gallows (and the player loses). You are to have the following 8 body parts drawn as incorrect letters are guessed:
  1. Head
  2. Body
  3. Right Arm
  4. Left Arm
  5. Right Leg
  6. Left Arm
  7. Eyes
  8. Mouth
You are to draw these items and the hangman's gallows using the Graphics class in Java.

The words selected for the game are to be taken from a list that can be supplied by the user. Your project is to have a menu item that will allow the user to select a word file that will contain the words in an ascii text file with one word per line in the file. If the user does not select a file, your project should have a default list of words that is to be used. As your program selects words from the overall list of words, it should randomly select each word but it should not selected a word a second time unless all of the words have been selected once.

Your project is also to have the following additional menu items:

Your program is to provide buttons for all 26 letters and it should also provide key listeners so the user can type the keys on the keyboard instead of pressing the buttons. A button should become disabled once it is selected so that the user can't selected the same letter twice during a game.

The area displaying the letters in the word to be guessed must be dynamic so that it displays the correct number of letters for word being guessed.

This program will also require a 1-2 page write up of the data structures used in the program and the logical division of your program into multiple source code files (i.e. which routines are where). Remember that this write-up is to be written in ASCII format and is to be electronically turned in with your program. The name of this file should be "readme.txt". Also recall that your program will be given to another student to write a critique. Therefore, it is suggested that you do not include your Social Security Number in your program. Instead use your name and your CS User ID to identify yourself.

You program can earn up to 15 points of extra credit by having an ability to change the difficulty level of your program. The program as described above is the basic/simpliest level. Ideas for adding complexity is to reduce the number of times the body part are drawn before the game is lost (i.e. draw both arms at once, draw the eyes and mouth at the same time, etc), or add a timer that forces the user to select a letter within a set time period. These 15 points are given at the discretion of the grader and adding a very eary-to-implement complexity may not give you all 15 extra credit points.

Your program must be written in good programming style. This includes (but is not limited to) meaningful identifier names, a file header at the beginning of each source code file, a function header at the beginning of the function, proper use of blank lines and indentation to aide in the reading of your code, explanatory "value-added" in-line comments, etc.

The work you turn in must be 100% your own. You are not allowed to share code with any other person (inside this class or not). You may discuss the project with other persons; however, you may not show any code you write to another person nor may you look at any other person's written code.

You are to submit this project using the CS Department's UNIX machine's turnin command. The project name for this assignment is proj4. Be sure to submit all source code, header files, makefile as well as your program description. Failure to turnin all required pieces will result in a lower grade for the assignment.