rubywarrior 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. data/CHANGELOG.rdoc +3 -0
  2. data/LICENSE +20 -0
  3. data/README.rdoc +170 -0
  4. data/Rakefile +21 -0
  5. data/bin/rubywarrior +5 -0
  6. data/features/command_options.feature +46 -0
  7. data/features/levels.feature +51 -0
  8. data/features/profiles.feature +56 -0
  9. data/features/step_definitions/common_steps.rb +19 -0
  10. data/features/step_definitions/interaction_steps.rb +65 -0
  11. data/features/support/env.rb +12 -0
  12. data/features/support/mockio.rb +57 -0
  13. data/features/towers.feature +14 -0
  14. data/lib/ruby_warrior.rb +44 -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 +22 -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 +193 -0
  35. data/lib/ruby_warrior/level.rb +119 -0
  36. data/lib/ruby_warrior/level_loader.rb +56 -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 +104 -0
  40. data/lib/ruby_warrior/runner.rb +33 -0
  41. data/lib/ruby_warrior/space.rb +63 -0
  42. data/lib/ruby_warrior/tower.rb +14 -0
  43. data/lib/ruby_warrior/turn.rb +38 -0
  44. data/lib/ruby_warrior/ui.rb +54 -0
  45. data/lib/ruby_warrior/units/archer.rb +34 -0
  46. data/lib/ruby_warrior/units/base.rb +95 -0
  47. data/lib/ruby_warrior/units/captive.rb +30 -0
  48. data/lib/ruby_warrior/units/sludge.rb +30 -0
  49. data/lib/ruby_warrior/units/thick_sludge.rb +13 -0
  50. data/lib/ruby_warrior/units/warrior.rb +58 -0
  51. data/lib/ruby_warrior/units/wizard.rb +34 -0
  52. data/spec/fixtures/short-tower/level_001.rb +15 -0
  53. data/spec/fixtures/short-tower/level_002.rb +15 -0
  54. data/spec/fixtures/walking_player.rb +5 -0
  55. data/spec/ruby_warrior/abilities/attack_spec.rb +51 -0
  56. data/spec/ruby_warrior/abilities/base_spec.rb +24 -0
  57. data/spec/ruby_warrior/abilities/bind_spec.rb +19 -0
  58. data/spec/ruby_warrior/abilities/direction_of_spec.rb +13 -0
  59. data/spec/ruby_warrior/abilities/direction_of_stairs_spec.rb +13 -0
  60. data/spec/ruby_warrior/abilities/distance_spec.rb +13 -0
  61. data/spec/ruby_warrior/abilities/explode_spec.rb +21 -0
  62. data/spec/ruby_warrior/abilities/feel_spec.rb +13 -0
  63. data/spec/ruby_warrior/abilities/health_spec.rb +13 -0
  64. data/spec/ruby_warrior/abilities/listen_spec.rb +17 -0
  65. data/spec/ruby_warrior/abilities/look_spec.rb +15 -0
  66. data/spec/ruby_warrior/abilities/pivot_spec.rb +18 -0
  67. data/spec/ruby_warrior/abilities/rescue_spec.rb +40 -0
  68. data/spec/ruby_warrior/abilities/rest_spec.rb +29 -0
  69. data/spec/ruby_warrior/abilities/shoot_spec.rb +22 -0
  70. data/spec/ruby_warrior/abilities/walk_spec.rb +25 -0
  71. data/spec/ruby_warrior/floor_spec.rb +81 -0
  72. data/spec/ruby_warrior/game_spec.rb +119 -0
  73. data/spec/ruby_warrior/level_loader_spec.rb +54 -0
  74. data/spec/ruby_warrior/level_spec.rb +203 -0
  75. data/spec/ruby_warrior/player_generator_spec.rb +12 -0
  76. data/spec/ruby_warrior/position_spec.rb +103 -0
  77. data/spec/ruby_warrior/profile_spec.rb +144 -0
  78. data/spec/ruby_warrior/space_spec.rb +165 -0
  79. data/spec/ruby_warrior/tower_spec.rb +15 -0
  80. data/spec/ruby_warrior/turn_spec.rb +42 -0
  81. data/spec/ruby_warrior/ui_spec.rb +93 -0
  82. data/spec/ruby_warrior/units/archer_spec.rb +23 -0
  83. data/spec/ruby_warrior/units/base_spec.rb +133 -0
  84. data/spec/ruby_warrior/units/captive_spec.rb +34 -0
  85. data/spec/ruby_warrior/units/sludge_spec.rb +27 -0
  86. data/spec/ruby_warrior/units/thick_sludge_spec.rb +19 -0
  87. data/spec/ruby_warrior/units/warrior_spec.rb +60 -0
  88. data/spec/ruby_warrior/units/wizard_spec.rb +23 -0
  89. data/spec/spec_helper.rb +10 -0
  90. data/templates/README.erb +20 -0
  91. data/templates/player.rb +5 -0
  92. data/towers/beginner/level_001.rb +16 -0
  93. data/towers/beginner/level_002.rb +18 -0
  94. data/towers/beginner/level_003.rb +21 -0
  95. data/towers/beginner/level_004.rb +18 -0
  96. data/towers/beginner/level_005.rb +22 -0
  97. data/towers/beginner/level_006.rb +19 -0
  98. data/towers/beginner/level_007.rb +18 -0
  99. data/towers/beginner/level_008.rb +21 -0
  100. data/towers/beginner/level_009.rb +20 -0
  101. data/towers/intermediate/level_001.rb +18 -0
  102. data/towers/intermediate/level_002.rb +20 -0
  103. data/towers/intermediate/level_003.rb +23 -0
  104. data/towers/intermediate/level_004.rb +24 -0
  105. data/towers/intermediate/level_005.rb +19 -0
  106. data/towers/intermediate/level_006.rb +24 -0
  107. metadata +167 -0
data/CHANGELOG.rdoc ADDED
@@ -0,0 +1,3 @@
1
+ 0.1.0 (Jan 2, 2010)
2
+
3
+ * initial release
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Ryan Bates
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,170 @@
1
+ = Ruby Warrior
2
+
3
+ This is a game designed to teach the Ruby language and artificial intelligence in a fun, interactive way.
4
+
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
+
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
+
9
+
10
+ == Getting Started
11
+
12
+ First install the gem.
13
+
14
+ gem install rubywarrior
15
+
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:
17
+
18
+ class Player
19
+ def play_turn(warrior)
20
+ # your code goes here
21
+ end
22
+ end
23
+
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.
25
+
26
+ Here is a simple example which will instruct the warrior to attack if he feels an enemy, otherwise he will walk forward.
27
+
28
+ class Player
29
+ def play_turn(warrior)
30
+ if warrior.feel.enemy?
31
+ warrior.attack!
32
+ else
33
+ warrior.walk!
34
+ end
35
+ end
36
+ end
37
+
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.
39
+
40
+ 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
+
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.
43
+
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.
45
+
46
+
47
+ == Scoring
48
+
49
+ 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
+
51
+ * defeat an enemy to add his max health to your score
52
+ * rescue a captive to earn 20 points
53
+ * pass the level within the bonus time to earn the amount of bonus time remaining
54
+ * defeat all enemies and rescue all captives to receive a 20% overall bonus
55
+
56
+ A total score is kept as you progress through the levels. When you pass a level, that score is added to your total.
57
+
58
+ 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
+
60
+
61
+ == Perspective
62
+
63
+ 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
+
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)
76
+
77
+
78
+ == Commanding the Warrior
79
+
80
+ 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
+
82
+ 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
+
84
+ warrior.walk!
85
+ Move in given direction (forward by default).
86
+
87
+ warrior.attack!
88
+ Attack the unit in given direction (forward by default).
89
+
90
+ warrior.rest!
91
+ Gain 10% of max health back, but do nothing more.
92
+
93
+ warrior.bind!
94
+ Bind unit in given direction to keep him from moving (forward by default).
95
+
96
+ warrior.rescue!
97
+ Rescue a captive from his chains (earning 50 points) in given direction (forward by default).
98
+
99
+
100
+ 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
+
102
+ warrior.feel
103
+ Returns a Space for the given direction (forward by default).
104
+
105
+ warrior.health
106
+ Returns an integer representing your health.
107
+
108
+ warrior.distance
109
+ Returns the number of spaces the stairs are away.
110
+
111
+ warrior.listen
112
+ Returns an array of all spaces which have units in them.
113
+
114
+
115
+ 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
+
117
+
118
+ == Spaces
119
+
120
+ 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
+
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
+ 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.
141
+
142
+ warrior.feel.captive?
143
+
144
+
145
+ == Epic Mode
146
+
147
+ 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.
148
+
149
+ 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.
150
+
151
+ rubywarrior -l 3
152
+
153
+ 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.
154
+
155
+ 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.
156
+
157
+
158
+ == Tips
159
+
160
+ 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).
161
+
162
+ 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.
163
+
164
+ Senses are cheap, so use them liberally. Store the sensed information to help you better determine what actions to take in the future.
165
+
166
+ Running "rubywarrior" while you are in your profile directory will auto-select that profile so you don't have to each time.
167
+
168
+ 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.
169
+
170
+ Make sure to try the different options you can pass to the rubywarrior command. Run "rubywarrior --help" to see them all.
data/Rakefile ADDED
@@ -0,0 +1,21 @@
1
+ require 'rake'
2
+ require 'spec'
3
+ require 'cucumber'
4
+
5
+ require 'cucumber/rake/task'
6
+ require 'spec/rake/spectask'
7
+
8
+
9
+ spec_files = Rake::FileList["spec/**/*_spec.rb"]
10
+
11
+ desc "Run specs"
12
+ Spec::Rake::SpecTask.new do |t|
13
+ t.spec_files = spec_files
14
+ t.spec_opts = ["-c"]
15
+ end
16
+
17
+ Cucumber::Rake::Task.new(:features) do |t|
18
+ t.cucumber_opts = "features --format progress"
19
+ end
20
+
21
+ task :default => [:spec, :features]
data/bin/rubywarrior ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../lib/ruby_warrior'
3
+
4
+ runner = RubyWarrior::Runner.new(ARGV, STDIN, STDOUT)
5
+ runner.run
@@ -0,0 +1,46 @@
1
+ Feature: Command Options
2
+ In order to play the game the way I want
3
+ As a player
4
+ I want to customize rubywarrior with options
5
+
6
+ Background:
7
+ Given no profile at "tmp"
8
+
9
+ Scenario: Run ruby warrior in specified directory with -d option
10
+ Given a profile named "Joe" on "beginner"
11
+ When I copy fixture "walking_player.rb" to "tmp/rubywarrior/joe-beginner/player.rb"
12
+ And I run rubywarrior with options "-d tmp/rubywarrior/joe-beginner -t 0"
13
+ And I answer "y" to "next level"
14
+ Then I should see "the updated README in the rubywarrior/joe-beginner directory"
15
+
16
+ Scenario: Skip user input with -s option
17
+ Given a profile named "Joe" on "beginner"
18
+ When I copy fixture "walking_player.rb" to "tmp/rubywarrior/joe-beginner/player.rb"
19
+ And I run rubywarrior with options "-d tmp/rubywarrior/joe-beginner -t 0 -s"
20
+ Then I should see "current level"
21
+ When I run rubywarrior with options "-d tmp/rubywarrior/joe-beginner -t 0"
22
+ And I answer "y" to "next level"
23
+ Then I should see "the updated README in the rubywarrior/joe-beginner directory"
24
+ When I run rubywarrior with options "-d tmp/rubywarrior/joe-beginner -t 0 -s"
25
+ Then I should see "failed level 2"
26
+
27
+ Scenario: Unable to practice level if not epic
28
+ Given a profile named "Joe" on "beginner"
29
+ When I copy fixture "walking_player.rb" to "tmp/rubywarrior/joe-beginner/player.rb"
30
+ And I run rubywarrior with options "-d tmp/rubywarrior/joe-beginner -l 2"
31
+ Then I should see "Unable"
32
+
33
+ Scenario: Practice specific level when epic
34
+ When I copy fixture "short-tower" to "towers/short"
35
+ Given a profile named "Bill" on "short"
36
+ When I copy fixture "walking_player.rb" to "tmp/rubywarrior/bill-short/player.rb"
37
+ And I run rubywarrior
38
+ And I choose "Bill - short - level 1" for "profile"
39
+ Then I answer "y" to "next level"
40
+ And I should see "the updated README in the rubywarrior/bill-short directory"
41
+ When I run rubywarrior
42
+ And I choose "Bill - short - level 2" for "profile"
43
+ Then I answer "y" to "epic"
44
+ And I should see "epic mode"
45
+ When I run rubywarrior with options "-d tmp/rubywarrior/bill-short -l 2"
46
+ Then I should not see "Level 1" before "Total Score: 17"
@@ -0,0 +1,51 @@
1
+ Feature: Play levels
2
+ In order to play ruby warrior
3
+ As a player
4
+ I want to advance through levels or retry them
5
+
6
+ Background:
7
+ Given no profile at "tmp"
8
+
9
+ Scenario: Pass first level, fail second level
10
+ Given a profile named "Joe" on "beginner"
11
+ When I copy fixture "walking_player.rb" to "tmp/rubywarrior/joe-beginner/player.rb"
12
+ And I run rubywarrior
13
+ And I choose "Joe - beginner - level 1" for "profile"
14
+ And I answer "y" to "next level"
15
+ Then I should see "the updated README in the rubywarrior/joe-beginner directory"
16
+ When I run rubywarrior
17
+ And I choose "Joe - beginner - level 2" for "profile"
18
+ And I answer "y" to "clues"
19
+ Then I should see "warrior.feel.empty?"
20
+
21
+ Scenario: Retry first level
22
+ Given a profile named "Joe" on "beginner"
23
+ When I copy fixture "walking_player.rb" to "tmp/rubywarrior/joe-beginner/player.rb"
24
+ And I run rubywarrior
25
+ And I choose "Joe - beginner - level 1" for "profile"
26
+ And I answer "n" to "next level"
27
+ Then I should see "current level"
28
+ When I run rubywarrior
29
+ Then I should see "Joe - beginner - level 1"
30
+
31
+ @focus
32
+ Scenario: Replay levels as epic when finishing last level with grades
33
+ When I copy fixture "short-tower" to "towers/short"
34
+ Given a profile named "Bill" on "short"
35
+ When I copy fixture "walking_player.rb" to "tmp/rubywarrior/bill-short/player.rb"
36
+ And I run rubywarrior
37
+ And I choose "Bill - short - level 1" for "profile"
38
+ Then I answer "y" to "next level"
39
+ And I should see "the updated README in the rubywarrior/bill-short directory"
40
+ When I run rubywarrior
41
+ And I choose "Bill - short - level 2" for "profile"
42
+ Then I answer "y" to "epic"
43
+ And I should see "epic mode"
44
+ When I run rubywarrior
45
+ And I choose "Bill - short - first score 34 - epic score 0" for "profile"
46
+ Then I should see "Level Grade: S"
47
+ When I run rubywarrior
48
+ And I choose "Bill - short - first score 34 - epic score 34" for "profile"
49
+ Then I should see "grade for this tower"
50
+ When I run rubywarrior
51
+ Then I should see "Bill - short - first score 34 - epic score 34"
@@ -0,0 +1,56 @@
1
+ Feature: Manage Profiles
2
+ In order to play ruby warrior
3
+ As a player
4
+ I want to create and choose profiles
5
+
6
+ Background:
7
+ Given no profile at "tmp"
8
+
9
+ Scenario: New profile
10
+ When I run rubywarrior
11
+ And I answer "y" to "create one?"
12
+ And I choose "beginner" for "tower"
13
+ And I answer "Joe" to "name"
14
+ Then I should see "generated"
15
+ And I should find file at "tmp/rubywarrior"
16
+ When I run rubywarrior
17
+ Then I should see "Joe - beginner - level 1 - score 0"
18
+
19
+ Scenario: Another new profile on same tower
20
+ Given a profile named "Joe" on "beginner"
21
+ When I run rubywarrior
22
+ And I choose "New" for "profile"
23
+ And I choose "beginner" for "tower"
24
+ And I answer "Bob" to "name"
25
+ Then I should see "generated"
26
+ When I run rubywarrior
27
+ Then I should see "Bob - beginner - level 1 - score 0"
28
+
29
+ Scenario: Replace profile in same tower with same name
30
+ Given a profile named "Joe" on "beginner"
31
+ When I run rubywarrior
32
+ And I choose "New" for "profile"
33
+ And I choose "beginner" for "tower"
34
+ And I answer "Joe" to "name"
35
+ And I answer "y" to "replace"
36
+ Then I should see "generated"
37
+ When I run rubywarrior
38
+ Then I should see "Joe - beginner - level 1 - score 0"
39
+
40
+ Scenario: Auto select profile at given path
41
+ Given a profile named "Joe" on "beginner"
42
+ And current directory is "tmp/rubywarrior/joe-beginner"
43
+ When I copy fixture "walking_player.rb" to "tmp/rubywarrior/joe-beginner/player.rb"
44
+ And I run rubywarrior
45
+ And I answer "y" to "next level"
46
+ Then I should see "the updated README in the rubywarrior/joe-beginner directory"
47
+
48
+ Scenario: Move legacy ruby-warrior profile
49
+ Given a directory at "tmp/ruby-warrior"
50
+ And no directory at "tmp/rubywarrior"
51
+ When I run rubywarrior
52
+ And I choose "beginner" for "tower"
53
+ And I answer "Joe" to "name"
54
+ Then I should see "generated"
55
+ And I should find file at "tmp/rubywarrior"
56
+ And I should find no file at "tmp/ruby-warrior"
@@ -0,0 +1,19 @@
1
+ Given /^a directory at "([^\"]*)"$/ do |path|
2
+ Dir.mkdir(path) unless File.exist? path
3
+ end
4
+
5
+ Given /^no directory at "([^\"]*)"$/ do |path|
6
+ Dir.rmdir(path) if File.exist? path
7
+ end
8
+
9
+ When /^I copy fixture "([^\"]*)" to "([^\"]*)"$/ do |from, to|
10
+ FileUtils.cp_r("spec/fixtures/" + from, to)
11
+ end
12
+
13
+ Then /^I should find file at "([^\"]*)"$/ do |path|
14
+ File.exist?(path).should be_true
15
+ end
16
+
17
+ Then /^I should find no file at "([^\"]*)"$/ do |path|
18
+ File.exist?(path).should be_false
19
+ end
@@ -0,0 +1,65 @@
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"'
7
+ end
8
+
9
+ Given /^no profile at "([^\"]*)"$/ do |path|
10
+ RubyWarrior::Config.path_prefix = path
11
+ FileUtils.rm_rf("#{path}/rubywarrior")
12
+ end
13
+
14
+ Given /^current directory is "([^\"]*)"$/ do |path|
15
+ RubyWarrior::Config.path_prefix = path
16
+ end
17
+
18
+ When /^I run rubywarrior$/ do
19
+ @io = MockIO.new
20
+ @io.start do |io|
21
+ RubyWarrior::Config.out_stream = io
22
+ RubyWarrior::Config.in_stream = io
23
+ RubyWarrior::Game.new.start
24
+ end
25
+ end
26
+
27
+ When /^I run rubywarrior with options "([^\"]*)"$/ do |options|
28
+ RubyWarrior::Config.reset
29
+ @io = MockIO.new
30
+ @io.start do |io|
31
+ RubyWarrior::Runner.new(options.split, io, io).run
32
+ end
33
+ end
34
+
35
+ When /^I answer "([^\"]*)" to "([^\"]*)"$/ do |answer, question|
36
+ @io.gets_until_include(question)
37
+ @io.puts(answer)
38
+ end
39
+
40
+ When /^I choose "([^\"]*)" for "([^\"]*)"$/ do |choice, phrase|
41
+ answer = nil
42
+ content = @io.gets_until_include(phrase)
43
+ content.split("\n").each do |line|
44
+ if line.include?(choice) && line =~ /\[(\d)\]/
45
+ answer = $1
46
+ end
47
+ end
48
+ if answer
49
+ @io.puts(answer)
50
+ else
51
+ raise "Unable to find choice #{choice} in #{content}"
52
+ end
53
+ end
54
+
55
+ When /^I wait until it says "([^\"]*)"$/ do |phrase|
56
+ @io.gets_until_include(phrase)
57
+ end
58
+
59
+ Then /^I should see "([^\"]*)"$/ do |phrase|
60
+ @io.gets_until_include(phrase).should include(phrase)
61
+ end
62
+
63
+ Then /^I should not see "([^\"]*)" before "([^\"]*)"$/ do |first_phrase, second_phrase|
64
+ @io.gets_until_include(second_phrase).should_not include(first_phrase)
65
+ end