Skip to content

Commit

Permalink
adding -l option for practicing a level - closes ryanb#11
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanb committed Nov 4, 2009
1 parent 99a0a1a commit 9c9af01
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 11 deletions.
22 changes: 22 additions & 0 deletions features/command_options.feature
Expand Up @@ -23,3 +23,25 @@ Feature: Command Options
Then I should see "directory for the next level"
When I run rubywarrior with options "-d tmp/ruby-warrior/joe-beginner -t 0 -s"
Then I should see "failed the level"

Scenario: Unable to practice level if not epic
Given a profile named "Joe" on "beginner"
When I copy fixture "walking_player.rb" to "tmp/ruby-warrior/joe-beginner/player.rb"
And I run rubywarrior with options "-d tmp/ruby-warrior/joe-beginner -l 2"
Then I should see "Unable"

@focus
Scenario: Practice specific level when epic
When I copy fixture "short-tower" to "towers/short"
Given a profile named "Bill" on "short"
When I copy fixture "walking_player.rb" to "tmp/ruby-warrior/bill-short/player.rb"
And I run rubywarrior
And I choose "Bill - short - level 1" for "profile"
Then I answer "y" to "next level"
And I should see "next level"
When I run rubywarrior
And I choose "Bill - short - level 2" for "profile"
Then I answer "y" to "epic"
And I should see "epic mode"
When I run rubywarrior with options "-d tmp/ruby-warrior/bill-short -l 2"
Then I should not see "Level 1" before "Total Score: 17"
4 changes: 4 additions & 0 deletions features/step_definitions/interaction_steps.rb
Expand Up @@ -59,3 +59,7 @@
Then /^I should see "([^\"]*)"$/ do |phrase|
@io.gets_until_include(phrase).should include(phrase)
end

Then /^I should not see "([^\"]*)" before "([^\"]*)"$/ do |first_phrase, second_phrase|
@io.gets_until_include(second_phrase).should_not include(first_phrase)
end
4 changes: 2 additions & 2 deletions lib/ruby_warrior/config.rb
@@ -1,7 +1,7 @@
module RubyWarrior
class Config
class << self
attr_accessor :delay, :in_stream, :out_stream
attr_accessor :delay, :in_stream, :out_stream, :practice_level
attr_writer :path_prefix, :skip_input

def path_prefix
Expand All @@ -13,7 +13,7 @@ def skip_input?
end

def reset
[:@path_prefix, :@skip_input, :@delay, :@in_stream, :@out_stream].each do |i|
[:@path_prefix, :@skip_input, :@delay, :@in_stream, :@out_stream, :@practice_level].each do |i|
remove_instance_variable(i) if instance_variable_defined?(i)
end
end
Expand Down
28 changes: 19 additions & 9 deletions lib/ruby_warrior/game.rb
Expand Up @@ -13,19 +13,29 @@ def start
if profile.epic?
Config.delay /= 2 if Config.delay # speed up UI since we're going to be doing a lot here
profile.current_epic_score = 0
playing = true
while playing
if Config.practice_level
@current_level = @next_level = nil
profile.level_number += 1
playing = play_current_level
profile.level_number = Config.practice_level.to_i
play_current_level
else
playing = true
while playing
@current_level = @next_level = nil
profile.level_number += 1
playing = play_current_level
end
profile.save # saves the score for epic mode
end
profile.save # saves the score for epic mode
else
if current_level.number.zero?
prepare_next_level
UI.puts "First level has been generated. See the ruby-warrior directory for instructions."
if Config.practice_level
UI.puts "Unable to practice level while not in epic mode, remove -l option."
else
play_current_level
if current_level.number.zero?
prepare_next_level
UI.puts "First level has been generated. See the ruby-warrior directory for instructions."
else
play_current_level
end
end
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/ruby_warrior/runner.rb
Expand Up @@ -23,6 +23,7 @@ def parse_options
options = OptionParser.new
options.banner = "Usage: rubywarrior [options]"
options.on('-d', '--directory DIR', "Run under given directory") { |dir| Config.path_prefix = dir }
options.on('-l', '--level LEVEL', "Practice level on epic") { |level| Config.practice_level = level }
options.on('-s', '--skip', "Skip user input") { Config.skip_input = true }
options.on('-t', '--time SECONDS', "Delay each turn by seconds") { |seconds| Config.delay = seconds.to_f }
options.on('-h', '--help', "Show this message") { puts(options); exit }
Expand Down

0 comments on commit 9c9af01

Please sign in to comment.