karnowski-ruby-warrior 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. data/.gitignore +3 -0
  2. data/LICENSE +20 -0
  3. data/README.rdoc +156 -0
  4. data/Rakefile +36 -0
  5. data/VERSION +1 -0
  6. data/bin/rubywarrior +8 -0
  7. data/features/levels.feature +50 -0
  8. data/features/profiles.feature +46 -0
  9. data/features/step_definitions/common_steps.rb +7 -0
  10. data/features/step_definitions/interaction_steps.rb +53 -0
  11. data/features/support/env.rb +8 -0
  12. data/features/support/mockio.rb +57 -0
  13. data/features/towers.feature +14 -0
  14. data/lib/ruby_warrior.rb +41 -0
  15. data/lib/ruby_warrior/abilities/attack.rb +24 -0
  16. data/lib/ruby_warrior/abilities/base.rb +36 -0
  17. data/lib/ruby_warrior/abilities/bind.rb +19 -0
  18. data/lib/ruby_warrior/abilities/direction_of.rb +13 -0
  19. data/lib/ruby_warrior/abilities/direction_of_stairs.rb +13 -0
  20. data/lib/ruby_warrior/abilities/distance.rb +13 -0
  21. data/lib/ruby_warrior/abilities/explode.rb +16 -0
  22. data/lib/ruby_warrior/abilities/feel.rb +13 -0
  23. data/lib/ruby_warrior/abilities/health.rb +13 -0
  24. data/lib/ruby_warrior/abilities/listen.rb +15 -0
  25. data/lib/ruby_warrior/abilities/look.rb +15 -0
  26. data/lib/ruby_warrior/abilities/pivot.rb +16 -0
  27. data/lib/ruby_warrior/abilities/rescue.rb +23 -0
  28. data/lib/ruby_warrior/abilities/rest.rb +20 -0
  29. data/lib/ruby_warrior/abilities/shoot.rb +23 -0
  30. data/lib/ruby_warrior/abilities/walk.rb +20 -0
  31. data/lib/ruby_warrior/config.rb +11 -0
  32. data/lib/ruby_warrior/core_additions.rb +25 -0
  33. data/lib/ruby_warrior/floor.rb +71 -0
  34. data/lib/ruby_warrior/game.rb +160 -0
  35. data/lib/ruby_warrior/level.rb +93 -0
  36. data/lib/ruby_warrior/level_loader.rb +52 -0
  37. data/lib/ruby_warrior/player_generator.rb +41 -0
  38. data/lib/ruby_warrior/position.rb +80 -0
  39. data/lib/ruby_warrior/profile.rb +86 -0
  40. data/lib/ruby_warrior/space.rb +63 -0
  41. data/lib/ruby_warrior/tower.rb +14 -0
  42. data/lib/ruby_warrior/turn.rb +38 -0
  43. data/lib/ruby_warrior/ui.rb +64 -0
  44. data/lib/ruby_warrior/units/archer.rb +34 -0
  45. data/lib/ruby_warrior/units/base.rb +95 -0
  46. data/lib/ruby_warrior/units/captive.rb +30 -0
  47. data/lib/ruby_warrior/units/sludge.rb +30 -0
  48. data/lib/ruby_warrior/units/thick_sludge.rb +13 -0
  49. data/lib/ruby_warrior/units/warrior.rb +58 -0
  50. data/lib/ruby_warrior/units/wizard.rb +34 -0
  51. data/ruby-warrior.gemspec +191 -0
  52. data/script/console +8 -0
  53. data/spec/fixtures/short-tower/level_001.rb +14 -0
  54. data/spec/fixtures/short-tower/level_002.rb +14 -0
  55. data/spec/fixtures/walking_player.rb +5 -0
  56. data/spec/ruby_warrior/abilities/attack_spec.rb +51 -0
  57. data/spec/ruby_warrior/abilities/base_spec.rb +24 -0
  58. data/spec/ruby_warrior/abilities/bind_spec.rb +19 -0
  59. data/spec/ruby_warrior/abilities/direction_of_spec.rb +13 -0
  60. data/spec/ruby_warrior/abilities/direction_of_stairs_spec.rb +13 -0
  61. data/spec/ruby_warrior/abilities/distance_spec.rb +13 -0
  62. data/spec/ruby_warrior/abilities/explode_spec.rb +21 -0
  63. data/spec/ruby_warrior/abilities/feel_spec.rb +13 -0
  64. data/spec/ruby_warrior/abilities/health_spec.rb +13 -0
  65. data/spec/ruby_warrior/abilities/listen_spec.rb +17 -0
  66. data/spec/ruby_warrior/abilities/look_spec.rb +15 -0
  67. data/spec/ruby_warrior/abilities/pivot_spec.rb +18 -0
  68. data/spec/ruby_warrior/abilities/rescue_spec.rb +40 -0
  69. data/spec/ruby_warrior/abilities/rest_spec.rb +29 -0
  70. data/spec/ruby_warrior/abilities/shoot_spec.rb +22 -0
  71. data/spec/ruby_warrior/abilities/walk_spec.rb +25 -0
  72. data/spec/ruby_warrior/floor_spec.rb +81 -0
  73. data/spec/ruby_warrior/game_spec.rb +96 -0
  74. data/spec/ruby_warrior/level_loader_spec.rb +54 -0
  75. data/spec/ruby_warrior/level_spec.rb +163 -0
  76. data/spec/ruby_warrior/player_generator_spec.rb +12 -0
  77. data/spec/ruby_warrior/position_spec.rb +103 -0
  78. data/spec/ruby_warrior/profile_spec.rb +125 -0
  79. data/spec/ruby_warrior/space_spec.rb +165 -0
  80. data/spec/ruby_warrior/tower_spec.rb +15 -0
  81. data/spec/ruby_warrior/turn_spec.rb +42 -0
  82. data/spec/ruby_warrior/ui_spec.rb +96 -0
  83. data/spec/ruby_warrior/units/archer_spec.rb +23 -0
  84. data/spec/ruby_warrior/units/base_spec.rb +133 -0
  85. data/spec/ruby_warrior/units/captive_spec.rb +34 -0
  86. data/spec/ruby_warrior/units/sludge_spec.rb +27 -0
  87. data/spec/ruby_warrior/units/thick_sludge_spec.rb +19 -0
  88. data/spec/ruby_warrior/units/warrior_spec.rb +60 -0
  89. data/spec/ruby_warrior/units/wizard_spec.rb +23 -0
  90. data/spec/spec_helper.rb +7 -0
  91. data/templates/README.erb +20 -0
  92. data/templates/player.rb +5 -0
  93. data/towers/beginner/level_001.rb +15 -0
  94. data/towers/beginner/level_002.rb +17 -0
  95. data/towers/beginner/level_003.rb +20 -0
  96. data/towers/beginner/level_004.rb +17 -0
  97. data/towers/beginner/level_005.rb +21 -0
  98. data/towers/beginner/level_006.rb +18 -0
  99. data/towers/beginner/level_007.rb +17 -0
  100. data/towers/beginner/level_008.rb +20 -0
  101. data/towers/beginner/level_009.rb +19 -0
  102. data/towers/intermediate/level_001.rb +17 -0
  103. data/towers/intermediate/level_002.rb +19 -0
  104. data/towers/intermediate/level_003.rb +22 -0
  105. data/towers/intermediate/level_004.rb +23 -0
  106. data/towers/intermediate/level_005.rb +18 -0
  107. data/towers/intermediate/level_006.rb +23 -0
  108. metadata +218 -0
@@ -0,0 +1,34 @@
1
+ module RubyWarrior
2
+ module Units
3
+ class Wizard < 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
+ turn.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
+ 11
23
+ end
24
+
25
+ def max_health
26
+ 3
27
+ end
28
+
29
+ def to_map
30
+ "w"
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,191 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{ruby-warrior}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Ryan Bates"]
12
+ s.date = %q{2009-09-25}
13
+ s.default_executable = %q{rubywarrior}
14
+ s.email = %q{ryan@railscasts.com}
15
+ s.executables = ["rubywarrior"]
16
+ s.extra_rdoc_files = [
17
+ "LICENSE",
18
+ "README.rdoc"
19
+ ]
20
+ s.files = [
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "bin/rubywarrior",
27
+ "features/levels.feature",
28
+ "features/profiles.feature",
29
+ "features/step_definitions/common_steps.rb",
30
+ "features/step_definitions/interaction_steps.rb",
31
+ "features/support/env.rb",
32
+ "features/support/mockio.rb",
33
+ "features/towers.feature",
34
+ "lib/ruby_warrior.rb",
35
+ "lib/ruby_warrior/abilities/attack.rb",
36
+ "lib/ruby_warrior/abilities/base.rb",
37
+ "lib/ruby_warrior/abilities/bind.rb",
38
+ "lib/ruby_warrior/abilities/direction_of.rb",
39
+ "lib/ruby_warrior/abilities/direction_of_stairs.rb",
40
+ "lib/ruby_warrior/abilities/distance.rb",
41
+ "lib/ruby_warrior/abilities/explode.rb",
42
+ "lib/ruby_warrior/abilities/feel.rb",
43
+ "lib/ruby_warrior/abilities/health.rb",
44
+ "lib/ruby_warrior/abilities/listen.rb",
45
+ "lib/ruby_warrior/abilities/look.rb",
46
+ "lib/ruby_warrior/abilities/pivot.rb",
47
+ "lib/ruby_warrior/abilities/rescue.rb",
48
+ "lib/ruby_warrior/abilities/rest.rb",
49
+ "lib/ruby_warrior/abilities/shoot.rb",
50
+ "lib/ruby_warrior/abilities/walk.rb",
51
+ "lib/ruby_warrior/config.rb",
52
+ "lib/ruby_warrior/core_additions.rb",
53
+ "lib/ruby_warrior/floor.rb",
54
+ "lib/ruby_warrior/game.rb",
55
+ "lib/ruby_warrior/level.rb",
56
+ "lib/ruby_warrior/level_loader.rb",
57
+ "lib/ruby_warrior/player_generator.rb",
58
+ "lib/ruby_warrior/position.rb",
59
+ "lib/ruby_warrior/profile.rb",
60
+ "lib/ruby_warrior/space.rb",
61
+ "lib/ruby_warrior/tower.rb",
62
+ "lib/ruby_warrior/turn.rb",
63
+ "lib/ruby_warrior/ui.rb",
64
+ "lib/ruby_warrior/units/archer.rb",
65
+ "lib/ruby_warrior/units/base.rb",
66
+ "lib/ruby_warrior/units/captive.rb",
67
+ "lib/ruby_warrior/units/sludge.rb",
68
+ "lib/ruby_warrior/units/thick_sludge.rb",
69
+ "lib/ruby_warrior/units/warrior.rb",
70
+ "lib/ruby_warrior/units/wizard.rb",
71
+ "ruby-warrior.gemspec",
72
+ "script/console",
73
+ "spec/fixtures/short-tower/level_001.rb",
74
+ "spec/fixtures/short-tower/level_002.rb",
75
+ "spec/fixtures/walking_player.rb",
76
+ "spec/ruby_warrior/abilities/attack_spec.rb",
77
+ "spec/ruby_warrior/abilities/base_spec.rb",
78
+ "spec/ruby_warrior/abilities/bind_spec.rb",
79
+ "spec/ruby_warrior/abilities/direction_of_spec.rb",
80
+ "spec/ruby_warrior/abilities/direction_of_stairs_spec.rb",
81
+ "spec/ruby_warrior/abilities/distance_spec.rb",
82
+ "spec/ruby_warrior/abilities/explode_spec.rb",
83
+ "spec/ruby_warrior/abilities/feel_spec.rb",
84
+ "spec/ruby_warrior/abilities/health_spec.rb",
85
+ "spec/ruby_warrior/abilities/listen_spec.rb",
86
+ "spec/ruby_warrior/abilities/look_spec.rb",
87
+ "spec/ruby_warrior/abilities/pivot_spec.rb",
88
+ "spec/ruby_warrior/abilities/rescue_spec.rb",
89
+ "spec/ruby_warrior/abilities/rest_spec.rb",
90
+ "spec/ruby_warrior/abilities/shoot_spec.rb",
91
+ "spec/ruby_warrior/abilities/walk_spec.rb",
92
+ "spec/ruby_warrior/floor_spec.rb",
93
+ "spec/ruby_warrior/game_spec.rb",
94
+ "spec/ruby_warrior/level_loader_spec.rb",
95
+ "spec/ruby_warrior/level_spec.rb",
96
+ "spec/ruby_warrior/player_generator_spec.rb",
97
+ "spec/ruby_warrior/position_spec.rb",
98
+ "spec/ruby_warrior/profile_spec.rb",
99
+ "spec/ruby_warrior/space_spec.rb",
100
+ "spec/ruby_warrior/tower_spec.rb",
101
+ "spec/ruby_warrior/turn_spec.rb",
102
+ "spec/ruby_warrior/ui_spec.rb",
103
+ "spec/ruby_warrior/units/archer_spec.rb",
104
+ "spec/ruby_warrior/units/base_spec.rb",
105
+ "spec/ruby_warrior/units/captive_spec.rb",
106
+ "spec/ruby_warrior/units/sludge_spec.rb",
107
+ "spec/ruby_warrior/units/thick_sludge_spec.rb",
108
+ "spec/ruby_warrior/units/warrior_spec.rb",
109
+ "spec/ruby_warrior/units/wizard_spec.rb",
110
+ "spec/spec_helper.rb",
111
+ "templates/README.erb",
112
+ "templates/player.rb",
113
+ "tmp/.gitignore",
114
+ "towers/beginner/level_001.rb",
115
+ "towers/beginner/level_002.rb",
116
+ "towers/beginner/level_003.rb",
117
+ "towers/beginner/level_004.rb",
118
+ "towers/beginner/level_005.rb",
119
+ "towers/beginner/level_006.rb",
120
+ "towers/beginner/level_007.rb",
121
+ "towers/beginner/level_008.rb",
122
+ "towers/beginner/level_009.rb",
123
+ "towers/intermediate/level_001.rb",
124
+ "towers/intermediate/level_002.rb",
125
+ "towers/intermediate/level_003.rb",
126
+ "towers/intermediate/level_004.rb",
127
+ "towers/intermediate/level_005.rb",
128
+ "towers/intermediate/level_006.rb"
129
+ ]
130
+ s.homepage = %q{http://github.com/ryanb/ruby-warrior}
131
+ s.rdoc_options = ["--charset=UTF-8"]
132
+ s.require_paths = ["lib"]
133
+ s.rubygems_version = %q{1.3.5}
134
+ s.summary = %q{Game written in Ruby for learning Ruby and artificial intelligence.}
135
+ s.test_files = [
136
+ "spec/fixtures/short-tower/level_001.rb",
137
+ "spec/fixtures/short-tower/level_002.rb",
138
+ "spec/fixtures/walking_player.rb",
139
+ "spec/ruby_warrior/abilities/attack_spec.rb",
140
+ "spec/ruby_warrior/abilities/base_spec.rb",
141
+ "spec/ruby_warrior/abilities/bind_spec.rb",
142
+ "spec/ruby_warrior/abilities/direction_of_spec.rb",
143
+ "spec/ruby_warrior/abilities/direction_of_stairs_spec.rb",
144
+ "spec/ruby_warrior/abilities/distance_spec.rb",
145
+ "spec/ruby_warrior/abilities/explode_spec.rb",
146
+ "spec/ruby_warrior/abilities/feel_spec.rb",
147
+ "spec/ruby_warrior/abilities/health_spec.rb",
148
+ "spec/ruby_warrior/abilities/listen_spec.rb",
149
+ "spec/ruby_warrior/abilities/look_spec.rb",
150
+ "spec/ruby_warrior/abilities/pivot_spec.rb",
151
+ "spec/ruby_warrior/abilities/rescue_spec.rb",
152
+ "spec/ruby_warrior/abilities/rest_spec.rb",
153
+ "spec/ruby_warrior/abilities/shoot_spec.rb",
154
+ "spec/ruby_warrior/abilities/walk_spec.rb",
155
+ "spec/ruby_warrior/floor_spec.rb",
156
+ "spec/ruby_warrior/game_spec.rb",
157
+ "spec/ruby_warrior/level_loader_spec.rb",
158
+ "spec/ruby_warrior/level_spec.rb",
159
+ "spec/ruby_warrior/player_generator_spec.rb",
160
+ "spec/ruby_warrior/position_spec.rb",
161
+ "spec/ruby_warrior/profile_spec.rb",
162
+ "spec/ruby_warrior/space_spec.rb",
163
+ "spec/ruby_warrior/tower_spec.rb",
164
+ "spec/ruby_warrior/turn_spec.rb",
165
+ "spec/ruby_warrior/ui_spec.rb",
166
+ "spec/ruby_warrior/units/archer_spec.rb",
167
+ "spec/ruby_warrior/units/base_spec.rb",
168
+ "spec/ruby_warrior/units/captive_spec.rb",
169
+ "spec/ruby_warrior/units/sludge_spec.rb",
170
+ "spec/ruby_warrior/units/thick_sludge_spec.rb",
171
+ "spec/ruby_warrior/units/warrior_spec.rb",
172
+ "spec/ruby_warrior/units/wizard_spec.rb",
173
+ "spec/spec_helper.rb"
174
+ ]
175
+
176
+ if s.respond_to? :specification_version then
177
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
178
+ s.specification_version = 3
179
+
180
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
181
+ s.add_development_dependency(%q<rspec>, [">= 0"])
182
+ s.add_development_dependency(%q<cucumber>, [">= 0"])
183
+ else
184
+ s.add_dependency(%q<rspec>, [">= 0"])
185
+ s.add_dependency(%q<cucumber>, [">= 0"])
186
+ end
187
+ else
188
+ s.add_dependency(%q<rspec>, [">= 0"])
189
+ s.add_dependency(%q<cucumber>, [">= 0"])
190
+ end
191
+ end
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ # File: script/console
3
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
+
5
+ # loading the spec_helper file even though this isn't necessarily for specs
6
+ # it's just a convenient, quick way to load all the requirements.
7
+ puts "Loading console"
8
+ exec "#{irb} -r irb/completion -r #{File.dirname(__FILE__) + '/../lib/ruby_warrior.rb'} -r #{File.dirname(__FILE__) + '/../features/support/mockio.rb'} --simple-prompt"
@@ -0,0 +1,14 @@
1
+ # --
2
+ # |@>|
3
+ # --
4
+
5
+ description "You see before yourself a long hallway with stairs at the end. There is nothing in the way."
6
+ tip "Call warrior.walk! to walk forward in the Player 'play_turn' method."
7
+
8
+ time_bonus 15
9
+ size 2, 1
10
+ stairs 1, 0
11
+
12
+ warrior 0, 0, :east do |u|
13
+ u.add_abilities :walk!
14
+ end
@@ -0,0 +1,14 @@
1
+ # --
2
+ # |@>|
3
+ # --
4
+
5
+ description "You see before yourself a long hallway with stairs at the end. There is nothing in the way."
6
+ tip "Call warrior.walk! to walk forward in the Player 'play_turn' method."
7
+
8
+ time_bonus 15
9
+ size 2, 1
10
+ stairs 1, 0
11
+
12
+ warrior 0, 0, :east do |u|
13
+ u.add_abilities :walk!
14
+ end
@@ -0,0 +1,5 @@
1
+ class Player
2
+ def play_turn(warrior)
3
+ warrior.walk!
4
+ end
5
+ end
@@ -0,0 +1,51 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe RubyWarrior::Abilities::Attack do
4
+ before(:each) do
5
+ @attacker = stub(:position => stub, :attack_power => 3, :say => nil)
6
+ @attack = RubyWarrior::Abilities::Attack.new(@attacker)
7
+ end
8
+
9
+ it "should subtract attack power amount from health" do
10
+ receiver = RubyWarrior::Units::Base.new
11
+ receiver.stubs(:alive?).returns(true)
12
+ receiver.health = 5
13
+ @attack.stubs(:unit).returns(receiver)
14
+ @attack.perform
15
+ receiver.health.should == 2
16
+ end
17
+
18
+ it "should do nothing if recipient is nil" do
19
+ @attack.stubs(:unit).returns(nil)
20
+ lambda { @attack.perform }.should_not raise_error
21
+ end
22
+
23
+ it "should get object at position from offset" do
24
+ @attacker.position.expects(:relative_space).with(1, 0)
25
+ @attack.space(:forward)
26
+ end
27
+
28
+ it "should award points when killing unit" do
29
+ receiver = stub(:take_damage => nil, :max_health => 8, :alive? => false)
30
+ @attack.stubs(:unit).returns(receiver)
31
+ @attacker.expects(:earn_points).with(8)
32
+ @attack.perform
33
+ end
34
+
35
+ it "should not award points when not killing unit" do
36
+ receiver = stub(:max_health => 8, :alive? => true)
37
+ receiver.expects(:take_damage)
38
+ @attack.stubs(:unit).returns(receiver)
39
+ @attacker.expects(:earn_points).never
40
+ @attack.perform
41
+ end
42
+
43
+ it "should reduce attack power when attacking backward" do
44
+ receiver = RubyWarrior::Units::Base.new
45
+ receiver.stubs(:alive?).returns(true)
46
+ receiver.health = 5
47
+ @attack.stubs(:unit).returns(receiver)
48
+ @attack.perform(:backward)
49
+ receiver.health.should == 3
50
+ end
51
+ end
@@ -0,0 +1,24 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe RubyWarrior::Abilities::Base do
4
+ before(:each) do
5
+ @unit = stub
6
+ @ability = RubyWarrior::Abilities::Base.new(@unit)
7
+ end
8
+
9
+ it "should have offset for directions" do
10
+ @ability.offset(:forward).should == [1, 0]
11
+ @ability.offset(:right).should == [0, 1]
12
+ @ability.offset(:backward).should == [-1, 0]
13
+ @ability.offset(:left).should == [0, -1]
14
+ end
15
+
16
+ it "should fetch unit at given direction with distance" do
17
+ @ability.expects(:space).with(:right, 3).returns(stub(:unit => 'unit'))
18
+ @ability.unit(:right, 3).should == 'unit'
19
+ end
20
+
21
+ it "should have no description" do
22
+ @ability.description.should be_nil
23
+ end
24
+ end
@@ -0,0 +1,19 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe RubyWarrior::Abilities::Bind do
4
+ before(:each) do
5
+ @bind = RubyWarrior::Abilities::Bind.new(stub(:say => nil))
6
+ end
7
+
8
+ it "should bind recipient" do
9
+ receiver = RubyWarrior::Units::Base.new
10
+ @bind.stubs(:unit).returns(receiver)
11
+ @bind.perform
12
+ receiver.should be_bound
13
+ end
14
+
15
+ it "should do nothing if no recipient" do
16
+ @bind.stubs(:unit).returns(nil)
17
+ lambda { @bind.perform }.should_not raise_error
18
+ end
19
+ end
@@ -0,0 +1,13 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe RubyWarrior::Abilities::DirectionOf do
4
+ before(:each) do
5
+ @position = stub
6
+ @distance = RubyWarrior::Abilities::DirectionOf.new(stub(:position => @position, :say => nil))
7
+ end
8
+
9
+ it "should return relative direction of given space" do
10
+ @position.stubs(:relative_direction_of).with(:space).returns(:left)
11
+ @distance.perform(:space).should == :left
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe RubyWarrior::Abilities::DirectionOfStairs do
4
+ before(:each) do
5
+ @position = stub
6
+ @distance = RubyWarrior::Abilities::DirectionOfStairs.new(stub(:position => @position, :say => nil))
7
+ end
8
+
9
+ it "should return relative direction of stairs" do
10
+ @position.stubs(:relative_direction_of_stairs).returns(:left)
11
+ @distance.perform.should == :left
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe RubyWarrior::Abilities::Distance do
4
+ before(:each) do
5
+ @position = stub
6
+ @distance = RubyWarrior::Abilities::Distance.new(stub(:position => @position, :say => nil))
7
+ end
8
+
9
+ it "should return distance from stairs" do
10
+ @position.stubs(:distance_from_stairs).returns(5)
11
+ @distance.perform.should == 5
12
+ end
13
+ end
@@ -0,0 +1,21 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe RubyWarrior::Abilities::Explode do
4
+ before(:each) do
5
+ @captive = RubyWarrior::Units::Captive.new
6
+ @explode = RubyWarrior::Abilities::Explode.new(@captive)
7
+ end
8
+
9
+ it "should set health to 0" do
10
+ @captive.position = stub
11
+ @captive.health = 10
12
+ @explode.perform
13
+ @captive.health.should == 0
14
+ end
15
+
16
+ it "should do nothing if no position" do
17
+ @captive.health = 10
18
+ @explode.perform
19
+ @captive.health.should == 10
20
+ end
21
+ end
@@ -0,0 +1,13 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe RubyWarrior::Abilities::Feel do
4
+ before(:each) do
5
+ @unit = stub(:position => stub, :say => nil)
6
+ @feel = RubyWarrior::Abilities::Feel.new(@unit)
7
+ end
8
+
9
+ it "should get object at position from offset" do
10
+ @unit.position.expects(:relative_space).with(1, 0)
11
+ @feel.perform(:forward)
12
+ end
13
+ end