Skip to content
This repository
Browse code

keep track of last level played in profile and go back to normal mode…

… when level is added
  • Loading branch information...
commit ffc4f2cd95ceada5dba4e4ae6a7a24a9b691f5e6 1 parent 0a74bde
Ryan Bates authored January 02, 2010
3  CHANGELOG.rdoc
Source Rendered
... ...
@@ -1,3 +1,6 @@
  1
+* Keep track of last level played in profile and go back to normal mode when level is added
  2
+
  3
+
1 4
 0.1.0 (Jan 2, 2010)
2 5
 
3 6
 * initial release
22  features/levels.feature
@@ -28,7 +28,6 @@ Feature: Play levels
28 28
     When I run rubywarrior
29 29
     Then I should see "Joe - beginner - level 1"
30 30
   
31  
-  @focus
32 31
   Scenario: Replay levels as epic when finishing last level with grades
33 32
     When I copy fixture "short-tower" to "towers/short"
34 33
     Given a profile named "Bill" on "short"
@@ -49,3 +48,24 @@ Feature: Play levels
49 48
     Then I should see "grade for this tower"
50 49
     When I run rubywarrior
51 50
     Then I should see "Bill - short - first score 34 - epic score 34"
  51
+  
  52
+  Scenario: Continue normal mode after epic mode when level added
  53
+    When I copy fixture "short-tower" to "towers/short"
  54
+    Given a profile named "Bob" on "short"
  55
+    When I copy fixture "walking_player.rb" to "tmp/rubywarrior/bob-short/player.rb"
  56
+    And I run rubywarrior
  57
+    And I choose "Bob - short - level 1" for "profile"
  58
+    Then I answer "y" to "next level"
  59
+    And I should see "the updated README in the rubywarrior/bob-short directory"
  60
+    When I run rubywarrior
  61
+    And I choose "Bob - short - level 2" for "profile"
  62
+    Then I answer "y" to "epic"
  63
+    And I should see "epic mode"
  64
+    When I copy fixture "short-tower/level_002.rb" to "towers/short/level_003.rb"
  65
+    And I run rubywarrior
  66
+    And I choose "Bob - short - first score 34 - epic score 0" for "profile"
  67
+    And I should see "Another level"
  68
+    When I run rubywarrior
  69
+    And I choose "Bob - short - level 3" for "profile"
  70
+    Then I answer "y" to "epic"
  71
+    And I should see "epic mode"
17  lib/ruby_warrior/game.rb
@@ -13,7 +13,15 @@ def start
13 13
         make_game_directory unless File.exist?(Config.path_prefix + '/rubywarrior')
14 14
       end
15 15
       
16  
-      profile.epic? ? play_epic_mode : play_normal_mode
  16
+      if profile.epic?
  17
+        if profile.level_after_epic?
  18
+          go_back_to_normal_mode
  19
+        else
  20
+          play_epic_mode
  21
+        end
  22
+      else
  23
+        play_normal_mode
  24
+      end
17 25
     end
18 26
     
19 27
     def make_game_directory
@@ -111,6 +119,13 @@ def prepare_epic_mode
111 119
       profile.save # this saves score too
112 120
     end
113 121
     
  122
+    def go_back_to_normal_mode
  123
+      profile.enable_normal_mode
  124
+      prepare_next_level
  125
+      UI.puts "Another level has been added since you started epic, going back to normal mode."
  126
+      UI.puts "See the updated README in the rubywarrior/#{profile.directory_name} directory."
  127
+    end
  128
+    
114 129
     
115 130
     # profiles
116 131
     
18  lib/ruby_warrior/profile.rb
@@ -2,7 +2,7 @@
2 2
 
3 3
 module RubyWarrior
4 4
   class Profile
5  
-    attr_accessor :score, :epic_score, :current_epic_score, :average_grade, :current_epic_grades, :abilities, :level_number, :tower_path, :warrior_name, :player_path
  5
+    attr_accessor :score, :epic_score, :current_epic_score, :average_grade, :current_epic_grades, :abilities, :level_number, :last_level_number, :tower_path, :warrior_name, :player_path
6 6
     
7 7
     def initialize
8 8
       @tower_path = nil
@@ -14,6 +14,7 @@ def initialize
14 14
       @average_grade = nil
15 15
       @abilities = []
16 16
       @level_number = 0
  17
+      @last_level_number = nil
17 18
     end
18 19
     
19 20
     def encode
@@ -81,12 +82,27 @@ def enable_epic_mode
81 82
       @epic = true
82 83
       @epic_score ||= 0
83 84
       @current_epic_score ||= 0
  85
+      @last_level_number ||= @level_number
  86
+    end
  87
+    
  88
+    def enable_normal_mode
  89
+      @epic = false
  90
+      @epic_score = 0
  91
+      @current_epic_score = 0
  92
+      @current_epic_grades = {}
  93
+      @average_grade = nil
  94
+      @level_number = @last_level_number
  95
+      @last_level_number = nil
84 96
     end
85 97
     
86 98
     def epic?
87 99
       @epic
88 100
     end
89 101
     
  102
+    def level_after_epic?
  103
+      Level.new(self, last_level_number+1).exists? if last_level_number
  104
+    end
  105
+    
90 106
     def update_epic_score
91 107
       if @current_epic_score > @epic_score
92 108
         @epic_score = @current_epic_score
27  spec/ruby_warrior/profile_spec.rb
@@ -94,6 +94,33 @@
94 94
     @profile.current_epic_grades = {}
95 95
     @profile.calculate_average_grade.should be_nil
96 96
   end
  97
+
  98
+  it "should remember current level number as last_level_number" do
  99
+    @profile.level_number = 7
  100
+    @profile.enable_epic_mode
  101
+    @profile.last_level_number.should == 7
  102
+  end
  103
+
  104
+  it "should enable normal mode by clearing epic scores and resetting last level number" do
  105
+    @profile.last_level_number = 7
  106
+    @profile.epic_score = 123
  107
+    @profile.current_epic_score = 100
  108
+    @profile.current_epic_grades = { 1 => 100 }
  109
+    @profile.average_grade = "C"
  110
+    @profile.enable_normal_mode
  111
+    @profile.should_not be_epic
  112
+    @profile.epic_score.should be_zero
  113
+    @profile.current_epic_score.should be_zero
  114
+    @profile.last_level_number.should be_nil
  115
+    @profile.average_grade.should be_nil
  116
+    @profile.current_epic_grades.should == {}
  117
+    @profile.level_number.should == 7
  118
+  end
  119
+
  120
+  it "should be no level after epic if last level isn't specified" do
  121
+    @profile.last_level_number = nil
  122
+    @profile.should_not be_level_after_epic
  123
+  end
97 124
   
98 125
   describe "with tower path" do
99 126
     before(:each) do

0 notes on commit ffc4f2c

Please sign in to comment.
Something went wrong with that request. Please try again.