Computer Science 523
Advanced Programming
Summer 2014, The College of Saint Rose
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.
Practice Programs
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.
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.
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:
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.
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:
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 mode.
Replaces the room at the given 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:
Submitting
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".
Grading
This assignment is worth 85 points, which are distributed as follows:
> Feature | Value | Score |
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 | |