Class Item

All Implemented Interfaces:
Element

public class Item extends Positionable
An item in the game, such as a key, a sword, a potion, etc. Some items can be picked up and used, to open a door, cast a spell, etc. By default, an item can be picked up, but it cannot be reused (can be uised only once). This can be changed using the methods setPickable(boolean) and setReusable(boolean). The visual representation of the item is a Visual.
Author:
José Paulo Leal jpleal@fc.up.pt
Implementation Note:
Corresponds to a Leaf in the Composite design pattern.
  • Constructor Details

    • Item

      public Item(Visual visual, String description)
      Create an item.
      Parameters:
      visual - visual representation of the item
      description - description of the item
  • Method Details

    • isPickable

      public boolean isPickable()
      Returns true if the item can be picked up. By default, an item can be picked up.
      Returns:
      true if the item can be picked up, false otherwise.
    • setPickable

      public void setPickable(boolean pickable)
      Set whether the item can be picked up. By default, an item can be picked up.
      Parameters:
      pickable - true if the item can be picked up, false otherwise.
    • isReusable

      public boolean isReusable()
      Returns true if the item can be reused. By default, an item cannot be reused. Non-reusable items are removed from the inventory when used.
      Returns:
      true if the item can be reused, false otherwise.
    • setReusable

      public void setReusable(boolean reusable)
      Set whether the item can be reused. By default, an item cannot be reused. Non-reusable items are removed from the inventory when used.
      Parameters:
      reusable - true if the item can be reused, false otherwise.
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • accept

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