Computer Science 523
Advanced Programming

Summer 2014, The College of Saint Rose

Lab 8: The Wizard's Castle
Lecture and Practice Due: 4:30 PM, Tuesday, July 22, 2014
Programming Assignment Due: 4:30 PM, Tuesday, July 29, 2014

This week's lab will give you practice using inheritance, culminating in a fairly substantial program that will play a text-based game called The Wizard's Castle.

You may work alone or in a group of 2 or 3 on this lab. Only one submission per group is needed.

Getting Set Up

Start by downloading a working solution for the programming assignment and a lot of starter code here.

Create a document where you will record your answers to the lecture assignment and lab questions. If you use plain text, call it "lab8.txt". If it's a Word document, you can call it whatever you'd like, but when you submit, be sure you convert it to a PDF document "lab8.pdf" before you submit it.

Lecture Assignment Questions

We will usually discuss these questions at the start of class on the lab due date, so no credit can be earned for late submissions of lecture assignment questions.

LA Question 1: Gaddis Checkpoint exercise 11.2, p. 671-672. (3 points)

LA Question 2: Gaddis Checkpoint exercise 11.4, p. 679-680. (2 points)

LA Question 3: Gaddis Checkpoint exercise 11.5, p. 680. (2 points)

LA Question 4: Gaddis Checkpoint exercise 11.17, p. 703. (1 point)

LA Question 5: Gaddis Checkpoint exercise 11.18, p. 707-708. (3 points)

LA Question 6: Gaddis Algorithm Workbench exercise 1, p. 732. (1 point)

LA Question 7: Gaddis Algorithm Workbench exercise 2, p. 732. (1 point)

LA Question 8: Gaddis Algorithm Workbench exercise 3, p. 732. (4 points)

LA Question 9: Gaddis Algorithm Workbench exercise 5, p. 732-733. (1 point)

LA Question 10: Gaddis Algorithm Workbench exercise 7, p. 733. (1 point)

LA Question 11: Gaddis Algorithm Workbench exercise 8, p. 733. (1 point)

Practice Programs

Practice Program: Gaddis Programming Challenge exercise 10, p. 737-738. (6 points)

We can provide information to a Java application through the args parameter to its main method. As you can see from the main method signature we have been using all semester, it is an array of Strings. These String values come from what the program's user types after its name on the command line when running the program. Different Java IDEs provide different mechanisms for specifying these Strings, known as command-line parameters. In BlueJ, these are specified in a dialog box that we have been ignoring each time we run a Java application - the one that comes up after you choose main from the right-click menu to run your application. To specify the command-line parameters, we specify them as an array of String with the same syntax as a statically initialized array in Java. For example, we could specify an array of 3 String values:

  { "Java", "is", "fun" }

The Java run-time system will construct and initialize an array with these values, and we can access "Java" as args[0], "is" as args[1], and "fun" as args[2] in our program's main method.

Practice Program: Write a Java application in a program that takes any number of integers as command-line parameters (though they will come to you as String values) and prints their sum. (5 points)

Programming Assignment: The Wizard's Castle

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 origwiz.bas included in the starter you downloaded. In this lab, you will implement part of this program. The basic rules of the game are described in the file castle.txt, also in the starter download.

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 many of the classes from my implementation. You can get them from the starter package. 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.


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

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

Question 1: Describe the purpose of the abstract class RoomContents and discuss why it is not a regular class or an interface. (4 points)

Question 2: One of the important goals of our course is to understand object-oriented design. Describe the responsibilities of each class (treat all of the classes that extend RoomContents as a single entity for the purposes of this question) and describe how they interact with each other. (4 points)

Your Tasks

You will be developing your implementation of the Castle class for this program. 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.


Before 4:30 PM, Tuesday, July 22, 2014, submit your lab for grading. There are two things you need to do to complete the submission: (i) Copy your file with the answers to the lecture assignment and lab questions into your project directory. Be sure to use the correct file name. If you prepared your answers in Word, export to a PDF file and submit that. (ii) Upload a copy of your lab (a .7z or .zip file containing your project directory) using Submission Box under assignment "Lab8".


This assignment is worth 85 points, which are distributed as follows:

> FeatureValueScore
Lecture assignment quetions 20
Gaddis P.C. ex. 10 practice program 6
ArgAdder practice program 5
Wizard's Castle Castle constructor 2
Wizard's Castle Castle data structure 5
Wizard's Castle Castle correct initialization 12
Wizard's Castle Castle roomAt method 3
Wizard's Castle Castle printMap method 4
Wizard's Castle Castle printMapRevealed method 2
Wizard's Castle Castle makeEmpty method 2
Wizard's Castle Castle randomCoord method 1
Wizard's Castle Castle isXXX methods 2
Wizard's Castle Castle printOrbLocation method 1
Wizard's Castle Castle forgetRandomRoom method 2
Wizard's Castle comments 3
Wizard's Castle appropriate variable declarations 3
Wizard's Castle naming conventions 3
Wizard's Castle formatting 1
Lab questions 8
Total 85