Class: Degica::Actor
Instance Attribute Summary collapse
-
#focus ⇒ Object
Returns the value of attribute focus.
-
#inventory ⇒ Object
readonly
Returns the value of attribute inventory.
-
#location ⇒ Object
Returns the value of attribute location.
Instance Method Summary collapse
- #actions ⇒ Object
- #award(points) ⇒ Object
- #describe ⇒ Object
- #has_item?(item) ⇒ Boolean
-
#initialize(location) ⇒ Actor
constructor
A new instance of Actor.
- #pickup(item) ⇒ Object
Methods included from Actionable
Constructor Details
#initialize(location) ⇒ Actor
Returns a new instance of Actor.
8 9 10 11 12 13 |
# File 'lib/degica/actor.rb', line 8 def initialize(location) @location = location @inventory = InventoryCollection.new @focus = nil @points = 0 end |
Instance Attribute Details
#focus ⇒ Object
Returns the value of attribute focus.
5 6 7 |
# File 'lib/degica/actor.rb', line 5 def focus @focus end |
#inventory ⇒ Object (readonly)
Returns the value of attribute inventory.
6 7 8 |
# File 'lib/degica/actor.rb', line 6 def inventory @inventory end |
#location ⇒ Object
Returns the value of attribute location.
5 6 7 |
# File 'lib/degica/actor.rb', line 5 def location @location end |
Instance Method Details
#actions ⇒ Object
30 31 32 |
# File 'lib/degica/actor.rb', line 30 def actions [Action.new(:describe, self), Action.new(:inventory, self)] + @location.actions end |
#award(points) ⇒ Object
21 22 23 24 |
# File 'lib/degica/actor.rb', line 21 def award(points) @points += points puts "You've gained #{ANSI.highlight('10 points', :white)} 💕" end |
#describe ⇒ Object
34 35 36 |
# File 'lib/degica/actor.rb', line 34 def describe @focus&.describe || @location.describe end |
#has_item?(item) ⇒ Boolean
26 27 28 |
# File 'lib/degica/actor.rb', line 26 def has_item?(item) @inventory.include?(item) end |
#pickup(item) ⇒ Object
15 16 17 18 19 |
# File 'lib/degica/actor.rb', line 15 def pickup(item) puts "You picked up a (#{item.name}).".highlight @inventory << item.collection.delete(item) award(10) end |