rubywarrior 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +7 -0
  2. data/{CHANGELOG.rdoc → CHANGELOG.md} +21 -3
  3. data/Gemfile +10 -0
  4. data/Gemfile.lock +55 -0
  5. data/LICENSE +4 -4
  6. data/{README.rdoc → README.md} +115 -93
  7. data/Rakefile +4 -9
  8. data/bin/rubywarrior +1 -1
  9. data/features/step_definitions/common_steps.rb +2 -2
  10. data/features/step_definitions/interaction_steps.rb +7 -7
  11. data/features/support/env.rb +1 -1
  12. data/lib/ruby_warrior/game.rb +5 -3
  13. data/lib/ruby_warrior/level.rb +5 -1
  14. data/lib/ruby_warrior/player_generator.rb +3 -3
  15. data/lib/ruby_warrior/profile.rb +1 -1
  16. data/lib/ruby_warrior/tower.rb +1 -1
  17. data/rubywarrior.gemspec +16 -0
  18. data/spec/ruby_warrior/abilities/attack_spec.rb +10 -10
  19. data/spec/ruby_warrior/abilities/base_spec.rb +19 -19
  20. data/spec/ruby_warrior/abilities/bind_spec.rb +5 -5
  21. data/spec/ruby_warrior/abilities/direction_of_spec.rb +3 -3
  22. data/spec/ruby_warrior/abilities/direction_of_stairs_spec.rb +3 -3
  23. data/spec/ruby_warrior/abilities/distance_of_spec.rb +3 -3
  24. data/spec/ruby_warrior/abilities/explode_spec.rb +7 -7
  25. data/spec/ruby_warrior/abilities/feel_spec.rb +1 -1
  26. data/spec/ruby_warrior/abilities/form_spec.rb +14 -14
  27. data/spec/ruby_warrior/abilities/health_spec.rb +3 -3
  28. data/spec/ruby_warrior/abilities/listen_spec.rb +3 -3
  29. data/spec/ruby_warrior/abilities/look_spec.rb +3 -3
  30. data/spec/ruby_warrior/abilities/pivot_spec.rb +1 -1
  31. data/spec/ruby_warrior/abilities/rescue_spec.rb +8 -8
  32. data/spec/ruby_warrior/abilities/rest_spec.rb +7 -7
  33. data/spec/ruby_warrior/abilities/shoot_spec.rb +4 -4
  34. data/spec/ruby_warrior/abilities/throw_spec.rb +10 -10
  35. data/spec/ruby_warrior/abilities/walk_spec.rb +5 -5
  36. data/spec/ruby_warrior/core_additions_spec.rb +2 -2
  37. data/spec/ruby_warrior/floor_spec.rb +27 -27
  38. data/spec/ruby_warrior/game_spec.rb +36 -36
  39. data/spec/ruby_warrior/level_loader_spec.rb +19 -19
  40. data/spec/ruby_warrior/level_spec.rb +57 -57
  41. data/spec/ruby_warrior/player_generator_spec.rb +3 -3
  42. data/spec/ruby_warrior/position_spec.rb +43 -43
  43. data/spec/ruby_warrior/profile_spec.rb +59 -59
  44. data/spec/ruby_warrior/space_spec.rb +71 -71
  45. data/spec/ruby_warrior/tower_spec.rb +5 -5
  46. data/spec/ruby_warrior/turn_spec.rb +13 -13
  47. data/spec/ruby_warrior/ui_spec.rb +32 -32
  48. data/spec/ruby_warrior/units/archer_spec.rb +9 -9
  49. data/spec/ruby_warrior/units/base_spec.rb +42 -42
  50. data/spec/ruby_warrior/units/captive_spec.rb +9 -9
  51. data/spec/ruby_warrior/units/golem_spec.rb +9 -9
  52. data/spec/ruby_warrior/units/sludge_spec.rb +11 -11
  53. data/spec/ruby_warrior/units/thick_sludge_spec.rb +7 -7
  54. data/spec/ruby_warrior/units/warrior_spec.rb +23 -23
  55. data/spec/ruby_warrior/units/wizard_spec.rb +9 -9
  56. data/spec/spec_helper.rb +3 -2
  57. data/towers/beginner/level_002.rb +1 -1
  58. data/towers/beginner/level_003.rb +1 -1
  59. data/towers/beginner/level_005.rb +2 -2
  60. data/towers/beginner/level_006.rb +2 -2
  61. data/towers/intermediate/level_002.rb +1 -1
  62. data/towers/intermediate/level_003.rb +2 -2
  63. metadata +47 -67
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 0da1053639652ef190b19b22a47786adf5a31ed90e4f6575c177b71756cd66ab
4
+ data.tar.gz: 2f8ca01cc724b1e18fce98f2e8e16ad79978bbf05a7156937970ada0ddebeb03
5
+ SHA512:
6
+ metadata.gz: 2f554896bf063ac3fd423c22387aca81599df1fd580644e2dbdec1f15668dc0a53890ffcd803fa6172ca09450b23247de04112d889ffed1651c2f03e131c6fb7
7
+ data.tar.gz: 983eae03da65cd4e1ba8c918fe147164b4a3b48dce0b5855695798548d570929a5d3037c1468642349bc612d252c4f5c6cd6e05a913629801422b66951cca41e
@@ -1,4 +1,22 @@
1
- 0.1.2 (September 23, 2010)
1
+ ## 0.2.0 (March 26, 2024)
2
+
3
+ * Support Ruby 3.3 (thanks fpsvogel)
4
+
5
+ * Improve message when using --skip option (thanks dcki)
6
+
7
+
8
+ ## 0.1.3 (April 28, 2012)
9
+
10
+ * Making specs pass with latest RSpec.
11
+
12
+ * Lowering ace score for Beginner Level 6.
13
+
14
+ * Store relative tower paths in Profile so files can be moved.
15
+
16
+ * Other minor bug fixes (see commit history for details)
17
+
18
+
19
+ ## 0.1.2 (September 23, 2010)
2
20
 
3
21
  * Adding intermediate level 9 with distance_of ability
4
22
 
@@ -11,7 +29,7 @@
11
29
  * Mention direction when ability is performed
12
30
 
13
31
 
14
- 0.1.1 (Jan 3, 2010)
32
+ ## 0.1.1 (Jan 3, 2010)
15
33
 
16
34
  * Speeding up play speed a little
17
35
 
@@ -22,6 +40,6 @@
22
40
  * Keep track of last level played in profile and go back to normal mode when level is added
23
41
 
24
42
 
25
- 0.1.0 (Jan 2, 2010)
43
+ ## 0.1.0 (Jan 2, 2010)
26
44
 
27
45
  * initial release
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem 'base64'
4
+
5
+ group :test do
6
+ gem 'rake'
7
+ gem 'rspec', '~> 3.13.0'
8
+ gem 'cucumber'
9
+ gem 'mocha'
10
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,55 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ base64 (0.2.0)
5
+ builder (3.2.4)
6
+ cucumber (2.99.0)
7
+ builder (>= 2.1.2)
8
+ cucumber-core (~> 1.5.0)
9
+ cucumber-wire (~> 0.0.1)
10
+ diff-lcs (>= 1.1.3)
11
+ gherkin (~> 4.0)
12
+ multi_json (>= 1.7.5, < 2.0)
13
+ multi_test (>= 0.1.2)
14
+ cucumber-core (1.5.0)
15
+ gherkin (~> 4.0)
16
+ cucumber-wire (0.0.1)
17
+ diff-lcs (1.5.1)
18
+ gherkin (4.1.3)
19
+ mocha (2.1.0)
20
+ ruby2_keywords (>= 0.0.5)
21
+ multi_json (1.15.0)
22
+ multi_test (1.1.0)
23
+ prettier_print (1.2.1)
24
+ rake (13.1.0)
25
+ rspec (3.13.0)
26
+ rspec-core (~> 3.13.0)
27
+ rspec-expectations (~> 3.13.0)
28
+ rspec-mocks (~> 3.13.0)
29
+ rspec-core (3.13.0)
30
+ rspec-support (~> 3.13.0)
31
+ rspec-expectations (3.13.0)
32
+ diff-lcs (>= 1.2.0, < 2.0)
33
+ rspec-support (~> 3.13.0)
34
+ rspec-mocks (3.13.0)
35
+ diff-lcs (>= 1.2.0, < 2.0)
36
+ rspec-support (~> 3.13.0)
37
+ rspec-support (3.13.1)
38
+ ruby2_keywords (0.0.5)
39
+ syntax_tree (6.2.0)
40
+ prettier_print (>= 1.2.0)
41
+
42
+ PLATFORMS
43
+ arm64-darwin-23
44
+ ruby
45
+
46
+ DEPENDENCIES
47
+ base64
48
+ cucumber
49
+ mocha
50
+ rake
51
+ rspec (~> 3.13.0)
52
+ syntax_tree
53
+
54
+ BUNDLED WITH
55
+ 2.5.3
data/LICENSE CHANGED
@@ -1,5 +1,5 @@
1
- Copyright (c) 2010 Ryan Bates
2
-
1
+ Copyright (c) 2024 Ryan Bates
2
+
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
5
5
  "Software"), to deal in the Software without restriction, including
@@ -7,10 +7,10 @@ without limitation the rights to use, copy, modify, merge, publish,
7
7
  distribute, sublicense, and/or sell copies of the Software, and to
8
8
  permit persons to whom the Software is furnished to do so, subject to
9
9
  the following conditions:
10
-
10
+
11
11
  The above copyright notice and this permission notice shall be
12
12
  included in all copies or substantial portions of the Software.
13
-
13
+
14
14
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
15
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
16
  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@@ -1,50 +1,58 @@
1
- = Ruby Warrior
1
+ # Ruby Warrior
2
2
 
3
- This is a game designed to teach the Ruby language and artificial intelligence in a fun, interactive way.
3
+ This is a game designed to teach the Ruby language in a fun and interactive way.
4
4
 
5
5
  You play as a warrior climbing a tall tower to reach the precious Ruby at the top level. On each floor you need to write a Ruby script to instruct the warrior to battle enemies, rescue captives, and reach the stairs. You have some idea of what each floor contains, but you never know for certain what will happen. You must give the Warrior enough artificial intelligence up-front to find his own way.
6
6
 
7
- NOTE: The player directory structure changed on July 18, 2009. If you have an old profile using the "level-00*" structure then move the contents of the last level into the parent directory.
7
+ > Note: The player directory structure changed on July 18, 2009. If you have an old profile using the `level-00*` structure then move the contents of the last level into the parent directory.
8
8
 
9
9
 
10
- == Getting Started
10
+ ## Getting Started
11
11
 
12
12
  First install the gem.
13
13
 
14
- gem install rubywarrior
14
+ ```sh
15
+ gem install rubywarrior
16
+ ```
15
17
 
16
- Then run the "rubywarrior" command to setup your profile. This will create a rubywarrior directory in your current location where you will find a player.rb file in your profile's directory containing this:
18
+ > As of version 0.2.0, this gem has been updated to work with Ruby 3.3. If you have difficulty running it in an older version of Ruby, try using an older version of the gem.
17
19
 
18
- class Player
19
- def play_turn(warrior)
20
- # your code goes here
21
- end
20
+ Then run the `rubywarrior` command to setup your profile. This will create a rubywarrior directory in your current location where you will find a player.rb file in your profile's directory containing this:
21
+
22
+ ```rb
23
+ class Player
24
+ def play_turn(warrior)
25
+ # your code goes here
22
26
  end
27
+ end
28
+ ```
23
29
 
24
- Your objective is to fill this "play_turn" method with commands to instruct the warrior what to do. With each level your abilities will grow along with the difficulty. See the README in your profile's directory for details on what abilities your warrior has available on the current level.
30
+ Your objective is to fill this `play_turn` method with commands to instruct the warrior what to do. With each level your abilities will grow along with the difficulty. See the README in your profile's directory for details on what abilities your warrior has available on the current level.
25
31
 
26
32
  Here is a simple example which will instruct the warrior to attack if he feels an enemy, otherwise he will walk forward.
27
33
 
28
- class Player
29
- def play_turn(warrior)
30
- if warrior.feel.enemy?
31
- warrior.attack!
32
- else
33
- warrior.walk!
34
- end
34
+ ```rb
35
+ class Player
36
+ def play_turn(warrior)
37
+ if warrior.feel.enemy?
38
+ warrior.attack!
39
+ else
40
+ warrior.walk!
35
41
  end
36
42
  end
43
+ end
44
+ ```
37
45
 
38
- Once you are done editing player.rb, save the file and run the "rubywarrior" command again to start playing the level. The play happens through a series of turns. On each one, your "play_turn" method is called along with any enemy's.
46
+ Once you are done editing `player.rb`, save the file and run the `rubywarrior` command again to start playing the level. The play happens through a series of turns. On each one, your `play_turn` method is called along with any enemy's.
39
47
 
40
48
  You cannot change your code in the middle of a level. You must take into account everything that may happen on that level and give your warrior the proper instructions from the start.
41
49
 
42
- Losing all of your health will cause you to fail the level. You are not punished by this, you simply need to go back to your player.rb, improve your code, and try again.
50
+ Losing all of your health will cause you to fail the level. You are not punished by this, you simply need to go back to your `player.rb`, improve your code, and try again.
43
51
 
44
- Once you pass a level (by reaching the stairs), the profile README will be updated for the next level. Alter the player.rb file and run rubywarrior again to play the next level.
52
+ Once you pass a level (by reaching the stairs), the profile README will be updated for the next level. Alter the `player.rb` file and run `rubywarrior` again to play the next level.
45
53
 
46
54
 
47
- == Scoring
55
+ ## Scoring
48
56
 
49
57
  Your objective is to not only reach the stairs, but to get the highest score you can. There are many ways you can earn points on a level.
50
58
 
@@ -58,127 +66,141 @@ A total score is kept as you progress through the levels. When you pass a level,
58
66
  Don't be too concerned about scoring perfectly in the beginning. After you reach the top of the tower you will be able to re-run the tower and fine-tune your warrior to get the highest score. See the Epic Mode below for details.
59
67
 
60
68
 
61
- == Perspective
69
+ ## Perspective
62
70
 
63
71
  Even though this is a text-based game, think of it as two-dimensional where you are viewing from overhead. Each level is always rectangular in shape and is made up of a number of squares. Only one unit can be on a given square at a time, and your objective is to find the square with the stairs. Here is an example level map and key.
64
72
 
65
- ----
66
- |C s>|
67
- | S s|
68
- |C @ |
69
- ----
70
-
71
- > = Stairs
72
- @ = Warrior (20 HP)
73
- s = Sludge (12 HP)
74
- S = Thick Sludge (24 HP)
75
- C = Captive (1 HP)
73
+ ```
74
+ ----
75
+ |C s>|
76
+ | S s|
77
+ |C @ |
78
+ ----
76
79
 
80
+ > = Stairs
81
+ @ = Warrior (20 HP)
82
+ s = Sludge (12 HP)
83
+ S = Thick Sludge (24 HP)
84
+ C = Captive (1 HP)
85
+ ```
77
86
 
78
- == Commanding the Warrior
87
+
88
+ ## Commanding the Warrior
79
89
 
80
90
  When you first start, your warrior will only have a few abilities, but with each level your abilities will grow. A warrior has two kinds of abilities: actions and senses.
81
91
 
82
92
  An action is something that effects the game in some way. You can easily tell an action because it ends in an exclamation mark. Only one action can be performed per turn, so choose wisely. Here are some examples of actions.
83
93
 
84
- warrior.walk!
85
- Move in given direction (forward by default).
94
+ ```
95
+ warrior.walk!
96
+ Move in given direction (forward by default).
86
97
 
87
- warrior.attack!
88
- Attack the unit in given direction (forward by default).
98
+ warrior.attack!
99
+ Attack the unit in given direction (forward by default).
89
100
 
90
- warrior.rest!
91
- Gain 10% of max health back, but do nothing more.
101
+ warrior.rest!
102
+ Gain 10% of max health back, but do nothing more.
92
103
 
93
- warrior.bind!
94
- Bind unit in given direction to keep him from moving (forward by default).
104
+ warrior.bind!
105
+ Bind unit in given direction to keep him from moving (forward by default).
95
106
 
96
- warrior.rescue!
97
- Rescue a captive from his chains (earning 50 points) in given direction (forward by default).
107
+ warrior.rescue!
108
+ Rescue a captive from his chains (earning 20 points) in given direction (forward by default).
109
+ ```
98
110
 
99
111
 
100
112
  A sense is something which gathers information about the floor. You can perform senses as often as you want per turn to gather information about your surroundings and to aid you in choosing the proper action. Senses do NOT end in an exclamation mark.
101
113
 
102
- warrior.feel
103
- Returns a Space for the given direction (forward by default).
114
+ ```
115
+ warrior.feel
116
+ Returns a Space for the given direction (forward by default).
104
117
 
105
- warrior.health
106
- Returns an integer representing your health.
118
+ warrior.health
119
+ Returns an integer representing your health.
107
120
 
108
- warrior.distance
109
- Returns the number of spaces the stairs are away.
121
+ warrior.distance
122
+ Returns the number of spaces the stairs are away.
110
123
 
111
- warrior.listen
112
- Returns an array of all spaces which have units in them.
124
+ warrior.listen
125
+ Returns an array of all spaces which have units in them.
126
+ ```
113
127
 
114
128
 
115
129
  Since what you sense will change each turn, you should record what information you gather for use on the next turn. For example, you can determine if you are being attacked if your health has gone down since the last turn.
116
130
 
117
131
 
118
- == Spaces
132
+ ## Spaces
119
133
 
120
134
  Whenever you sense an area, often one or multiple spaces (in an array) will be returned. A space is an object representing a square in the level. You can call methods on a space to gather information about what is there. Here are the various methods you can call on a space.
121
135
 
122
- space.empty?
123
- If true, this means that nothing (except maybe stairs) is at this location and you can walk here.
124
-
125
- space.stairs?
126
- Determine if stairs are at that location
127
-
128
- space.enemy?
129
- Determine if an enemy unit is at this location.
130
-
131
- space.captive?
132
- Determine if a captive is at this location.
133
-
134
- space.wall?
135
- Returns true if this is the edge of the level. You can't walk here.
136
-
137
- space.ticking?
138
- Returns true if this space contains a bomb which will explode in time.
139
-
140
- space.golem?
141
- Returns true if a golem is occupying this space.
142
-
143
- You will often call these methods directly after a sense. For example, the "feel" sense returns one space. You can call "captive?" on this to determine if a captive is in front of you.
144
-
145
- warrior.feel.captive?
146
-
147
-
148
- == Golem
136
+ ```
137
+ space.empty?
138
+ If true, this means that nothing (except maybe stairs) is at this location and you can walk here.
139
+
140
+ space.stairs?
141
+ Determine if stairs are at that location
142
+
143
+ space.enemy?
144
+ Determine if an enemy unit is at this location.
145
+
146
+ space.captive?
147
+ Determine if a captive is at this location.
148
+
149
+ space.wall?
150
+ Returns true if this is the edge of the level. You can't walk here.
151
+
152
+ space.ticking?
153
+ Returns true if this space contains a bomb which will explode in time.
154
+
155
+ space.golem?
156
+ Returns true if a golem is occupying this space.
157
+ ```
158
+
159
+ You will often call these methods directly after a sense. For example, the `feel` sense returns one space. You can call `captive?` on this to determine if a captive is in front of you.
160
+
161
+ ```
162
+ warrior.feel.captive?
163
+ ```
164
+
165
+
166
+ ## Golem
149
167
 
150
168
  Along your journey you may discover the ability to create a golem. This is a separate unit which you also control. The turn handling is done through a block. Here is an example.
151
169
 
152
- warrior.form! do |golem|
153
- golem.attack! if golem.feel.enemy?
154
- end
170
+ ```rb
171
+ warrior.form! do |golem|
172
+ golem.attack! if golem.feel.enemy?
173
+ end
174
+ ```
155
175
 
156
176
  Complex logic can be placed in this block just like in the player turn method. You may want to move the logic into its own class or create multiple classes for different types of golems. You can create multiple golems in a level, but each one will take half of the warrior's health.
157
177
 
158
178
 
159
- == Epic Mode
160
-
179
+ ## Epic Mode
180
+
161
181
  Once you reach the top of the tower, you will enter epic mode. When running rubywarrior again it will run your current player.rb through all levels in the tower without stopping.
162
182
 
163
183
  Your warrior will most likely not succeed the first time around, so use the -l option on levels you are having difficulty or want to fine-tune the scoring.
164
184
 
165
- rubywarrior -l 3
185
+ ```sh
186
+ rubywarrior -l 3
187
+ ```
166
188
 
167
189
  Once your warrior reaches the top again you will receive an average grade, along with a grade for each level. The grades from best to worst are S, A, B, C, D and F. Try to get S on each level for the ultimate score.
168
190
 
169
- Note: I'm in the process of fine-tuning the grading system. If you find the "S" grade to be too easy or too difficult to achieve on a given level, please add an issue for this on GitHub.
191
+ Note: I'm in the process of fine-tuning the grading system. If you find the `S` grade to be too easy or too difficult to achieve on a given level, please add an issue for this on GitHub.
170
192
 
171
193
 
172
- == Tips
194
+ ## Tips
173
195
 
174
- If you ever get stuck on a level, review the README documentation and be sure you're trying each ability out. If you can't keep your health up, be sure to "rest" when no enemy is around (while keeping an eye on your health). Also, try to use far-ranged weapons whenever possible (such as the bow).
196
+ If you ever get stuck on a level, review the README documentation and be sure you're trying each ability out. If you can't keep your health up, be sure to `rest` when no enemy is around (while keeping an eye on your health). Also, try to use far-ranged weapons whenever possible (such as the bow).
175
197
 
176
- Remember, you're working in Ruby here. Don't simply fill up the "play_turn" method with a lot of code. Organize it with methods and classes. The player directory is set up as a load path so you can include other ruby files from your player.rb file.
198
+ Remember, you're working in Ruby here. Don't simply fill up the `play_turn` method with a lot of code. Organize it with methods and classes. The player directory is set up as a load path so you can include other ruby files from your player.rb file.
177
199
 
178
200
  Senses are cheap, so use them liberally. Store the sensed information to help you better determine what actions to take in the future.
179
201
 
180
- Running "rubywarrior" while you are in your profile directory will auto-select that profile so you don't have to each time.
202
+ Running `rubywarrior` while you are in your profile directory will auto-select that profile so you don't have to each time.
181
203
 
182
204
  If you're aiming for points, remember to sweep the area. Even if you're close to the stairs, don't go in until you've gotten everything (if you have the health). Use far-ranged senses (such as look and listen) to determine if there are any enemies left.
183
205
 
184
- Make sure to try the different options you can pass to the rubywarrior command. Run "rubywarrior --help" to see them all.
206
+ Make sure to try the different options you can pass to the rubywarrior command. Run `rubywarrior --help` to see them all.
data/Rakefile CHANGED
@@ -1,17 +1,12 @@
1
1
  require 'rake'
2
- require 'spec'
2
+ require 'rspec'
3
+ require 'rspec/core/rake_task'
3
4
  require 'cucumber'
4
-
5
5
  require 'cucumber/rake/task'
6
- require 'spec/rake/spectask'
7
-
8
-
9
- spec_files = Rake::FileList["spec/**/*_spec.rb"]
10
6
 
11
7
  desc "Run specs"
12
- Spec::Rake::SpecTask.new do |t|
13
- t.spec_files = spec_files
14
- t.spec_opts = ["-c"]
8
+ RSpec::Core::RakeTask.new(:spec) do |t|
9
+ t.pattern = "spec/**/*_spec.rb"
15
10
  end
16
11
 
17
12
  Cucumber::Rake::Task.new(:features) do |t|
data/bin/rubywarrior CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
- require File.dirname(__FILE__) + '/../lib/ruby_warrior'
2
+ require_relative '../lib/ruby_warrior'
3
3
 
4
4
  runner = RubyWarrior::Runner.new(ARGV, STDIN, STDOUT)
5
5
  runner.run
@@ -11,9 +11,9 @@ When /^I copy fixture "([^\"]*)" to "([^\"]*)"$/ do |from, to|
11
11
  end
12
12
 
13
13
  Then /^I should find file at "([^\"]*)"$/ do |path|
14
- File.exist?(path).should be_true
14
+ expect(File.exist?(path)).to eq(true)
15
15
  end
16
16
 
17
17
  Then /^I should find no file at "([^\"]*)"$/ do |path|
18
- File.exist?(path).should be_false
18
+ expect(File.exist?(path)).to eq(false)
19
19
  end
@@ -1,9 +1,9 @@
1
1
  Given /^a profile named "([^\"]*)" on "([^\"]*)"$/ do |name, tower|
2
- When 'I run rubywarrior'
3
- And 'I answer "y" to "create one?"'
4
- And 'I choose "' + tower + '" for "tower"'
5
- And 'I answer "' + name + '" to "name"'
6
- Then 'I should see "generated"'
2
+ step 'I run rubywarrior'
3
+ step 'I answer "y" to "create one?"'
4
+ step 'I choose "' + tower + '" for "tower"'
5
+ step 'I answer "' + name + '" to "name"'
6
+ step 'I should see "generated"'
7
7
  end
8
8
 
9
9
  Given /^no profile at "([^\"]*)"$/ do |path|
@@ -57,9 +57,9 @@ When /^I wait until it says "([^\"]*)"$/ do |phrase|
57
57
  end
58
58
 
59
59
  Then /^I should see "([^\"]*)"$/ do |phrase|
60
- @io.gets_until_include(phrase).should include(phrase)
60
+ expect(@io.gets_until_include(phrase)).to include(phrase)
61
61
  end
62
62
 
63
63
  Then /^I should not see "([^\"]*)" before "([^\"]*)"$/ do |first_phrase, second_phrase|
64
- @io.gets_until_include(second_phrase).should_not include(first_phrase)
64
+ expect(@io.gets_until_include(second_phrase)).to_not include(first_phrase)
65
65
  end
@@ -1,5 +1,5 @@
1
1
  require 'cucumber'
2
- require 'spec'
2
+ require 'rspec'
3
3
 
4
4
  require File.dirname(__FILE__) + '/../../lib/ruby_warrior'
5
5
 
@@ -94,7 +94,9 @@ module RubyWarrior
94
94
  end
95
95
 
96
96
  def request_next_level
97
- if !Config.skip_input? && (next_level.exists? ? UI.ask("Would you like to continue on to the next level?") : UI.ask("Would you like to continue on to epic mode?"))
97
+ if Config.skip_input?
98
+ UI.puts "Staying on current level. Remove --skip option to continue on to the next level."
99
+ elsif (next_level.exists? ? UI.ask("Would you like to continue on to the next level?") : UI.ask("Would you like to continue on to epic mode?"))
98
100
  if next_level.exists?
99
101
  prepare_next_level
100
102
  UI.puts "See the updated README in the rubywarrior/#{profile.directory_name} directory."
@@ -103,7 +105,7 @@ module RubyWarrior
103
105
  UI.puts "Run rubywarrior again to play epic mode."
104
106
  end
105
107
  else
106
- UI.puts "Staying on current level. Try to earn more points next time."
108
+ UI.puts "Staying on current level."
107
109
  end
108
110
  end
109
111
 
@@ -156,7 +158,7 @@ module RubyWarrior
156
158
  end
157
159
 
158
160
  def tower_paths
159
- Dir[File.expand_path(File.dirname(__FILE__) + '/../../towers/*')]
161
+ Dir[File.expand_path('../../../towers/*', __FILE__)]
160
162
  end
161
163
 
162
164
 
@@ -24,7 +24,11 @@ module RubyWarrior
24
24
  end
25
25
 
26
26
  def load_path
27
- @profile.tower_path + "/level_" + @number.to_s.rjust(3, '0') + ".rb"
27
+ File.join(
28
+ File.expand_path('../../../towers/', __FILE__),
29
+ File.basename(@profile.tower_path) + "/level_" +
30
+ @number.to_s.rjust(3, '0') + ".rb"
31
+ )
28
32
  end
29
33
 
30
34
  def load_level
@@ -19,7 +19,7 @@ module RubyWarrior
19
19
  # TODO refactor and test this method
20
20
  def generate
21
21
  if level.number == 1
22
- FileUtils.mkdir_p(level.player_path)
22
+ FileUtils.mkdir_p(level.player_path) unless File.exist? level.player_path
23
23
  FileUtils.cp(templates_path + '/player.rb', level.player_path)
24
24
  end
25
25
 
@@ -29,13 +29,13 @@ module RubyWarrior
29
29
  end
30
30
 
31
31
  def templates_path
32
- File.expand_path(File.dirname(__FILE__) + "/../../templates")
32
+ File.expand_path("../../../templates", __FILE__)
33
33
  end
34
34
 
35
35
  private
36
36
 
37
37
  def read_template(path)
38
- ERB.new(File.read(path), nil, '-').result(binding)
38
+ ERB.new(File.read(path), trim_mode: '-').result(binding)
39
39
  end
40
40
  end
41
41
  end
@@ -62,7 +62,7 @@ module RubyWarrior
62
62
  end
63
63
 
64
64
  def tower
65
- Tower.new(@tower_path)
65
+ Tower.new(File.basename @tower_path)
66
66
  end
67
67
 
68
68
  def current_level
@@ -3,7 +3,7 @@ module RubyWarrior
3
3
  attr_reader :path
4
4
 
5
5
  def initialize(path)
6
- @path = path
6
+ @path = File.join(File.expand_path('../../../towers/', __FILE__), path)
7
7
  end
8
8
 
9
9
  def name
@@ -0,0 +1,16 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "rubywarrior"
3
+ s.version = "0.2.0"
4
+ s.author = "Ryan Bates"
5
+ s.email = "ryan@railscasts.com"
6
+ s.homepage = "https://github.com/ryanb/ruby-warrior"
7
+ s.summary = "Game written in Ruby for learning Ruby."
8
+ s.description = "You play as a warrior climbing a tall tower. On each floor you need to write a Ruby script to instruct the warrior to battle enemies, rescue captives, and reach the stairs."
9
+ s.license = "MIT"
10
+
11
+ s.files = Dir["{lib,spec,features,towers,templates,bin}/**/*", "[A-Z]*", "init.rb"]
12
+ s.require_path = "lib"
13
+ s.executables = ["rubywarrior"]
14
+
15
+ s.required_rubygems_version = ">= 1.3.4"
16
+ end