From bc3e4f678f67c659587d19c7dff29a959cd18efa Mon Sep 17 00:00:00 2001 From: Ryan Bates Date: Mon, 19 Jan 2009 00:43:17 -0800 Subject: [PATCH] don't override existing tower profile without permission --- TODO | 4 +++- lib/ruby_warrior/game.rb | 15 +++++++++++++-- spec/ruby_warrior/game_spec.rb | 17 ++++++++++++++--- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/TODO b/TODO index d4e11175..fcff01a0 100644 --- a/TODO +++ b/TODO @@ -1,5 +1,7 @@ Primary - improve profile selection so you don't replace your current tower profile +% make beginner tower go up to the 10th level +% make intermediate tower go up to the 15th level - polish into gem Secondary @@ -9,9 +11,9 @@ Secondary - add level with light and look abilities - attacking or looking backward should be less effective than forward/left/right - handle errors cleanly stating if it's in the user's Player script -- make beginner tower go up to the 10th level - add a more in-depth help doc if they get stuck - update primary README to current abilities and game +- don't require selecting tower when running command inside tower directory Ideas - rename tower to dungeon diff --git a/lib/ruby_warrior/game.rb b/lib/ruby_warrior/game.rb index f8ca8670..34170de5 100644 --- a/lib/ruby_warrior/game.rb +++ b/lib/ruby_warrior/game.rb @@ -95,10 +95,21 @@ def next_level private - def choose_profile + def choose_profile # REFACTORME profile = UI.choose('profile', profiles + [[:new, 'New Profile']]) if profile == :new - new_profile + profile = new_profile + if profiles.any? { |p| p.tower_path == profile.tower_path } + if UI.ask("Are you sure you want to replace your existing profile for this tower?") + UI.puts("Replacing existing profile.") + profile + else + UI.puts("Not replacing profile.") + exit + end + else + profile + end else profile end diff --git a/spec/ruby_warrior/game_spec.rb b/spec/ruby_warrior/game_spec.rb index c08c81ee..7bc9f556 100644 --- a/spec/ruby_warrior/game_spec.rb +++ b/spec/ruby_warrior/game_spec.rb @@ -47,10 +47,21 @@ end it "should make a new profile if player chooses" do + new_profile = RubyWarrior::Profile.new RubyWarrior::UI.expects(:choose).returns(:new) - @game.stubs(:profiles).returns([:profile1]) - @game.expects(:new_profile).returns('new_profile') - @game.profile.should == 'new_profile' + RubyWarrior::UI.stubs(:ask).returns(true) + @game.stubs(:profiles).returns([RubyWarrior::Profile.new]) + @game.expects(:new_profile).returns(new_profile) + @game.profile.should == new_profile + end + + it "should ask permission before replacing existing tower profile when creating a new one" do + RubyWarrior::UI.expects(:choose).returns(:new) + RubyWarrior::UI.expects(:ask).returns(false) + @game.stubs(:profiles).returns([stub(:tower_path => :tower1)]) + @game.expects(:new_profile).returns(stub(:tower_path => :tower1)) + @game.expects(:exit).returns(:exit) + @game.profile.should == :exit end it "should ask user to choose a tower when creating a new profile" do