Package rea.components
Class Item
java.lang.Object
rea.components.Component
rea.components.Positionable
rea.components.Item
- All Implemented Interfaces:
Element
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.
-
Field Summary
Fields inherited from class rea.components.Component
description, visual
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Accept a visitor.boolean
int
hashCode()
boolean
Returns true if the item can be picked up.boolean
Returns true if the item can be reused.void
setPickable
(boolean pickable) Set whether the item can be picked up.void
setReusable
(boolean reusable) Set whether the item can be reused.Methods inherited from class rea.components.Positionable
getPosition, moveTo
Methods inherited from class rea.components.Component
getDescription, getVisual, toString
-
Constructor Details
-
Item
Create an item.- Parameters:
visual
- visual representation of the itemdescription
- 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
-
hashCode
public int hashCode() -
accept
Accept a visitor.- Parameters:
visitor
- the visitor to accept
-