Player

o1.adventure.Player
class Player(startingArea: Area)

A Player object represents a player character controlled by the real-life user of the program.

A player object’s state is mutable: the player’s location and possessions can change, for instance.

Parameters

startingArea

the player’s initial location

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Value members

Concrete methods

def drop(itemName: String): String

Tries to drop an item of the given name. This is successful if such an item is currently in the player’s possession. If so, the item is removed from the player’s inventory and placed in the area. Returns a description of the result of the attempt: "You drop the ITEM." or "You don't have that!".

Tries to drop an item of the given name. This is successful if such an item is currently in the player’s possession. If so, the item is removed from the player’s inventory and placed in the area. Returns a description of the result of the attempt: "You drop the ITEM." or "You don't have that!".

Attributes

def examine(itemName: String): String

Causes the player to examine the item of the given name. This is successful if such an item is currently in the player’s possession. Returns a description of the result, which, if the attempt is successful, includes a description of the item. The description has the form: "You look closely at the ITEM.\nDESCRIPTION" or "If you want to examine something, you need to pick it up first."

Causes the player to examine the item of the given name. This is successful if such an item is currently in the player’s possession. Returns a description of the result, which, if the attempt is successful, includes a description of the item. The description has the form: "You look closely at the ITEM.\nDESCRIPTION" or "If you want to examine something, you need to pick it up first."

Attributes

def get(itemName: String): String

Tries to pick up an item of the given name. This is successful if such an item is located in the player’s current location. If so, the item is added to the player’s inventory and removed from the location. Returns a description of the result: "You pick up the ITEM." or "There is no ITEM here to pick up."

Tries to pick up an item of the given name. This is successful if such an item is located in the player’s current location. If so, the item is added to the player’s inventory and removed from the location. Returns a description of the result: "You pick up the ITEM." or "There is no ITEM here to pick up."

Attributes

def go(direction: String): String

Attempts to move the player in the given direction. This is successful if there is an exit from the player’s current location towards the direction name. Returns a description of the result: "You go DIRECTION." or "You can't go DIRECTION."

Attempts to move the player in the given direction. This is successful if there is an exit from the player’s current location towards the direction name. Returns a description of the result: "You go DIRECTION." or "You can't go DIRECTION."

Attributes

def has(itemName: String): Boolean

Determines whether the player is carrying an item of the given name.

Determines whether the player is carrying an item of the given name.

Attributes

Determines if the player has indicated a desire to quit the game.

Determines if the player has indicated a desire to quit the game.

Attributes

Causes the player to list what they are carrying. Returns a listing of the player’s possessions or a statement indicating that the player is carrying nothing. The return value has the form "You are carrying:\nITEMS ON SEPARATE LINES" or "You are empty-handed." The items are listed in an arbitrary order.

Causes the player to list what they are carrying. Returns a listing of the player’s possessions or a statement indicating that the player is carrying nothing. The return value has the form "You are carrying:\nITEMS ON SEPARATE LINES" or "You are empty-handed." The items are listed in an arbitrary order.

Attributes

def location: Area

Returns the player’s current location.

Returns the player’s current location.

Attributes

def quit(): String

Signals that the player wants to quit the game. Returns a description of what happened within the game as a result (which is the empty string, in this case).

Signals that the player wants to quit the game. Returns a description of what happened within the game as a result (which is the empty string, in this case).

Attributes

def rest(): String

Causes the player to rest for a short while (this has no substantial effect in game terms). Returns a description of what happened.

Causes the player to rest for a short while (this has no substantial effect in game terms). Returns a description of what happened.

Attributes

override def toString: String

Returns a brief description of the player’s state, for debugging purposes.

Returns a brief description of the player’s state, for debugging purposes.

Attributes

Definition Classes
Any