Class: DiabloGame::Hero

Inherits:
Object
  • Object
show all
Includes:
Playable
Defined in:
lib/diablo_game/hero.rb

Direct Known Subclasses

BlacksmithPlayer

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Playable

#dead?, #heal, #hit

Constructor Details

#initialize(name, health = 100) ⇒ Hero

Returns a new instance of Hero.



10
11
12
13
14
# File 'lib/diablo_game/hero.rb', line 10

def initialize(name, health=100)
  @name = name.capitalize
  @health = health
  @found_jewel = Hash.new(0)
end

Instance Attribute Details

#healthObject (readonly)

Returns the value of attribute health.



7
8
9
# File 'lib/diablo_game/hero.rb', line 7

def health
  @health
end

#nameObject

Returns the value of attribute name.



8
9
10
# File 'lib/diablo_game/hero.rb', line 8

def name
  @name
end

Instance Method Details

#dig(jewel) ⇒ Object



28
29
30
31
# File 'lib/diablo_game/hero.rb', line 28

def dig(jewel)
  @found_jewel[jewel.name] += jewel.points
  puts "#{@name} digs for #{jewel.name} worth #{jewel.points} points. Satchel: #{@found_jewel}."
end

#pointsObject



20
21
22
# File 'lib/diablo_game/hero.rb', line 20

def points
  @found_jewel.values.reduce(0,:+)
end

#to_sObject



24
25
26
# File 'lib/diablo_game/hero.rb', line 24

def to_s
  "#{@name} has health of #{@health} and a total of #{points} item points."
end