Program 3

Objective

The objective of this assignment is to get some practice defining and working with classes.

Specification

An early form of computer game was the "adventure" game. In this game the player moves around in an artificial world composed of rooms connected by passageways or doorways. The rooms contain various items that the player can interact with such as monsters, treasure, weapons, and magic potions. One key aspect of these games (with respect to this assignment) is that the connections between the rooms do NOT obey the normal rules of our world. For example you might go out the north door of room 1 to enter room 2, but going out the south door of room 2 will not necessarily take you back into room 1. As a player, one major challenge was building a map of how all of the rooms were connected. Unlike today's  adventure games, all interaction with the computer was done via typing and all output was text based.

For this assignment you will create a basic text based adventure game. You are given the core elements of the game with a player that can move from room to room, pickup, and drop objects. You need to

  • add an objective to the game
  • add at least two subclasses of the class Thing to represent objects that have more than just a name
  • add code to allow for interaction with the objects you created.

The code you are provided (which you must add to) is built around a Room class where each Room object has four doors, north, south, east, and west, that connect to other Room objects, except that some of the doors may be blocked. The Player class is used to represent the player and the Thing class is used to represent things in the room and in the player's backpack. 

In order to make sure you practice good object-oriented software engineering all instance variables in your classes must be private and thus accessed using getter/setter methods. Also, make sure you do not have any globally accessible static (class) variables unless they are final.

The starter code includes the ability to read the list of rooms and their contents from a file. The connections between the rooms are randomized. To allow for easy testing, the program will accept a "seed" for the random number generator so that the same game sequence can be repeated.
 

Getting Started

The programs you submit this quarter should be original programs created just for this class. It is NOT acceptable to submit programs that you (or someone else) has written previously. If you incorporate any portions of programs written by someone else, or by you for a prior course or assignment, then that should be clearly noted in the program via comments. (See "Giving Credit Where Credit is Due".)

This problem is large enough that it is important you build it and test it in phases. You certainly want to make sure you have a complete minimal solution before moving on.

The starter program (yes you must build on this starter code by adding to it, not removing existing functionality) is in prog3.zip. It contains a sample world.txt configuration file, Adventure.java, Player.java, Room.java, Thing.java, and a pre-configured DrJava project file, adventure.drjava. To run the program without providing a random seed (the room connections will change every time) you can just hit the "Run Project" button in DrJava or type "java Adventure" at a command line or the DrJava interactions pane. To run with a different configuration file type "java Adventure myWorldFile.txt". To provide a seed type "java Adventure world.txt 1234" of course changing 1234 to any number and changing world.txt if using something other than the provided default world.txt configuration file.

I recommend you develop your solution following these steps.

  1. Download prog3.zip. Extract the contents. Open the project file prog3/adventure.drjava. Compile and run it. Study that code. Ask lots of questions.
  2. Create a new subclass of Thing.
  3. Modify Adventure.addStuff() to create the correct kind of object and add it to the room when the name of your thing is found in the configuration file.
  4. Add some code in Adventure.play() to do something with your new thing invoking at least one new method/operation that is available for that type of thing (eat the food, drink the potion, wield the sword, fight the dragon, pet the cat, ...).
  5. Make a goal for the game.
  6. Add additional subclasses and operations (steps 2 and 3).
  7. Run your game and create a script of demonstrating all of the features.
  8. Turn in that solution and the script, all in a zip file.

What to turn in

One of you should submit a zip file named prog3.zip that contains the prog3 folder that contains your DrJava project on CrowdGrader. That folder (prog3) should contain at the very least Adventure.java, Room.java, Player.java, Thing.java, your subclasses of Thing (at least two), prog3.drjava, world.txt and demo.txt (the script of your playing your game). Make sure there are no other extraneous files in that prog3 folder, like test projects that you abandoned or other versions of the program.

You should include the transcript of a sample run of your program showing all of its features. When grading programs, the grader is expected to review the transcript and see what the program does. They will then play the game for just a minute or two to confirm that it behaves as expected. For some submissions, it might take 5 or 10 minutes of play to demonstrate some game features. These must be demonstrated in the transcript. The grader can examine the code to confirm that the two correspond.

It won't hurt if you both submit the same .zip file to CrowdGrader. Better safe than sorry. You might want to watch your partner do the submission to make sure it is successful. You are responsible even if your partner is the one doing the submission.

Also, don't forget to have BOTH partners submit a log (by pasting into the submission text field) using one of the log templates from this file in Canvas. Late submissions may be made in Canvas by attaching the .zip file up until the start of class following the due date.

Grading

See the rubric in CrowdGrader.

To create a truly interesting adventure game with all of the above features and complex worlds is well beyond the scope of this assignment. So be careful not to get too carried away.