Package com.bdtripp.hauntedhouse.model
Class Room
java.lang.Object
com.bdtripp.hauntedhouse.model.Room
Represents a room in the game world.
Rooms contain items, characters, and exits that connect them to other rooms.
- Author:
- Michael Kölling, David J. Barnes, and Brian Tripp
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddCharacter(Character character) Adds a character to the roomvoidAdds an item to the roomProduces a formatted list of characters in the room.Builds a description of all exits from this room.Produces a formatted description of all items present in the room.Produces a full description of the room, including its exits.findCharacter(String name) Find the character that matches the given nameFinds an item with a given nameReturns the description for this room.Returns the exit associated with the given direction.getName()Returns the name of the room.getNeighbor(Direction direction) Retrieves the neighboring room in the specified direction.removeItem(Item item) Removes an item from the roomvoidCreates an exit for the room
-
Constructor Details
-
Room
Creates a new room with the given name and description.- Parameters:
name- the room's identifierdescription- the room's narrative text (e.g., "in a misty indoor garden" or "in a dark hallway")
-
-
Method Details
-
addItem
Adds an item to the room- Parameters:
item- the item to add
-
findItem
Finds an item with a given name- Parameters:
name- the name of the item- Returns:
- the item
-
removeItem
Removes an item from the room- Parameters:
item- the item to remove- Returns:
- the item that was removed
-
addCharacter
Adds a character to the room- Parameters:
character- the character to add
-
setExit
Creates an exit for the room- Parameters:
direction- the direction of the exit.neighbor- the room in the given direction.type- the type of exit (locked or unlocked)
-
getNeighbor
Retrieves the neighboring room in the specified direction.- Parameters:
direction- the direction of the neighbor- Returns:
- the room in the given direction. null if there is no exit in that direction
-
getExit
Returns the exit associated with the given direction.- Parameters:
direction- the direction of the exit- Returns:
- the exit in the direction provided
-
describeExits
Builds a description of all exits from this room.- Returns:
- a description of the room's exits, for example, "Exits: north west".
-
getName
Returns the name of the room.- Returns:
- the name of the room.
-
getDescription
Returns the description for this room.- Returns:
- the description of the room.
-
describeItems
Produces a formatted description of all items present in the room.- Returns:
- a description of the items in the room
-
describeCharacters
Produces a formatted list of characters in the room.- Returns:
- a list of characters in the room
-
describeRoom
Produces a full description of the room, including its exits.- Returns:
- a description of the room. For example: You are in the kitchen. Exits: north west
-
findCharacter
Find the character that matches the given name- Parameters:
name- the name to search for- Returns:
- the matching character, or null if none is found
-