Class Player

java.lang.Object
  |
  +--Player
Direct Known Subclasses:
Neandertal

public class Player
extends java.lang.Object

A Player object represents the person playing the game. The Player can move around, see the Room, and can take, drop, use, and look at Things.

Author:
David Matuszek

Field Summary
protected  Room location
           
protected  java.util.Vector thingsIAmHolding
           
 
Constructor Summary
Player(Room location)
          Constructor for the (single) object of class Player.
 
Method Summary
 java.lang.String drop(java.lang.String thingName)
          Attempts to drop a Thing being held by the Player.
 Room getMyLocation()
          Returns this Player's current Room.
 java.lang.String go(java.lang.String direction)
          Attempts to move the Player to an adjoining Room in the indicated direction.
 java.lang.String inventory()
          Returns a String describing the Things that are in the user's "inventory" (the things the user is holding).
 java.lang.String look()
          Returns information about the user's current location.
 java.lang.String look(java.lang.String thingName)
          Attempts to look at a Thing that is either being held by the Player or is in the same Room as the Player.
 java.lang.String take(java.lang.String thingName)
          Attempts to pick up a Thing from the Room that this Player is in.
 java.lang.String use(java.lang.String thingName)
          Attempts to use a Thing being held by the Player.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

location

protected Room location

thingsIAmHolding

protected java.util.Vector thingsIAmHolding
Constructor Detail

Player

public Player(Room location)
Constructor for the (single) object of class Player. The Player must be created in a Room, therefore the Room must be created before the Player is created.
Method Detail

getMyLocation

public Room getMyLocation()
Returns this Player's current Room.

take

public java.lang.String take(java.lang.String thingName)
Attempts to pick up a Thing from the Room that this Player is in. The attempt should succeed if the Thing is in the same Room as this Player.
Parameters:
thingName - the name of the Thing to be picked up.
Returns:
a text message indicating the result.

drop

public java.lang.String drop(java.lang.String thingName)
Attempts to drop a Thing being held by the Player. If successful, the Thing will be placed in the same Room as this Player.
Parameters:
thingName - the name of the Thing to be dropped.
Returns:
a text message indicating the result.

use

public java.lang.String use(java.lang.String thingName)
Attempts to use a Thing being held by the Player. The Player must be holding the Thing; if so, the Thing is sent the use() message, and whatever result it returns will be the result of this use(thingName) method.
Parameters:
thingName - the name of the Thing to be dropped.
Returns:
a text message indicating the result.

look

public java.lang.String look(java.lang.String thingName)
Attempts to look at a Thing that is either being held by the Player or is in the same Room as the Player. If successful, the long description of the Thing is returned.
Parameters:
thingName - the name of the Thing to be dropped.
Returns:
a text message indicating the result.

look

public java.lang.String look()
Returns information about the user's current location.
Returns:
a description of the Room that the Player is in, along with a description of the contents of that Room.

inventory

public java.lang.String inventory()
Returns a String describing the Things that are in the user's "inventory" (the things the user is holding).
Returns:
a list of the Things being held by this Player.

go

public java.lang.String go(java.lang.String direction)
Attempts to move the Player to an adjoining Room in the indicated direction.
Parameters:
direction - One of "north", "south", "east", "west", "up", or "down".
Returns:
a text message indicating the result.