Class: Degica::Actor

Inherits:
Object
  • Object
show all
Includes:
Actionable
Defined in:
lib/degica/actor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Actionable

#do, #prompt

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

#focusObject

Returns the value of attribute focus.



5
6
7
# File 'lib/degica/actor.rb', line 5

def focus
  @focus
end

#inventoryObject (readonly)

Returns the value of attribute inventory.



6
7
8
# File 'lib/degica/actor.rb', line 6

def inventory
  @inventory
end

#locationObject

Returns the value of attribute location.



5
6
7
# File 'lib/degica/actor.rb', line 5

def location
  @location
end

Instance Method Details

#actionsObject



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

#describeObject



34
35
36
# File 'lib/degica/actor.rb', line 34

def describe
  @focus&.describe || @location.describe
end

#has_item?(item) ⇒ Boolean

Returns:

  • (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