Permalink
Browse files

detonate ticking explosive when hit by bomb - closes #20

  • Loading branch information...
1 parent 5aeb11f commit 867655c89e2588e7d76de4e4fe061ab37c385972 @ryanb committed Jan 3, 2010
Showing with 26 additions and 4 deletions.
  1. +16 −4 lib/ruby_warrior/abilities/throw.rb
  2. +10 −0 spec/ruby_warrior/abilities/throw_spec.rb
@@ -8,11 +8,23 @@ def description
def perform(direction = :forward)
if @unit.position
@unit.say "throws a bomb #{direction}"
- receiver = space(direction, 2, 0).unit
- damage(receiver, 10) if receiver
+ bomb(direction, 2, 0, 10)
[[2, 1], [2, -1], [3, 0], [1, 0]].each do |x, y|
- receiver = space(direction, x, y).unit
- damage(receiver, 1) if receiver
+ bomb(direction, x, y, 1)
+ end
+ end
+ end
+
+ def bomb(direction, x, y, damage_amount)
+ if @unit.position
+ receiver = space(direction, x, y).unit
+ if receiver
+ if receiver.abilities[:explode!]
+ receiver.say "caught in bomb's flames which detonates ticking explosive"
+ receiver.abilities[:explode!].perform
+ else
+ damage(receiver, damage_amount)
+ end
end
end
end
@@ -33,4 +33,14 @@
target_unit.health.should == 5
second_unit.health.should == 14
end
+
+ it "should detonate an explosive if any unit has one" do
+ captive = RubyWarrior::Units::Captive.new
+ captive.health = 1
+ captive.bomb_time = 3
+ @floor.add(captive, 1, 2)
+ @throw.perform
+ captive.health.should == -99
+ @warrior.health.should == -80
+ end
end

0 comments on commit 867655c

Please sign in to comment.