CSE/ENGR 142 Homework 5

Whack-A-Mole! 

July 30, 1999

When working at the computer, everyone needs to take a break once in a while. Since computer games are such a popular diversion, here is your chance to write your own computer game... Whack-A-Mole! This game involves moles popping up in different spots on the computer screen, and it is the player's job to knock the moles off the screen (by clicking on them with the mouse).


As with Homework 4, this assignment will use the GP142 graphics package. You will also have the opportunity to program with structs and 2-Dimensional arrays.


Due Dates:

There are two parts to this assignment with two different due dates.

Part A:  Due Friday, August 6 at 5:00 p.m.: a call graph of the original file.

Part B:  Whack-A-Mole program, final version submitted via electronic turn-in by 5:00 p.m. on Friday, August 13. Usual deadline policies apply.  This assignment will also have a small extra-credit opportunity!


What you have to start with

This homework uses the GP142 graphics package.  This is the same graphics package used in HW4, and you can read all about it on the Web, or in the course packet.  

You have a sample executable program to experiment with.  Many of the following instructions won't make sense until you have tried it.    Play with it to figure out what it can do.   The final version of your program does not have to behave exactly like this.

To start work off, you have a .c file called hw5_orig.c.  Your first jobs is to study it,  get it to compile, then run it and figure out what it does.  [There's an important note below about compiling the program.] You should look over the code, and to help ensure you understand at least the "big picture," make a call graph showing all the functions called in hw5_orig.c.  This is due as Part A of the homework.  The call graph should include a box for every function which is defined in or called from hw5_orig.c; it doesn't have to include any functions which are not either defined in or called from hw5_orig.c.  (For example: it should not include any functions which you plan to write later.  It should not include functions which may be defined in GP142.c but which are not called from hw5_orig.c). 

Keep a copy of your call graph to refer to as you continue to study the program.    As you modify the program, keep the graph updated to reflect your changes.   If you are in the IPL and ask a consultant to help you, have that updated copy of the call graph on hand; it will help both of you understand your program.

 

What you need to end up with

For Part B of the homework,  improve the program so that it is at least as fun and interesting as the sample executable program.  It doesn't have to do exactly the same things as the sample executable, but here's what it should do at the least:

  • The program should have moles appear at different times, in different spots, for different periods of time. (See the hints on random numbers on the annoucenments page)
  • Different moles should appear as good moles or bad moles.
  • There should be a status bar to keep track of the player's score and how many lives they have left.
  • Both buttons should work correctly.
  • Mouse clicks outside the board or button area should be ignored. There does not have to be any error message, but your program needs to do something intelligent internally.

In this assignment, if you want the moles to pop up at different random times in different random locations on the board, then you will have to understand some basics about using random numbers. There are some hints on the annoucements page to help with this.

Information about the 4 x 4 board is stored in a 2-dimensional array. Each element of the array must be a structure consisting of several fields: whether there is a mole in the given board square, whether the mole is a good mole or a bad mole, how long the mole will stay on the screen, whether the mole has been whacked, and anything else which is appropriate...

Here are some ideas for possible ways to improve the program:

  • Have lots of different types of moles, each worth a different number of points.
  • Have a timer running throughout the game. Maybe the game ends when the timer reaches zero, or maybe the user plays against the clock - trying to see how many moles he or she can whack before the timer runs out.
  • Let the user choose whatever board size they want, so the user could play on a board of size 3 x 6, 4 x 4, 7 x 5, etc.
  • Have different skill levels (easy, medium, difficult) where the moles show up for shorter periods of time at harder skill levels.
  • Have the game become more and more difficult as the player's score increases.

Feel free to be creative!

Caution:  Be realistic and don't try to do too much all at once. It is much more important to have something fairly simple that works instead of something overly complex that you can't finish in time. Start with a simplified version of your ultimate program, get that working, and then add to it.

For a small amount of extra credit, make your program so interesting that the TA cannot stop playing the game. They are forced to exclaim, "Wow!  This is incredible.   Hey, everybody, come and take a look at what this program does!"  You do not have to use fancy features of C.   The extra-credit judgement will be based on what the program does, not on how it does it.  It will only be a couple of extra points at most. 

Working with GP142

If you are using Windows, we strongly advise that you compile and modify the program ONLY via the .dsw file that will be supplied in the self-extracting archive.  Here's why.  GP142 programs differ from previous projects in some important ways.  First, they have multiple .c files (gp142.c in addition to your own).  Second, they use a special .h file that must be available to the compiler.    Third, they are built as "Windows Applications" rather than "Console Applications."  All of this means that you cannot create a "default project workspace" to compile and run your program in.  If you click on the .dsw file we give you (.dsp for users of older versions of MSVC), all this is taken care of.

If you really need to know how to create your own project, look at the tips on-line.