CIS 260 Dungeon

The objective of this assignment is to create some classes that use linked lists to get a basic dungeon explorer up and running. You will also have to deal with multiple source files.

Requirements and Resources

You have to implement four classes for this program: Path, Room, Item, and Dungeon.

  1. PlayDungeon2.java: main program that runs game
  2. LinkedList.java: A generic linked list class you are required to use
  3. dungeon.txt: A generic linked list class you are required to use

Path

  1. Class name: Path
  2. Instance variables:
    1. access: public; type: String; name: direction
    2. access: public; type: String; name: to
  3. Constructors
    1. parameters: none; action: sets both instance variables to zero-length Strings
    2. parameters: direction, to; action: set instance variables using parameter values
  4. Method
    1. Override of toString(); returns: "Path: direction to destination" (where direction and destination are replaced by the instance variable values)

Item

  1. Class name: Item
  2. Instance variables:
    1. access: public; type: String; name: name
    2. access: public; type: String; name: description
    3. access: public; type: String; name: location
  3. Constructors
    1. parameters: none; action: sets name and description to zero-length Strings and location to null
    2. parameters: name, description, location; action: set instance variables using parameter values
  4. Method
    1. Override of toString(), returns: description

Room

  1. Class name: Room
  2. Instance variables:
    1. access: public; type: boolean; name: visited; initialize: false
    2. access: public; type: String; name: id
    3. access: public; type: String; name: name
    4. access: public; type: String; name: description
    5. access: public; type: LinkedList of Path objects; name: paths; initialize: new empty LinkedList
    6. access: public; type: LinkedList of Item objects; name: items; initialize: new empty LinkedList
  3. Constructors
    1. parameters: none; action: calls other constructor using zero-length Strings for all parameters
    2. parameters: id, name, description; action: set instance variables using parameter values
  4. Methods
    1. access: public; name: getPath; parameter: String direction;
      purpose: iterates through paths linked list looking for Path with same direction as parameter
      returns that Path object if found, otherwise returns null
    2. Override of toString(), returns: "Room: id: name" (where id and name are replaced with the instance variable values)

Dungeon

  1. Class name: Dungeon
  2. Instance variables:
    1. access: public; type: String; name: currentRoom; initialize to: zero-length String
    2. access: public; type: LinkedList of Room objects; name: rooms; initialize: new empty LinkedList
  3. Constructors: none (Java will write a default constructor for you)
  4. Methods
    1. access: public; name: getRoom; parameter: String id;
      purpose: iterates through rooms linked list looking for a Room with the same id as parameter
      returns that Room object if found, otherwise returns null
    2. Override of toString(), returns: "Room: id: name" (where id and name are replaced with the instance variable values)

Sample output

>java PlayDungeon2
You are in a large open computer lab
A large room with many computers that are available to the public.
Exits are: e, w

Enter command: help
Commands are: help, quit, look, drop, take, go, inv, and the exit directions
You are in a large open computer lab
Exits are: e, w

Enter command: look
You are in a large open computer lab
A large room with many computers that are available to the public.
Exits are: e, w

Enter command: think
Unknown command. Try again.
You are in a large open computer lab
Exits are: e, w

Enter command: go w
You are in the west hall
A long, carpeted hallway running north-south.
Exits are: w, nw, s, e

Enter command: s
You are in the west hall
A long, carpeted hallway running north-south.
Exits are: s, n

Enter command: quit
Thanks for playing. Visit again soon.