Skip to content

Commit 04df8b9

Browse files
committed
raising an exception when performing an ability with a bad direction
1 parent c31ea4a commit 04df8b9

File tree

13 files changed

+24
-1
lines changed

13 files changed

+24
-1
lines changed

CHANGELOG.rdoc

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
* Raising an exception when performing an ability with a bad direction.
2+
13
* Hard wrapping clue text to 80 characters
24

35
* Mention direction when ability is performed

lib/ruby_warrior/abilities/attack.rb

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ def description
66
end
77

88
def perform(direction = :forward)
9+
verify_direction(direction)
910
receiver = unit(direction)
1011
if receiver
1112
@unit.say "attacks #{direction} and hits #{receiver}"

lib/ruby_warrior/abilities/base.rb

+6
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ def description
3333
def pass_turn
3434
# callback which is triggered every turn
3535
end
36+
37+
def verify_direction(direction)
38+
unless Position::RELATIVE_DIRECTIONS.include? direction
39+
raise "Unknown direction \"#{direction}\". Should be :forward, :backward, :left or :right."
40+
end
41+
end
3642
end
3743
end
3844
end

lib/ruby_warrior/abilities/bind.rb

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ def description
66
end
77

88
def perform(direction = :forward)
9+
verify_direction(direction)
910
receiver = unit(direction)
1011
if receiver
1112
@unit.say "binds #{direction} and restricts #{receiver}"

lib/ruby_warrior/abilities/detonate.rb

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ def description
66
end
77

88
def perform(direction = :forward)
9+
verify_direction(direction)
910
if @unit.position
1011
@unit.say "detonates a bomb #{direction}"
1112
bomb(direction, 1, 0, 8)

lib/ruby_warrior/abilities/feel.rb

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ def description
66
end
77

88
def perform(direction = :forward)
9+
verify_direction(direction)
910
space(direction)
1011
end
1112
end

lib/ruby_warrior/abilities/look.rb

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ def description
66
end
77

88
def perform(direction = :forward)
9+
verify_direction(direction)
910
[1, 2, 3].map do |amount|
1011
space(direction, amount)
1112
end

lib/ruby_warrior/abilities/pivot.rb

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ def description
88
end
99

1010
def perform(direction = :backward)
11+
verify_direction(direction)
1112
@unit.position.rotate(ROTATION_DIRECTIONS.index(direction))
1213
@unit.say "pivots #{direction}"
1314
end

lib/ruby_warrior/abilities/rescue.rb

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ def description
66
end
77

88
def perform(direction = :forward)
9+
verify_direction(direction)
910
if space(direction).captive?
1011
recipient = unit(direction)
1112
@unit.say "unbinds #{direction} and rescues #{recipient}"

lib/ruby_warrior/abilities/shoot.rb

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ def description
66
end
77

88
def perform(direction = :forward)
9+
verify_direction(direction)
910
receiver = multi_unit(direction, 1..3).compact.first
1011
if receiver
1112
@unit.say "shoots #{direction} and hits #{receiver}"

lib/ruby_warrior/abilities/walk.rb

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ def description
66
end
77

88
def perform(direction = :forward)
9+
verify_direction(direction)
910
if @unit.position
1011
@unit.say "walks #{direction}"
1112
if space(direction).empty?

spec/ruby_warrior/abilities/base_spec.rb

+6
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,10 @@
2929
it "should have no description" do
3030
@ability.description.should be_nil
3131
end
32+
33+
it "should raise an exception if direction isn't recognized" do
34+
lambda {
35+
@ability.verify_direction(:foo)
36+
}.should raise_error("Unknown direction \"foo\". Should be :forward, :backward, :left or :right.")
37+
end
3238
end

towers/intermediate/level_006.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
description "What's that ticking? Some captives have a timed bomb at their feet!"
77
tip "Hurry and rescue captives first that have space.ticking?, they'll soon go!"
8-
clue "Avoid fighting enemies at first. Go around them until you've rescued all of the ticking captives."
8+
clue "Avoid fighting enemies at first. Use warrior.listen and space.ticking? and quickly rescue those captives."
99

1010
time_bonus 50
1111
ace_score 108

0 commit comments

Comments
 (0)