module Adjective::Vulnerable
Public Instance Methods
alive?()
click to toggle source
# File lib/adjective/concerns/vulnerable.rb, line 27 def alive? @hitpoints > 0 end
dead?()
click to toggle source
# File lib/adjective/concerns/vulnerable.rb, line 31 def dead? @hitpoints == 0 end
heal_for(healing)
click to toggle source
# File lib/adjective/concerns/vulnerable.rb, line 22 def heal_for(healing) @hitpoints += healing normalize_hitpoints end
heal_to_full()
click to toggle source
# 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)
click to toggle source
# 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_hitpoints()
click to toggle source
# 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)
click to toggle source
# File lib/adjective/concerns/vulnerable.rb, line 11 def take_damage(damage) @hitpoints -= damage normalize_hitpoints return self end