Skip to content

Commit

Permalink
don't override existing tower profile without permission
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanb committed Jan 19, 2009
1 parent 55e8f16 commit bc3e4f6
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
4 changes: 3 additions & 1 deletion 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
Expand All @@ -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
Expand Down
15 changes: 13 additions & 2 deletions lib/ruby_warrior/game.rb
Expand Up @@ -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
Expand Down
17 changes: 14 additions & 3 deletions spec/ruby_warrior/game_spec.rb
Expand Up @@ -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
Expand Down

0 comments on commit bc3e4f6

Please sign in to comment.