Class Room

java.lang.Object
com.bdtripp.hauntedhouse.model.Room

public class Room extends Object
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 Details

    • Room

      public Room(RoomName name, String description)
      Creates a new room with the given name and description.
      Parameters:
      name - the room's identifier
      description - the room's narrative text (e.g., "in a misty indoor garden" or "in a dark hallway")
  • Method Details

    • addItem

      public void addItem(Item item)
      Adds an item to the room
      Parameters:
      item - the item to add
    • findItem

      public Item findItem(String name)
      Finds an item with a given name
      Parameters:
      name - the name of the item
      Returns:
      the item
    • removeItem

      public Item removeItem(Item item)
      Removes an item from the room
      Parameters:
      item - the item to remove
      Returns:
      the item that was removed
    • addCharacter

      public void addCharacter(Character character)
      Adds a character to the room
      Parameters:
      character - the character to add
    • setExit

      public void setExit(Direction direction, Room neighbor, ExitType type)
      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

      public Room getNeighbor(Direction direction)
      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

      public Exit getExit(Direction direction)
      Returns the exit associated with the given direction.
      Parameters:
      direction - the direction of the exit
      Returns:
      the exit in the direction provided
    • describeExits

      public String describeExits()
      Builds a description of all exits from this room.
      Returns:
      a description of the room's exits, for example, "Exits: north west".
    • getName

      public RoomName getName()
      Returns the name of the room.
      Returns:
      the name of the room.
    • getDescription

      public String getDescription()
      Returns the description for this room.
      Returns:
      the description of the room.
    • describeItems

      public String describeItems()
      Produces a formatted description of all items present in the room.
      Returns:
      a description of the items in the room
    • describeCharacters

      public String describeCharacters()
      Produces a formatted list of characters in the room.
      Returns:
      a list of characters in the room
    • describeRoom

      public String 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

      public Character findCharacter(String name)
      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