Module: Adjective::Vulnerable

Defined in:
lib/adjective/concerns/vulnerable.rb

Instance Method Summary collapse

Instance Method Details

#alive?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/adjective/concerns/vulnerable.rb', line 27

def alive?
  @hitpoints > 0
end

#dead?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/adjective/concerns/vulnerable.rb', line 31

def dead?
  @hitpoints == 0
end

#heal_for(healing) ⇒ Object



22
23
24
25
# File 'lib/adjective/concerns/vulnerable.rb', line 22

def heal_for(healing)
  @hitpoints += healing
  normalize_hitpoints
end

#heal_to_fullObject



17
18
19
20
# File 'lib/adjective/concerns/vulnerable.rb', line 17

def heal_to_full
  @hitpoints = @max_hitpoints
  normalize_hitpoints
end

#initialize_vulnerability(hitpoints = 1, max_hitpoints = 10) ⇒ Object



4
5
6
7
8
9
# File 'lib/adjective/concerns/vulnerable.rb', line 4

def initialize_vulnerability(hitpoints = 1, max_hitpoints = 10)
  @hitpoints = hitpoints
  @max_hitpoints = max_hitpoints
  self.class.send(:attr_accessor, :hitpoints)
  self.class.send(:attr_accessor, :max_hitpoints)     
end

#normalize_hitpointsObject



35
36
37
38
# File 'lib/adjective/concerns/vulnerable.rb', line 35

def normalize_hitpoints
  @hitpoints = 0 if @hitpoints < 0
  @hitpoints = @max_hitpoints if @hitpoints > @max_hitpoints
end

#take_damage(damage) ⇒ Object



11
12
13
14
15
# File 'lib/adjective/concerns/vulnerable.rb', line 11

def take_damage(damage)
  @hitpoints -= damage
  normalize_hitpoints
  return self
end