Computer Science 60
Principles of Computer Science

Assignment 12: Spampede!
Due Monday April 29 by 11:59 PM

Please read the following carefully. There is a lot here!


  1. Pair programming is permitted on all three parts of this week's assignment.  

  2. You will be submitting several files for this assignment. Please zip all of your files into a single zip file named hw12files.zip and then submit that zip file for your assignment. That way, we know we'll be able to run your applet! In particular, we will look for Maze.java (Part 1), SpamMaze.java (Part 2), Spampede.java (Part 3), SpampedeBase.java (Provided), Queue.java (Provided), and QueueInterface.java (Provided).

  3. This week, we ask that you also submit a file that is typically submitted in any large software project: A text file called README. We have provided a basic README file on the main assignment page. You should edit this file and submit it. The README file will constitute part of your score on this assignment.
  4. Previous students have identified some common mistakes that we think might be helpful to you!

This assignment has three parts, which ultimately build to the Spampede game! In Part 1 (hw11), you extended the capabilities of your maze solver from HW7. In Part 2, you will use the results of Part 1 to build some of the primary functionality of the Spampede game. In Part 3, you will use Part 2 in a graphical applet - if you'd like to make it accessible from your CS webspace, all the better. As noted, there is a README file in which we ask you to list the features, possible missing features, and any additions to the game that you've created.


What is the final product?

Overview

This project introduces and practices a number of different techniques that are common to software engineering, that is the design and implementation of large software projects. Certainly this assignment can only provide a hint at a very rich -- and important -- field.

The Spampede applet is a bigger and more complex beast than any you have had to deal with in the past.  Before you begin, we provide you with an overview of the software design behind the Applet you will create.  Normally, it would be up to you, the developer (or some team of developers), to do this design, but because this is your first large-scale project, we have done the class design for you.  

The functionality of the application is broken down into three classes that you will be responsible for:

Part 1:     Maze.java [possible extra credit]

You can decide if you are going to use your Maze.java code from the previous assignment or if you'd like to use the solution code. If you use your own Maze.java code, you will receive 5 points of extra credit. If you would like to use the solution from indicate in your README file that you are using the solution version of Maze.java Please email Colleen your login to get a copy of the file.

Part 2:     Writing SpamMaze.java [50 points]

The overview

In this part of the assignment you will create a derived class named SpamMaze that handles the model for the applet, which is part 3. A derived class is simply an extension of the data and capabilities (methods) available in the base class. Thus, by starting the code as in the provided SpamMaze.java file:

import java.lang.Math;
import java.util.LinkedList;

class SpamMaze extends Maze
{
// your code goes here...
}
You should keep in mind that any object of type SpamMaze IS also an object of type Maze. In other words, a SpamMaze can do everything a Maze can do, and more!  This is identical to the relationship of every object with Java's Object type. Object is the base class of all Java classes.  

The data

Because a SpamMaze object represents the model for the Spampede applet, it needs to keep track of (1) the maze, (2), the centipede, and (3) the spam in the environment. Remember that (1) is already taken care of because your SpamMaze is a derived class of Maze. To keep track of (2) and (3), you should use lists of MazeCells. In particular, you will declare two data members:

  // The data members representing the spam and the centipede
private LinkedList<MazeCell> spamCells;
private LinkedList<MazeCell> pedeCells;
Each of these is of type LinkedList<MazeCell>, which is the Java-library version of a double-ended queue implemented via a linked list. You will thus have access to the methods listed at http://docs.oracle.com/javase/6/docs/api/index.html?java/util/LinkedList.html. Notice especially the methods addFirst, addLast, removeFirst, removeLast, getFirst, getLast, and get(int n). Each get method is similar to peek in that it returns a value, but does not change the list. You can ask the size of a list with size(), which returns an int.

How should we represent the head of the snake?    One way to do this is simply to decide that the first element of the pedeCells data member will always be the head of the snake. Equivalently, you could use the last element. Either way, it will be up to your code to make sure the head of the snake contains the 'S' character, that the other cells in the snake contain the 'P' character, and that the snake is updated appropriately.

The methods

You should, in essence, implement all of the functionality, but not the graphics front end, for the Spampede game inside SpamMaze. At a minimum, you should implement the following methods. You may choose to add more methods - either private helper methods (to help these public methods) - or other public methods for your game to use.

Testing!!

As with Maze, be sure to test your SpamMaze thoroughly before worrying about the graphical front-end of the applet in part 3.



Part 3:     Putting it all together: Spampede.java [50 points]

Overview of Spampede.java

The Spampede applet gives a user control over a spam-seeking centipede. Key presses from the keyboard change the direction of the centipede's movement in order to intersect snacks (spam) that appear at random places on the screen. For each snack consumed, the centipede grows by one segment (a segment is simply one MazeCell). Variations are welcome (see the extra credit section below)!

As a result, in this part of the assignment you will be modifying another derived class, this one named Spampede, which is a child class of SpamBase, which is a child class of Java's JApplet. This means that your Spampede is itself an applet that will run in a Java-enabled browser from anywhere.

Setting up

The "starter" applet Spampede.java and its html file Spampede.html are provided for you on the top-level assignments page.  There are some other files you'll need, like ImagePanel.java, so make sure all the files are in the same directory with the files you developed for parts 1 and 2.

Finally, we have also provided the following files which you may wish to use (but they are totally optional):

Getting the applet compiling, running, recompiling, and rerunning

When you run Spampede.java in Eclipse, you will first get a very small window!

To get the regular size window, you must go to the Run Configurations dialog box. You can do this by opening up the Spampede.java file and clicking Run->Run Configurations. In the Run Configuration menu (shown below), click on the "Parameter" tab and modify "Width" and "Height" to both be 600.

Now if you run Spampede.java you should see this:


Writing the applet

Once the above steps work for you, you're ready to write Spampede by the modifying Spampede.java file with the following things in mind.

As you write your code, please compile and rerun the applet often to make sure you're on the right path. Use the appletviewer (or a web browser with a Java Console) to help with debugging and error-detection. Basically, this means many iterations of the compilation, copying, and testing steps above.

A Reminder On What to Submit

Please be sure to zip up the whole folder of files that makes up your Spampede applet (including any sound and/or image files) into an archive named hw12files.zip, and then submit it in the usual way. Be sure your README file described at the very of this web page is within that zip archive, too.

Extra Credit (10 points)

In addition to the extra credit described below, we'll have a unique type of extra credit this week. While I know that many many CS60ers help their classmates to debug the homework assignments, this week there will be an extra insentive to do so! To earn these 10 extra credit points...

I want more!

If you haven't had enough of the Spampede.java file at the end of this assignment, there are a couple of specific items and an open-ended invitation to improve on the applet for optional bonus credit. (Up to 20 points in total.)

If you add optional features, please explain them carefully in the README file.