From b942db125b024b883c40e38a80b79c46891e57bc Mon Sep 17 00:00:00 2001 From: rheber Date: Sun, 9 Nov 2014 15:10:09 +1100 Subject: [PATCH] health no longer dips below zero --- lib/ruby_warrior/units/base.rb | 2 ++ spec/ruby_warrior/abilities/explode_spec.rb | 8 ++++---- spec/ruby_warrior/abilities/throw_spec.rb | 4 ++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/ruby_warrior/units/base.rb b/lib/ruby_warrior/units/base.rb index a7a2abd0..bda15075 100644 --- a/lib/ruby_warrior/units/base.rb +++ b/lib/ruby_warrior/units/base.rb @@ -23,6 +23,8 @@ def take_damage(amount) unbind if bound? if health self.health -= amount + # health can't be negative + self.health = 0 if self.health < 0 say "takes #{amount} damage, #{health} health power left" if health <= 0 @position = nil diff --git a/spec/ruby_warrior/abilities/explode_spec.rb b/spec/ruby_warrior/abilities/explode_spec.rb index bf4d7e6c..0b98536f 100644 --- a/spec/ruby_warrior/abilities/explode_spec.rb +++ b/spec/ruby_warrior/abilities/explode_spec.rb @@ -10,14 +10,14 @@ @explode = RubyWarrior::Abilities::Explode.new(@captive) end - it "should subtract 100 health from each unit on the floor" do + it "should subtract up to 100 health from each unit on the floor" do unit = RubyWarrior::Units::Base.new unit.health = 20 @floor.add(unit, 0, 1) @captive.health = 10 @explode.perform - @captive.health.should == -90 - unit.health.should == -80 + @captive.health.should == 0 + unit.health.should == 0 end it "should explode when bomb time reaches zero" do @@ -27,6 +27,6 @@ @explode.pass_turn @captive.health.should == 10 @explode.pass_turn - @captive.health.should == -90 + @captive.health.should == 0 end end diff --git a/spec/ruby_warrior/abilities/throw_spec.rb b/spec/ruby_warrior/abilities/throw_spec.rb index 3dffdd35..6462ea68 100644 --- a/spec/ruby_warrior/abilities/throw_spec.rb +++ b/spec/ruby_warrior/abilities/throw_spec.rb @@ -40,7 +40,7 @@ captive.add_abilities :explode! @floor.add(captive, 1, 1) @detonate.perform - captive.health.should == -99 - @warrior.health.should == -80 + captive.health.should == 0 + @warrior.health.should == 0 end end