Computer Science 136
Data Structures and Advanced Programming

Williams College
Fall 2005


Lab 2: The Wizard's Castle
Due: Monday, September 26, 2005 at 9:00 AM

Before Lab

You should come to lab with a proposed design for the Castle class that you will be writing this week. Before lab, you should also familiarize yourself with the game.

Background

Long before first-person shooters and texture-mapping 3D graphics processing units, there were text-based games. A favorite from my Commodore 64 days was called The Wizard's Castle. The game was written in BASIC in 1980 by Joseph Power, and the version I used was converted to Commodore Basic by Jim Pryzyblo in 1983.

After coming across a "vintage" version on the web, I converted it to Java. The BASIC program is available here and in the CS 136 shared directories as origwiz.bas. In this lab, you will implement part of this program.

The basic rules of the game are described in the file castle.txt, also available both here and in the CS 136 shared directories.

Java Implementation

You can run my version of the program on the Macs in TCL 217a with the command wizard (as long as you've run the script to set up the CS 136 Java environment). Try it out to get a feel for the game. Issue the command "h" to learn more about the interface. If you provide any command-line parameter when you run this version, you will enter a debugging mode, where some additional information about the game is printed. This allows you to test features of the game that would otherwise be difficult to test (such as finding which of the 65 monsters in the castle has the Runestaff).

I am providing the source code for 22 of the classes from my implementation. You can get them from the CS136 common area on the TCL 217a Macs in the file wizard.tar.gz. The classes that implement the castle itself are omitted. Your task is to develop a Castle class, and any additional classes you deem appropriate, that will work with the rest of my implementation.

Here is a brief description of the classes.

Game Control

class WizardsCastle is responsible for setting up the game and managing game play. The main method simply constructs an instance of WizardsCastle and calls its setup and play methods. The setup and play methods interact with the Castle class (which you will write) through the public interface described later in this document.

Player

class Player and class Species define the player and his or her inventory and attributes.

Castle Rooms

The abstract class RoomContents defines the common behavior of all of the items that can be placed throughout the Castle. A major part of your task in developing the Castle will be to manage the 512 instances of RoomContents subclasses.

RoomContents defines one instance variable visible and appropriate accessor and mutator methods to access this variable. It determines whether the player is aware of the contents of that room (by having been there or seen it by light of a flare, a lamp, or by gazing into a Crystal Orb).

RoomContents provides default implementations of two methods that are overridden by some subclasses: take and interact. The take method is overridden by classes that represent objects that can be picked up by the player. The interact method is overridden by classes that define a room containing something the player can interact with. It also defines two abstract methods, mapSymbol and contents, which must be provided by all classes extending RoomContents.

The following classes extend RoomContents:

Miscellaneous Utilities

Three utility classes are provided that do not implement any part of the game directly, but are used by other parts of the program.

My classes include Javadoc comments, so you may wish to generate the Javadoc to learn more about these classes.

Lab Program

This week, you will be developing your implementation of the Castle class for this program. You should come to lab with a written design of the classes you will be writing. You should not make any changes to the other classes provided.

Your implementation of class Castle is up to you, but in order to make it work with the rest of the program, you will need to take care that your class provides the required constructor and public methods. Here are the specifications:

There are a number of ways that you can approach this task. Here is one possibility:

  1. Start writing the constructor. At first, just initialize the castle to contain all empty rooms.
  2. Write the printMapRevealed method.
  3. Write a main method for class Castle. This will allow you to test the Castle class as you go without having to write all of the methods to test it with the real game. This main method should just construct a Castle and display it with calls to printMapRevealed.
  4. Incrementally develop the constructor to add the required rooms to the castle. Test as you go.
  5. Once you have the contents of the castle created correctly, implement the other methods listed above so you can test with the entire game.

When you have finished the program, create a tar file of all of the files you wish to submit. Please call this file lab2.tar, and submit it using the turnin utility.

As in all labs, you will be graded on design, documentation, style, and correctness. Be sure to document your program with appropriate Javadoc comments, including a general description at the top of the file, a description of each method with pre- and post-conditions where appropriate. Also use comments and descriptive variable names to clarify sections of the code which may not be clear to someone trying to understand it.