Class: DiabloGame::Hero
- Inherits:
-
Object
- Object
- DiabloGame::Hero
- Includes:
- Playable
- Defined in:
- lib/diablo_game/hero.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#health ⇒ Object
readonly
Returns the value of attribute health.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
- #dig(jewel) ⇒ Object
-
#initialize(name, health = 100) ⇒ Hero
constructor
A new instance of Hero.
- #points ⇒ Object
- #to_s ⇒ Object
Methods included from Playable
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
#health ⇒ Object (readonly)
Returns the value of attribute health.
7 8 9 |
# File 'lib/diablo_game/hero.rb', line 7 def health @health end |
#name ⇒ Object
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 |
#points ⇒ Object
20 21 22 |
# File 'lib/diablo_game/hero.rb', line 20 def points @found_jewel.values.reduce(0,:+) end |
#to_s ⇒ Object
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 |