Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

adding archer unit

  • Loading branch information...
commit a5b9dbdcc21a7e7efc2998366cd149260db96c39 1 parent 78a6720
Ryan Bates authored
1  lib/ruby_warrior.rb
View
@@ -15,6 +15,7 @@
require 'ruby_warrior/units/base'
require 'ruby_warrior/units/warrior'
require 'ruby_warrior/units/sludge'
+require 'ruby_warrior/units/archer'
require 'ruby_warrior/abilities/base'
require 'ruby_warrior/abilities/walk'
30 lib/ruby_warrior/units/archer.rb
View
@@ -0,0 +1,30 @@
+module RubyWarrior
+ module Units
+ class Archer < Base
+ def initialize
+ add_abilities :shoot!, :look
+ end
+
+ def play_turn(turn)
+ [:forward, :left, :right].each do |direction|
+ look(direction).each do |space|
+ if space.warrior?
+ turn.shoot!(direction)
+ return
+ elsif !space.empty?
+ break
+ end
+ end
+ end
+ end
+
+ def shoot_power
+ 3
+ end
+
+ def max_health
+ 7
+ end
+ end
+ end
+end
19 spec/ruby_warrior/units/archer_spec.rb
View
@@ -0,0 +1,19 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+describe RubyWarrior::Units::Archer do
+ before(:each) do
+ @sludge = RubyWarrior::Units::Archer.new
+ end
+
+ it "should have look and shoot abilities" do
+ @sludge.abilities.keys.to_set.should == [:shoot!, :look].to_set
+ end
+
+ it "should have shoot power of 3" do
+ @sludge.shoot_power.should == 3
+ end
+
+ it "should have 7 max health" do
+ @sludge.max_health.should == 7
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.