Skip to content
This repository
Browse code

adding archer unit

  • Loading branch information...
commit a5b9dbdcc21a7e7efc2998366cd149260db96c39 1 parent 78a6720
Ryan Bates authored
1  lib/ruby_warrior.rb
@@ -15,6 +15,7 @@
15 15 require 'ruby_warrior/units/base'
16 16 require 'ruby_warrior/units/warrior'
17 17 require 'ruby_warrior/units/sludge'
  18 +require 'ruby_warrior/units/archer'
18 19
19 20 require 'ruby_warrior/abilities/base'
20 21 require 'ruby_warrior/abilities/walk'
30 lib/ruby_warrior/units/archer.rb
... ... @@ -0,0 +1,30 @@
  1 +module RubyWarrior
  2 + module Units
  3 + class Archer < Base
  4 + def initialize
  5 + add_abilities :shoot!, :look
  6 + end
  7 +
  8 + def play_turn(turn)
  9 + [:forward, :left, :right].each do |direction|
  10 + look(direction).each do |space|
  11 + if space.warrior?
  12 + turn.shoot!(direction)
  13 + return
  14 + elsif !space.empty?
  15 + break
  16 + end
  17 + end
  18 + end
  19 + end
  20 +
  21 + def shoot_power
  22 + 3
  23 + end
  24 +
  25 + def max_health
  26 + 7
  27 + end
  28 + end
  29 + end
  30 +end
19 spec/ruby_warrior/units/archer_spec.rb
... ... @@ -0,0 +1,19 @@
  1 +require File.dirname(__FILE__) + '/../../spec_helper'
  2 +
  3 +describe RubyWarrior::Units::Archer do
  4 + before(:each) do
  5 + @sludge = RubyWarrior::Units::Archer.new
  6 + end
  7 +
  8 + it "should have look and shoot abilities" do
  9 + @sludge.abilities.keys.to_set.should == [:shoot!, :look].to_set
  10 + end
  11 +
  12 + it "should have shoot power of 3" do
  13 + @sludge.shoot_power.should == 3
  14 + end
  15 +
  16 + it "should have 7 max health" do
  17 + @sludge.max_health.should == 7
  18 + end
  19 +end

0 comments on commit a5b9dbd

Please sign in to comment.
Something went wrong with that request. Please try again.