Assignment 6

Harvey Mudd College
Computer Science 60
Assignment 6, Due Thursday, October 14, by midnight

Maze Maker

Assignment 6 embeds your breadth-first search code from Assignment 5 into an applet for searching a maze. This will give you the chance to use Java's graphics library and event-handling code.

Example Applet

You can run example maze maker applets by Prof. Keller or Prof. Dodds.

Files and Classes to Create

You will need to create a file Maze.java that contains at least two classes: a Maze class that contains the graphics code for the maze-making applet and breadth-first search code for solving it and a Queue class which provides the services of a queue for the breadth-first search. You can use your Queue class from the previous assignment for this (also, a working Queue class will be placed in the file /cs/cs60/assignment5/hw5.java.sols once that assignment is complete.

You will also need an html file which contains an < APPLET ... > tag. An example html file and information about where to place it are given below.

What does the code have to do?

The Maze Maker applet (the code's class name is Maze) is a tool for constructing mazes. The user drags the mouse within the rectangular field to create internal walls, as shown in blue above. The object of the maze player is to find a path constructed by the user. Maze Maker is required to display a minimal-length path through the maze, as shown in red in the picture above.

The rules for maze creation are as follows:

The rules for path creation are as follows:

The code for the simple applet in Square.java will help in setting up a Maze.java file for the maze maker applet. Square.java demonstrates the use of mouse down, mouse drag, and mouse up events, as well as how to draw to the screen. (Click here to run the applet.) Use the method of an off-screen buffer, as discussed in class and shown in the Square.java example, so that your applet does not flicker. This is mandatory.

I want more!

If you haven't had enough of your Maze.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 (10 pts.) optional bonus credit (for one):

Testing your applet

Applets require an html file. The text for the web page containing the example applet is Square.html. The text for the web page containing the example maze maker applet is mazeMaker.html. You should create a page named mazeMaker.html and are welcome to copy from that link.

You can test your code in two ways:

  1. With the appletviewer: if you are working in the terminal room or have an X connection to a remote machine, you can test your applet with the command
    appletviewer mazeMaker.html
    
    from any directory which contains both the compiled java code (Maze.class) and the mazeMaker.html file.

    Caution! For me, Turing's appletviewer takes a long time to appear and run (> 1 minute) unless the line

    setenv JAVA_FONTS "/usr/local/java/jre/lib/fonts"
    
    is added to the .cshrc file (which is then "sourced") before running. This line speeds the search for fonts, but error messages still appear that some fonts are not found.

    Appletviewer seems to process mouse events very slowly in any case.

  2. With a web browser: you can create a directory named public_html in your home directory with the command
    mkdir public_html
    
    Documents you place in that directory will be publicly available on the web. For example, you can place this index.html file into your public_html directory and then access it from the URL http://www.cs.hmc.edu/~username, where username is your username. If you then place your mazeMaker.html file and compiled java code Maze.class in that same directory, you can use the link from your index page to test your applet.

    Thank you! Netscape will reload newly-compiled applet code if you hold down the "Shift" key while pressing the reload button.

    For me this approach provided a much more responsive application.

What's the compiler saying about "deprecation"?

When you compile your Maze.java file with the 1.2.2 version of the java compiler, it will print a message similar to

> javac Maze.java

Note: Maze.java uses or overrides a deprecated API. 
Recompile with "-deprecation" for details.
1 warning
This is because some of the method calls used are no longer the preferred way of handling events and graphics in java. If you compile with the "-deprecation" flag, the compiler will tell you what calls are now deprecated. You can leave out that flag to avoid seeing the warnings.

This assignment is using older calls to certain event-handling and graphics methods in order to create applets which will work with the default capabilities of a wide variety of browsers.

Submission

You should submit your Maze.java source file in the usual way, i.e., by running

% cs60submit Maze.java
You will be asked to input the assignment number (6).

You should not submit your mazeMaker.html file.