600.108 Intro Programming Lab, Week 3

Getting Started: If your partner from last week's lab is present, please sit and work together again this week. Check with the lab leaders if you forget who your partner was, or if you need a (different) partner for this week for some reason.

Do the Blackboard quiz "week3" to get started.

The Problem: HANGMAN

Write a program to play hangman. In this game, there is a secret word which is read from a file called "hangwords.txt". The user has to try to guess the word and should have the following options available at any time during game play (you can use a menu, or make up another mechanism):

	- make a single letter guess
	- make a whole word guess
	- start a new game (if there are words left in the input file)
	- quit the program
   

For each correct single letter guess, all occurrences of that letter should then be displayed for the user in the appropriate position in the secret word. For each incorrect letter guess, a body part is added to the hangman's noose. If the hangman figure is completed before the word is guessed, the user loses. If the user tries a whole word guess but is wrong, they also lose the game. If they complete or guess the word before the hangman is completed, then they win. Your program should continue playing the game until the user chooses to quit, or until there are no more words in the file. Assume there is one word per line of the input file.

Step 1) ANALYSIS: Create a sample run (play the game on paper) to show the user interface of the program and possible input/output scenarios. Instead of having your program draw a hangman figure (we'll add this later), just plan for it to say how many body parts are left. Decide on a user interface for making the guesses - try to make it easy to use. Ask your lab leader if the problem needs clarification. Show your sample to a lab leader before proceeding.

--- Switch driver/nagivator roles ---

Step 2) DESIGN: Create a text file with a design structure. Because this problem is rather complicated, you should use several subroutines to help organize the processing. Start by writing pseudocode for your main method which uses calls to those subroutines to do much of the work. By writing main first, it should be fairly easy to see which tasks are too complicated to figure out easily. Those are the things you should create subroutines for, but you don't have to specify the full details of the subroutines right now. Have a lab leader check your main pseudocode and explain your subroutine ideas to him/her.

--- Switch driver/nagivator roles ---

Step 3) MORE DESIGN: Now you need to clarify the processing for each subroutine by writing pseudocode for them. Think about what data each will need passed to it through the parameters, and what data if any it might need to return to the main processing. Have a lab leader check over your subroutine pseudocode before continuing.

--- Switch driver/nagivator roles ---

Step 4) CODING: You can download a java program which contains a partial solution: HangmanStart.java. Save it as Hangman.java. Our approach and method breakdown is likely to be somewhat different from yours (and is different from the sample run posted on Piazza @18).

--- Switch driver/nagivator roles ---

Step 5) TESTING: Play the game a bit to determine if it is working correctly. Fix any problems that you find. Make sure your final version is Checkstyle compliant, with the exception of the cyclomatic complexity issue. That stems from having a method (main in this case) that is too complex with respect to nested control structures, which would make it hard to fully test. (Eliminating the problem in this case would require a large restructuring of the program, ideally with a more object oriented design.) Remember to recompile and test the program as you fix any style issues.

Step 6) CLEAN-UP: Zip all the files together from today's lab and email to both students. Then each student must submit their work on Blackboard for the week, noting their partner's name and JHED login in the submission textbox. You must then delete your files off the lab computer and logout before leaving! Failure to do so constitutes an ethics violation.