Class: TreasureHunt::BerserkPlayer

Inherits:
Player
  • Object
show all
Defined in:
lib/treasure_game/berserk_player.rb

Instance Attribute Summary

Attributes inherited from Player

#health, #name

Instance Method Summary collapse

Methods inherited from Player

#<=>, #each_found_treasure, #found_treasure, #points, #score, #to_s

Methods included from Playable

#strong?

Constructor Details

#initialize(name, health = 100) ⇒ BerserkPlayer

Returns a new instance of BerserkPlayer.



6
7
8
9
# File 'lib/treasure_game/berserk_player.rb', line 6

def initialize(name, health=100)
  super(name, health)
  @heal_count = 0
end

Instance Method Details

#berserk?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/treasure_game/berserk_player.rb', line 11

def berserk?
  @heal_count > 5
end

#healObject



15
16
17
18
19
# File 'lib/treasure_game/berserk_player.rb', line 15

def heal
  super
  @heal_count += 1
  puts "#{@name} has gone berserk!" if berserk?
end

#hitObject



21
22
23
# File 'lib/treasure_game/berserk_player.rb', line 21

def hit
  berserk? ? heal : super
end