Class Thing

java.lang.Object
  |
  +--Thing
Direct Known Subclasses:
Key

public class Thing
extends java.lang.Object

A "Thing" is an object in the adventure game. Things can be picked up, carried from place to place, and dropped, and they can be visible or invisible, but they are basically inert lumps, with little or no behavior of their own.

Each Thing you create should have a unique name. The Thing class keeps track of all Things that you create. Given a Thing myThing, myThing.getName() will return its name. Given a name thingName, Thing.getThing(thingName) will return the Thing with that name.

If you want to create a useful Thing, you should either (1) extend the Thing class and override the use() method, or (2) extend the Thing class, add new methods of your own, and teach the CommandHandler to recognize the corresponding new commands. You should NOT alter this class unless you want to give new behaviors to ALL Things.

Author:
David Matuszek

Field Summary
private  java.lang.String description
           
private  java.lang.String name
           
private static java.util.Hashtable things
           
private  boolean visible
           
 
Constructor Summary
Thing(java.lang.String name)
          Constructor for objects of class Thing.
 
Method Summary
 java.lang.String getDescription()
           
static Thing getThing(java.lang.String name)
           
 boolean getVisible()
           
 void setDescription(java.lang.String description)
          Replaces the description of this Thing with something more appropriate.
 void setVisible(boolean visible)
          Marks the thing visible if the parameter is true, or invisible if the parameter is false.
 java.lang.String toString()
           
 java.lang.String use(Player player, Room room)
          Does nothing and returns a message saying that this Thing is useless.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, wait, wait, wait
 

Field Detail

name

private java.lang.String name

description

private java.lang.String description

visible

private boolean visible

things

private static java.util.Hashtable things
Constructor Detail

Thing

public Thing(java.lang.String name)
Constructor for objects of class Thing. The name is required; the description will initially be taken from the name, but you should later supply a more detailed description. By default, newly created objects are visible.
Method Detail

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
Returns:
the name of this Thing.

getThing

public static Thing getThing(java.lang.String name)
Returns:
the Thing itself, given the name of the Thing.

getDescription

public java.lang.String getDescription()
Returns:
a full description of this Thing, probably beginning with the words "You see ..."

setDescription

public void setDescription(java.lang.String description)
Replaces the description of this Thing with something more appropriate.
Parameters:
description - One or more complete sentences describing this Thing.

getVisible

public boolean getVisible()
Returns:
true if this Thing is marked "visible", false otherwise.

setVisible

public void setVisible(boolean visible)
Marks the thing visible if the parameter is true, or invisible if the parameter is false. The setting of this flag does not affect the behavior of this Thing; the flag is provided as a convenience for any other Object that wants to make use of it.
Parameters:
visible - True iff this thing is to be marked visible.

use

public java.lang.String use(Player player,
                            Room room)
Does nothing and returns a message saying that this Thing is useless. To create a useful Thing, you should either (1) extend the Thing class and override the use() method, or (2) extend the Thing class, add new methods of your own, and teach the CommandHandler and Player classes to recognize the corresponding new commands.
Parameters:
player - A reference to the player, just in case it's needed
room - A reference to the player's current location, just in case it's needed
Returns:
a message telling the result of using this Thing.