CS21 Homework 5
Due Sunday, September 28 by 11:30pm


Introduction

This assignment serves two purposes. First, it is designed to give you more practice using top-down design to decompose a problem into a series of functions. Second, it gives you a chance to learn to use the graphics library. For a graphics example that uses function decomposition, review the house.c program from chapter 7 of our textbook. Before you write any code, it is important to sit down and think about what needs to be done and how to organize your solution strategy into a well-structured program.

You are welcome to work with a partner for this assignment.


Graphics for a game of Hangman

Later in the semester, once we learn how to do string manipulation, we will write a program to play the game of Hangman. For now, we will write a program to handle just the graphics portion of the game.

When played by children, the real fascination of Hangman comes from the fact that incorrect guesses are recorded by drawing an evolving picture of the player being hanged on a scaffold. For each incorrect guess, a new part of a stick-figure body (first the head, then the torso, then each arm, each leg, and finally each foot) is added to the scaffold until the hanging is complete. The program should begin by drawing the scaffold. Then the program should prompt the user to determine whether or not to continue, as shown below.

Continue (1=yes/0=no)? 
If the user wants to continue, then the next body part should be drawn. As long as the user wants to continue, this prompt should be repeated (at most eight times). Once the stick figure is complete, the program should automatically end.

Getting Started

In order to make your program easy to modify, you should define a set of constants for the important features of the picture to be drawn. You may use the constants provided below, or modify them or add to them to create a different picture.

#define ScaffoldX      0.5   // x coordinate of scaffold base
#define ScaffoldY      0.5   // y coordinate of scaffold base
#define ScaffoldHeight 2.5   // height of vertical scaffold section
#define BeamLength     1.0   // length of top of the cross beam
#define RopeLength     0.25  // length of rope between head and beam
#define HeadRadius     0.25  // radius of the head
#define BodyLength     0.8   // length of the stick figure's body
#define ArmOffset      0.2   // distance from head to shoulders
#define UpperArmLength 0.5   // horizontal length of upper part of arm
#define LowerArmLength 0.3   // vertical length of lower part of arm
#define HipWidth       0.25  // horizontal length between body and leg
#define LegLength      0.75  // vertical length of leg
#define FootLength     0.2   // length of the foot
#define GroundGap      0.2   // distance from ground to bottom of feet

Remember that your main program should be short and abstract. Most of the details for solving the problem should be divided up into functions. Create a function with the following prototype to draw each body part:

void DrawBodyPart(int part);
where an argument of 0 draws the head, an argument of 1 draws the body, and so on. This function, should in turn call other functions to actually draw each part. Be on the lookout for ways to reuse code. Can you have a single function to draw both arms or will you need a function to draw the left arm and another to draw the right arm?

Extra Credit

The stick figure I showed you in class is quite simple. Enhance the figure to make it more visually interesting. You could add fingers and toes, facial expressions, hair, ears, clothes, etc.


Handing in your solution

Use cs21handin to turn in your program. Remember that if you work with a partner only one of you needs to turn in the code, but you should both indicate that you partnered together.