CMSC 341 Fall 2008
Project 1
Assigned
| Wednesday, Sep 3, 2008
|
Due
| Wednesday, Sep 17, 2008 at 11:59 PM
|
Updates
| Additional details have been added to the LOOK and INVENTORY commands
on what should be printed when they are issued.
To make it possible for students to use packages other than the default
or to name the class containing the main() routine something other than
Proj1, you are now required to add a run task to your
build.xml. Below is an example of such a task:
<property name="build.dir" value="."/>
<target name="run" description="run the project">
<java dir="${build.dir}" classname="Proj1" fork="yes">
<arg line="${args}"/>
</java>
</target>
To use this task to run your project on a file named commands.txt you
would use the following command:
ant -Dargs="commands.txt" run
|
Background
The goal of this project is to have you write a Java application using
the various development tools that are required this semester: CVS,
ant, and javadoc. You will implement a simple text-based adventure
game in which a player moves around, finds treasure, and fights
monsters. There is significant flexibility in how you implement the
relevant classes, so think carefully about that topic as design is
part of the project grade.
Description
The world in which the player, monsters, and treasures exist is an
infinitely large grid. Locations on this grid are specified by their
X and Y coordinates. When a game starts, the player is always at
location X = 0 and Y = 0, which we'll write (0, 0).
Treasure has a location (X and Y coordinates), a value (an
integer), and a description (a string). For example, there might be a
"Crown" at location (2, 5) worth 100, and a "Diamond" at location (-3,
7) worth 500.
The player has a location, the amount of damage from monster
attacks she has taken (an integer), and a record of the treasures she
has picked up. When the player attacks a monster, she always inflicts
10 points of damage.
Players can take the following actions:
- NORTH - Increase the player's Y coordinate by 1
- SOUTH - Decrease the player's Y coordinate by 1
- EAST - Increase the player's X coordinate by 1
- WEST - Decrease the player's X coordinate by 1
- GRAB - Pick up all treasures at the current location, if there
are any
- ATTACK - Attack all monsters at the current location, if there
are any
- LOOK - Print the descriptions of the treasures and monsters at
the current location. Be sure to include the value of treasures and the
current strength (see below) of monsters at that location.
- INVENTORY - Print the player's location, damage taken so far, and
a description of all treasures that have been picked up, including their
individual values.
A monster will only attack after the player executes a GRAB or ATTACK
action at the monster's location.
Monsters have a location, strength (an integer), force (an
integer), and a description. When the player attacks a monster, the
monster's strength is reduced by 10 points. When a monster attacks
the player, the player takes damage equal to the monster's force. If
a monster's strength falls to 0 or less, it dies and is removed from
the playing field.
Input
To test your program we will run it with a single command line
argument, which is the name of a text file containing commands as
described below. Your program must check to ensure that a single
argument is given on the command line, open the specified file
(reporting an error if that's not possible), process each command
in the file, and exit when the end of the file is reached. There may
be blank lines in the file which should be ignored.
The commands can be any of the following in any order:
- MONSTER x y strength force description
- TREASURE x y value description
- NORTH
- SOUTH
- EAST
- WEST
- GRAB
- ATTACK
- LOOK
- INVENTORY
For the first two commands (MONSTER and TREASURE), x, y, strength,
force, and value will be integers. The description will be a string
with no white space. All commands will be well formed so you don't
have to worry about making your command parser bullet proof. That is,
you'll never get something like "NORTH 10" or "MONSTER 10 10 Ogre".
Project Notes, Hints, and Requirements
- Be sure that the main() for your program is in a file named
Proj1.java. The scripts that execute your program will assume this.
- Echo each command as it is read to System.out.
- Note that monsters and treasures share certain similarities, such
as having locations and descriptions. Think about how best to
implement the classes in light of this.
- Think about encapsulating locations in a class.
- You must use Java generics if you store monsters and treasures in a
Java collection. For example, if you have a Vector of monsters it should
be of type Vector < Monster > rather than a Vector of Objects.
- There can be multiple monsters and treasures at any given
location.
- Monsters and treasures can be added to the map at any time in the
command file.
- Commands in the command file may be upper case, lower case, or
any combination. You should recognize NORTH and North and north as
the same command.
Submission
You must use CVS to check out your module in the Proj1 repository and
to check in your code. That must include an ant build.xml file and
javadoc. See
the projects
page for more information on all of these topics.
If you don't submit a project correctly, you will not get credit for it.
Why throw away all that hard work you did to write the project? Check your
submittals. Make sure they work. Do this before the due date.
Project grading is described in the
Project
Policy handout.
Cheating in any form will not be tolerated. Please re-read the Project
Policy handout for further details on honesty in doing projects for this
course.
Remember, the due date is firm. Submittals made after midnight of the due
date will not be accepted. Do not submit any files after that time.