COSC 198 - Programming Computer Games
Exam 2
Spring 1999

Write your answers clearly on the separate paper provided.

Do your own work. You may consult the Java API and the course website, but you are not allowed to use email, talk, chatrooms, or any other method of communication during the exam.


1. Here is a version of the Prim's algorithm maze applet which we discussed in class. Here is the Java source file and the HTML source file.

(a) Explain how we can change the maze to a 20 by 15 grid without changing or recompiling the Java source.

(b) Suppose we wished to be able to adjust the cell width and cell height separately. In other words, rather than just squares, we might want to use tall, skinny rectangles for the cells in the maze and we want to be able to change that shape from the HTML file alone (like in part (a)). Explain what we would need to change in the java and HTML files to make this possible.

2. The tortoise and the hare are having a race in front of Cudahy. Unfortunately, while the tortoise moves across the background quite nicely, the hare is surrounded by a white box. Here is the Java source for the applet. Explain what is wrong with the hare and how we might fix it.

3. Suppose that we wish to enhance the applet in Question 2 by adding some sound. In particular, I would like a loud bang to sound at the beginning of the race (for the starter's gun). Explain what changes would need to be made in the Java code to add this sound effect.

4. In the Alien Landings game described in the book, the gun can only fire one missile at a time. Suppose we wanted to change this so that several missiles can be in the air at once. The code is spread across several files: GameManager.java, Sprite.java, UFOManager.java, GunManager.java, and UFO.java. I don't think you'll need to refer to the code much for this question, but I decide to link it here anyways.

(a) Describe how the Java class Vector could be used to store the missiles. Give two specific features of the Vector class which would be useful in implementing multiple missiles.

(b) The book actually suggests using an array of MissileSprites rather than a Vector. Explain why this might be a better approach.

5. The Depth-first search maze applet produces a perfect maze. That is, there is a unique path from any cell to any other cell in the final maze. Suppose we wish to modify the applet so that, after the perfect maze is completed, we knock down an additional ten walls (to provide more paths through the maze). Explain carefully (or give the new code) how to change the Java source code to accomplish this.

6. Given the following simple applet, maneuver the blue box to be inside the hollow red box at the top of the screen. Here is the source code for the applet. It also uses some of the sprite classes from the text.

Once you get the blue box into the red box, a code will be printed. Write that code down as the answer to this question.

(Hint: Read the program to see what to do.)