Homework J7

Due: Friday, 11 Nov 2005 by 10 a.m.



Home | Resources | Homeworks | Slides | Labs | Contacts | Submit | Forums

Purpose

This assignment will give you more practice implementing your own classes.  To give you a sense for the process of writing slightly larger programs, we continue to build toward a simple text adventure game.  In this assignment you will create a Room class which represents a room in the game.  A room may (or may not) contain a monster to fight and a weapon to pick up, and may have exits to other rooms in the north, south, east, and west directions.  The player can move among rooms by typing commands such as "north" or simply "n". The player can also attack a monster, get a weapon, look around, or quit the game by typing the appropriate commands.  To simplify and compartmentalize the handling of user input, you will use the Parser from lab 9 class which processes or parses each string that the user types, and returns an integer representing a single action from a short list of possible user actions.

Of course, you will reuse the Creature class that you developed in the last assignment (Homework J6) to represent the monsters that the player can fight.  You will also extend the Creature class by adding a single private variable and accessor/mutator functions to indicate whether the monster will attack on sight.  If you were not able to complete that assignment, or suspect that your code might have bugs, we provide a Creature.class file that you may use instead (with no penalty to your grade) -- this file (Creature.class) needs to be saved to the same directory that your Room.java file is in.  We also provide a Weapon.class file in case you did not get that working; again this must be in the same directory as the Room.java file.

The Room class needs to be in a Room.java file.  We are not providing a skeleton file.

The Classes

Creature

The Creature class should be extended by adding a boolean instance variable and accessor/mutator methods getAngry() and setAngry().  This variable should always be false by default (you do not need to add a specific constructor that can change its initial value).  In addition, the takeDamage() method should be extended to print "<creature name> is down to <creature hit points> hit points" after applying the damage.

Parser

The parser class is from lab 9.  If you did not complete lab 9, you can use a pre-compiled version here -- this file (Parser.class) needs to be saved to the same directory that your Room.java file is in.

Room

The Room class implements most of the actual game functionality.   The Room class should provide the following instance variables:

The Room class should provide the following methods:

Game

We provide this class in the Game.java file. The Game class provides the main() method for the game program, which sets up several Room, Creature, and Weapon objects (including the Creature object that represents the player), prints out an introduction, and enters a loop that repeatedly calls the enterRoom() method of the Room object in which the player is located.  Below is a map of the "world" that the Game class creates.

You do not need to modify or submit Game.java.

Submission

When you are finished, submit just your Room.java file.