forked from ryanb/ruby-warrior
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding direction_of ability to determine direction towards any given …
…space
- Loading branch information
Showing
7 changed files
with
45 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module RubyWarrior | ||
module Abilities | ||
class DirectionOf < Base | ||
def description | ||
"Pass a Space as an argument, and the direction (:left, :right, :forward, :backward) to that space will be returned." | ||
end | ||
|
||
def perform(space) | ||
@unit.position.relative_direction_of(space) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,4 +10,4 @@ def perform | |
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
require File.dirname(__FILE__) + '/../../spec_helper' | ||
|
||
describe RubyWarrior::Abilities::DirectionOf do | ||
before(:each) do | ||
@position = stub | ||
@distance = RubyWarrior::Abilities::DirectionOf.new(stub(:position => @position, :say => nil)) | ||
end | ||
|
||
it "should return relative direction of given space" do | ||
@position.stubs(:relative_direction_of).with(:space).returns(:left) | ||
@distance.perform(:space).should == :left | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters