Computer Science 136 |
Lab 2: The Wizard's Castle
Due: Monday, September 26, 2005 at 9:00 AM
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.
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.
class Player and class Species define the player and his or her inventory and attributes.
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:
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:
The constructor takes no parameters. It creates the internal storage for the castle and initializes the castle contents. Immediately after construction, the castle should contain:
Returns the contents of the room on the specified level and position.
Prints a map of the specified level of the castle, with the room at pos printed enclosed in angle brackets (indicating the current location of the player). Actual contents of rooms should be displayed only if the player has been in that room (the room's isVisible() method returns true). Otherwise, the room should be denoted with ".". Note that the map symbol for a visible room can be displayed using its toString() method.
Same as printMap, except the contents of all rooms are displayed, not just visible rooms. This is used only in debugging.
Replaces the room at the givel level and position with an empty room.
Returns a random number in the range 1 through WizardsCastle.NUM_LEVELS. In addition to be called by other classes, this will be a useful helper method for castle initialization.
Returns true if the given level and position specifies the room containing the Orb of Zot.
Returns true if the given level and position specifies the room containing the Runestaff.
Prints (using System.out.println) the location of the Orb of Zot. This is used when gazing into a crystal orb.
Takes a random room anywhere in the castle and makes it invisible. This implements the effect of the forgetful curse.
Returns true if the given level and position specifies the room that contains the lethargy curse.
Returns true if the given level and position specifies the room that contains the leech curse.
Returns true if the given level and position specifies the room that contains the forgetful curse.
There are a number of ways that you can approach this task. Here is one possibility:
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.