Permalink
Browse files

adding basic throw bomb ability, need to support multiple directions …

…still
  • Loading branch information...
1 parent 5be20cb commit 9acca7001b0db2326dfcd72d1f84e2c0ab5c9392 @ryanb ryanb committed Jan 3, 2010
Showing with 46 additions and 0 deletions.
  1. +1 −0 lib/ruby_warrior.rb
  2. +21 −0 lib/ruby_warrior/abilities/throw.rb
  3. +24 −0 spec/ruby_warrior/abilities/throw_spec.rb
View
@@ -42,3 +42,4 @@
require 'ruby_warrior/abilities/direction_of_stairs'
require 'ruby_warrior/abilities/direction_of'
require 'ruby_warrior/abilities/explode'
+require 'ruby_warrior/abilities/throw'
@@ -0,0 +1,21 @@
+module RubyWarrior
+ module Abilities
+ class Throw < Base
+ def description
+ "Throw a bomb in a given direction (forward by default) which damages second space and lightly damages surrounding 4 spaces."
+ end
+
+ def perform(direction = :forward)
+ if @unit.position
+ @unit.say "throws a bomb"
+ receiver = @unit.position.relative_space(2, 0).unit
+ damage(receiver, 10) if receiver
+ [[2, 1], [2, -1], [3, 0], [1, 0]].each do |x, y|
+ receiver = @unit.position.relative_space(x, y).unit
+ damage(receiver, 1) if receiver
+ end
+ end
+ end
+ end
+ end
+end
@@ -0,0 +1,24 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+describe RubyWarrior::Abilities::Throw do
+ before(:each) do
+ @floor = RubyWarrior::Floor.new
+ @floor.width = 2
+ @floor.height = 3
+ @warrior = RubyWarrior::Units::Warrior.new
+ @floor.add(@warrior, 0, 0, :south)
+ @throw = RubyWarrior::Abilities::Throw.new(@warrior)
+ end
+
+ it "should subtract 10 from units tow spaces away and 1 from units surrounding that space" do
+ target_unit = RubyWarrior::Units::Base.new
+ target_unit.health = 15
+ second_unit = RubyWarrior::Units::Base.new
+ second_unit.health = 15
+ @floor.add(target_unit, 0, 2)
+ @floor.add(second_unit, 1, 2)
+ @throw.perform
+ target_unit.health.should == 5
+ second_unit.health.should == 14
+ end
+end

0 comments on commit 9acca70

Please sign in to comment.