Package rea.components
Class Character
java.lang.Object
rea.components.Component
rea.components.Positionable
rea.components.Character
- All Implemented Interfaces:
Element
A character in the game.
The character has a name, an avatar, an inventory of items, and a path of visited places .
The character can move to a place, move back to the previous place, and hold an item.
- Author:
- José Paulo Leal
jpleal@fc.up.pt
- Implementation Note:
- Corresponds to a Leaf in the Composite design pattern.
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) Item
The item being heldThe inventory of items(package private) String
The name of the characterThe path of visited places.Fields inherited from class rea.components.Component
description, visual
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Accept a visitor.void
Add an item to the inventory.boolean
Drop an item from the inventory.Get the item being held.Get the inventory, the items the character is carrying.getName()
Get the name of the character.getPlace()
Get the place where the character is currently in.void
Hold the given item.void
Move to the given place.moveBack()
Move back to the previous place, if possible.Methods inherited from class rea.components.Positionable
getPosition, moveTo
Methods inherited from class rea.components.Component
getDescription, getVisual, toString
-
Field Details
-
Constructor Details
-
Character
Create a character.- Parameters:
name
- the name of the characteravatar
- the avatar of the character
-
-
Method Details
-
getName
Get the name of the character.- Returns:
- the name of the character.
-
getPlace
Get the place where the character is currently in.- Returns:
- the place where the character is currently in,
or
null
if the character is not in any place.
-
move
Move to the given place. In that place, the character is postioned at the entrance.- Parameters:
place
- the place to move to
-
moveBack
Move back to the previous place, if possible. Cannot move back if the character has not moved to any place yet, apart from the starting place.- Returns:
- the place where the character moves to, or
null
if the character cannot ho back.
-
getInventory
Get the inventory, the items the character is carrying.- Returns:
- the inventory
-
addItem
Add an item to the inventory.- Parameters:
item
- the item to add
-
dropItem
Drop an item from the inventory.- Parameters:
item
- the item to drop- Returns:
- true if the item was dropped, false otherwise
-
holdItem
Hold the given item. A single item can be held by a character at a time. An item must be held to be used. The argument can benull
to stop holding an item.- Parameters:
item
- to hold
-
getHolding
Get the item being held.- Returns:
- the item being held, or
null
if no item is being held.
-
accept
Accept a visitor.- Parameters:
visitor
- the visitor to accept
-