Class Place

All Implemented Interfaces:
Element

public class Place extends Component
A place in the game. A place can contain connections to other places and game components such as characters, items, etc.
Author:
José Paulo Leal jpleal@fc.up.pt
Implementation Note:
Corresponds to a Container in the Composite design pattern.
  • Field Details

    • entrance

      final Position entrance
      Position where the character enters this place.
    • positionables

      List<Positionable> positionables
      The positionable components in this place.
      Implementation Note:
      cannot be a Set because positionable are mutable and this interferes with the Set.contains(Object) method.
  • Constructor Details

    • Place

      public Place(Visual background, String description, Position entrance)
      Create a place.
      Parameters:
      background - showing this place.
      description - of this place.
      entrance - position where the characters enter this place.
  • Method Details

    • getEntrance

      public Position getEntrance()
      The entrance to this place.
      Returns:
      the position where the character enters this place.
    • addGameComponent

      public Place addGameComponent(Positionable positionable, Position position)
      Add a positionable component, such as Item or Character to this place. It returns the place itself to allow chaining.
      Parameters:
      positionable - component to add.
      position - where to add the component.
      Returns:
      the place itself.
    • removeGameComponent

      public boolean removeGameComponent(Positionable positionable)
      Remove a positionable component, such as Item or Character from this place. It returns true if the component was removed, false otherwise.
      Parameters:
      positionable - component to remove.
      Returns:
      true if the component was removed, false otherwise.
    • getPositionables

      public List<Positionable> getPositionables()
      Get the list of game positionable components in this place.
      Returns:
      the list of positionable components.
    • getCharacters

      public Set<Character> getCharacters()
      Get the characters in this place. Convinience methods to get the positionables that are players.
      Returns:
      the set of players in this place.
    • getItems

      public Set<Item> getItems()
      Get the items in this place. Convinience methods to get the positionables that are item.
      Returns:
      the set of items in this place.
    • accept

      public void accept(Visitor visitor)
      Accept a visitor.
      Parameters:
      visitor - the visitor to accept