CMSC491F Introduction To Design Patterns
Spring 2003
Project 1
Adventure Game Project
Due Date: April 9, 2003
Project Description
In this project, you will be implementing a simple adventure game in Java.
The class diagram which provides the framework for the game is as follows:
Here's a brief description of each class:
- AdventureGame
- The adventure game itself. Either an applet or application or both.
The creation of the user interface, the players and the adventure
world will be initiated here.
- Notable Attributes:
- map - a map of the adventure world locations
- Map
- A map of the adventure world
- Notable Attributes:
- locations - all the MapSite locations in the adventure world
- MapSite
- Abstract superclass for any adventure world location
- Methods:
- abstract void enter(Player p) - player p enters the location
- abstract void exit(Player p) - player p exits the location
- Room
- A room; subclass of MapSite
- Notable Attributes:
- number - unique number of room
- name - name of room
- walls - walls of the room
- players - players in the room
- things - movable things in the room
- Notable Methods:
- void enter(Player p) - player p enters the room
- void exit(Player p) - player p exits the room
- Enumeration players() - returns an enumeration of the players in the room
- boolean hasPlayer(Player p) - returns true if player p is in the room
- Enumeration things() - returns an enumeration of the movable things in the room
- boolean hasThing(Object t) - returns true if the movable thing t is in the room
- void addThing(Object t) - adds the movable thing t to the room
- void removeThing(Object t) - removes the movable thing t from the room
- Wall
- Door
- Door in a wall
- Notable Attributes:
- room1 - room on side 1 of door
- room2 - room on side 2 of door
- Notable Methods:
- Room getOtherRoom(Room r) - returns room on other side of door from room r
- void open() - open the door
- void close() - close the door
- DoorWithLock; subclass of Door
- Door with a lock
- Notable Methods:
- void lock() - lock the door
- void unlock() - unlock the door
- Player
- A player of the game
- Notable Attributes:
- name - name of player
- room - room the player is in
- items - items the player is carrying (the player's inventory)
- Notable Methods:
- Enumeration items() - returns an enumeration of the items the player is carrying
- boolean hasItem(Object i) - returns true if the player has the item i
- void takeItem(Object i) - adds item i to player's inventory if item i is in the room
- void dropItem(Object i) - removes item i from player's inventory and drops it in the room
- Room moveToRoom(Room r) - moves player to room r; returns room exited
Note that the required accessors and mutators are not listed above for
the sake of brevity.
Project Requirements
Use the above framework to write a working version of an adventure
game.
Your project must have at least two players, four rooms and ten
movable objects.
Implement the user interface any way you like, either textual or graphical.
Your project must implement the following design patterns:
- Iterator
This one is easy. Methods that return an Enumeration demonstrate the
Iterator pattern.
- Abstract Factory with Factory Methods
Create all rooms, walls and doors using factories. Create some doors
with no locks and some doors with locks.
- Singleton
Allow only one instance of each factory type you create.
- Observer
Both rooms and players should be observable objects. Demonstrate
this pattern by having some observers somewhere in your game. For
example, have your user interface register as an observer of one or
more rooms and players.
- Composite
One way to utilize the Composite pattern is to have a bag or box as
one of the movable items in the game. This bag can contain other bags
as well as non-container items.
Feel free to use any other patterns you feel appropriate.
Your project code must also be well documented and use a reasonable
indentation style. In particular, places where design patterns are
implemented should be noted in the code.
Finally, a short report, no more than five pages in length, should be
submitted describing your use of design patterns in your project.
Please name the report file Project1.txt. Please submit this report
in text form only!
Project Grading
Your project will be graded according to the following criteria:
- Program Correctness - 65%
- The program performs all of its required functions properly.
- The program has no bugs.
- The program handles appropriate error conditions properly.
- The program operates with reasonable efficiency.
- Proper implementation of all required design patterns - 20%
- Coding Style - 10%
- Good, professional documentation.
- Good readability and understandability.
- Proper use of indentation to highlight function flow control.
- Proper use of blank lines to highlight distinct sections of a function.
- Project Report - 5%
As in all your work, NO COPYING OR PLAGIARISM. If such is
detected, no credit for the project will be given and appropriate
actions for academic dishonesty will be taken.
Project Submission
You must submit the following:
- All source files.
- All class files.
- Any makefile, if used.
- Your report file, Project1.txt
Submit all of the above using the submit program. To submit, you type
submit cs491f project1 <filenamelist>
where filenamelist is a list of one or more files. You can submit a
file as often as you like; the latest file submitted overwrites any
previous submissions. To list the names of the files you have submitted,
type
submitls cs491f project1
To remove a previously submitted file, type
submitrm cs491f project1 <filename>
Project Due Date
This project is due April 9, 2003. You have a one week, automatic,
no-need-for-a-lame-excuse grace period.
No project will be accepted after April 16, 2003.
NO EXCEPTIONS! NO EXCUSES!