Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

health no longer dips below zero #79

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/ruby_warrior/units/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions spec/ruby_warrior/abilities/explode_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -27,6 +27,6 @@
@explode.pass_turn
@captive.health.should == 10
@explode.pass_turn
@captive.health.should == -90
@captive.health.should == 0
end
end
4 changes: 2 additions & 2 deletions spec/ruby_warrior/abilities/throw_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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