Harvey Mudd College
Computer Science 60
Assignment 6, Due Friday, March 8, by midnight

Spampede!

Assignment 6 takes advantage of the double-ended Queue (Deque) class you wrote in assignment 5 in order to implement a centipede in search of spam within a simple Maze-like world. This will give you the chance to use Java's graphics library and event-handling code. The Java 1.1 event-handling mechanism will be used.

Example Applet

You can run an example Spampede applet at www.cs.hmc.edu/~dodds/Applets/Spampede/Spampede.html .

Files and Classes to Create

You will need to create (actually, modify) a Spampede.java file that contains your Spampede applet class. In addition, you will need to use the following classes, which you may spread among several files (such as those in /cs/cs60/as/a6).



To get you started, there are the following files in the /cs/cs60/as/a6 directory:

You should copy all of these files to your ~/cs60/a06 directory with the command
cp /cs/cs60/as/a6/* ~/cs60/a06
(This will also copy a couple of other important files you'll need.) You can see what the skeleton Spampede.java applet does at http://www.cs.hmc.edu/~situdent/Spampede.html. Note that this is just a starting point, and not the whole Spampede applet.

Getting the applet running

So, the first thing to do is to make sure you can get that example applet running on your own webpage. To do this, follow these steps:

  1. You should make sure you have all the files from /cs/cs60/as/a6 in the directory you'd like to work in. I would strongly suggest creating an a6 directory in your ~/courses/cs60 directory and then putting all the files there. To move all the files at once, go to the directory you'll be working in and then type
           cp /cs/cs60/as/a6/* .
           
  2. Copy the Spampede.html file to your "public_html" directory. That directory is inside your top-level home directory. Thus, from your assignment 6 working directory you can type
           cp Spampede.html ~/public_html
           
    You will not have to do this step again.

  3. Make sure that the permissions are set so that people can view your applet. I believe this is already true by default. If you run into trouble, however, it won't hur to do the following:
           chmod 755 ~/public_html
           
    Then, your public_html directory will be readable by anyone.

  4. Next, from your working directory, ~/courses/cs60/a6 or whatever you've called it, compile all of the files:
           javac *.java
           
  5. This compilation will produce a large number or .class files. These all need to be copied to your public_html directory with the command
           cp *.class ~/public_html
           
  6. Finally, you need to make sure that all of the files in your public_html directory are readable by everyone. To do this, type
           chmod o+r ~/public_html/*
           
  7. Now your Spampede applet (in it's current state) should appear from any web browser at the address
           http://www.cs.hmc.edu/~<your turing login name>/Spampede.html
           

Writing the applet

Once the above steps work for you, you're ready to write your own applet. Basically, the starting point is the Spampede.java file. You will want to change the Spampede class to include a data member of type Maze and you will want to write a method that draws a Maze.

As you write your code, please compile and run the applet often to make sure you're on the right path. Bascially, that means repeating steps 4-7 above.

How do I know what going wrong in an applet?

IE and Netscape have a wonderful applet-debugging feature called the Java Console. To open the Java Console, go to the Communicator Menu, the Tools submenu, and choose "Java Console." A window will open up. In Internet Explorer, choose "Java Console" from the "View" Menu. If any errors occur during the running of your applet, they will appear in that window.

Also, you can use System.out.println to debug your applet -- all of those print statements will print to the Java Console. This is critical for debugging!

What does the code have to do?

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).

The particular applet behaviors and methods you need to implement are





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 up to 20% (or beyond...) optional bonus credit.



Grading/Testing?

The best way to test your code is with a Java-enabled browser.

Note Netscape will reload newly-compiled applet code if you hold down the "Shift" key while pressing the reload button. Internet Explorer will reload applet code if your hold down the "Ctrl" key while pressing the refresh button. (I suppose they're different to avoid lawsuits ... ?).

Note #2 Netscape has a "Java Console" available from the Communicator -- Tools menu. You should have this open as you test your applet. With the Java Console, you can include System.out.println messages anywhere in your code and see what gets printed. In addition, runtime errors will get reported there. This is a good thing! Debugging without it is bad! (Spoken from first-hand experience.) Internet Explorer also has a Java Console -- available from the "View" menu.

Reading

This assignment takes advantage of Object-Oriented programming (covered in Chapter 7 of the book), but the details of Java's Applet and GUI Component classes are available from the references page. Also, the basics of event handling and Java's built-in classes will be presented in class.

Submission

There are a lot of files that make up this assignment -- you could type cs60submit for each of them, but you can submit all of your .java files at once with the command

% cs60submit *.java
Here is a list of files that should be part of this all-in-one submission. You may add your own files, as well, if you wish. Note that you can also have several class in one file, e.g., all of the Queue and Deque classes or Maze with MazeCell.
  Spampede.java
  Maze.java
  MazeCell.java
  DequeInterface.java
  Deque.java
  DCell.java
  Queue.java
  QCell.java
There is no need to submit the .html file; we will provide one.

No tests will be run; instead the graders will play your Spampede applet to see if it does all of the things it should!