Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

raising an exception when performing an ability with a bad direction

  • Loading branch information...
commit 04df8b9f8e666c83413e10a0974d5a3078fe3c99 1 parent c31ea4a
@ryanb authored
View
2  CHANGELOG.rdoc
@@ -1,3 +1,5 @@
+* Raising an exception when performing an ability with a bad direction.
+
* Hard wrapping clue text to 80 characters
* Mention direction when ability is performed
View
1  lib/ruby_warrior/abilities/attack.rb
@@ -6,6 +6,7 @@ def description
end
def perform(direction = :forward)
+ verify_direction(direction)
receiver = unit(direction)
if receiver
@unit.say "attacks #{direction} and hits #{receiver}"
View
6 lib/ruby_warrior/abilities/base.rb
@@ -33,6 +33,12 @@ def description
def pass_turn
# callback which is triggered every turn
end
+
+ def verify_direction(direction)
+ unless Position::RELATIVE_DIRECTIONS.include? direction
+ raise "Unknown direction \"#{direction}\". Should be :forward, :backward, :left or :right."
+ end
+ end
end
end
end
View
1  lib/ruby_warrior/abilities/bind.rb
@@ -6,6 +6,7 @@ def description
end
def perform(direction = :forward)
+ verify_direction(direction)
receiver = unit(direction)
if receiver
@unit.say "binds #{direction} and restricts #{receiver}"
View
1  lib/ruby_warrior/abilities/detonate.rb
@@ -6,6 +6,7 @@ def description
end
def perform(direction = :forward)
+ verify_direction(direction)
if @unit.position
@unit.say "detonates a bomb #{direction}"
bomb(direction, 1, 0, 8)
View
1  lib/ruby_warrior/abilities/feel.rb
@@ -6,6 +6,7 @@ def description
end
def perform(direction = :forward)
+ verify_direction(direction)
space(direction)
end
end
View
1  lib/ruby_warrior/abilities/look.rb
@@ -6,6 +6,7 @@ def description
end
def perform(direction = :forward)
+ verify_direction(direction)
[1, 2, 3].map do |amount|
space(direction, amount)
end
View
1  lib/ruby_warrior/abilities/pivot.rb
@@ -8,6 +8,7 @@ def description
end
def perform(direction = :backward)
+ verify_direction(direction)
@unit.position.rotate(ROTATION_DIRECTIONS.index(direction))
@unit.say "pivots #{direction}"
end
View
1  lib/ruby_warrior/abilities/rescue.rb
@@ -6,6 +6,7 @@ def description
end
def perform(direction = :forward)
+ verify_direction(direction)
if space(direction).captive?
recipient = unit(direction)
@unit.say "unbinds #{direction} and rescues #{recipient}"
View
1  lib/ruby_warrior/abilities/shoot.rb
@@ -6,6 +6,7 @@ def description
end
def perform(direction = :forward)
+ verify_direction(direction)
receiver = multi_unit(direction, 1..3).compact.first
if receiver
@unit.say "shoots #{direction} and hits #{receiver}"
View
1  lib/ruby_warrior/abilities/walk.rb
@@ -6,6 +6,7 @@ def description
end
def perform(direction = :forward)
+ verify_direction(direction)
if @unit.position
@unit.say "walks #{direction}"
if space(direction).empty?
View
6 spec/ruby_warrior/abilities/base_spec.rb
@@ -29,4 +29,10 @@
it "should have no description" do
@ability.description.should be_nil
end
+
+ it "should raise an exception if direction isn't recognized" do
+ lambda {
+ @ability.verify_direction(:foo)
+ }.should raise_error("Unknown direction \"foo\". Should be :forward, :backward, :left or :right.")
+ end
end
View
2  towers/intermediate/level_006.rb
@@ -5,7 +5,7 @@
description "What's that ticking? Some captives have a timed bomb at their feet!"
tip "Hurry and rescue captives first that have space.ticking?, they'll soon go!"
-clue "Avoid fighting enemies at first. Go around them until you've rescued all of the ticking captives."
+clue "Avoid fighting enemies at first. Use warrior.listen and space.ticking? and quickly rescue those captives."
time_bonus 50
ace_score 108
Please sign in to comment.
Something went wrong with that request. Please try again.