diff options
| author | mo khan <mo@mokhan.ca> | 2013-04-26 17:36:51 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2013-04-26 17:36:51 -0600 |
| commit | ccfd9cd5a9f6340ec6de66d9c64579a3bb045c6f (patch) | |
| tree | e2896e55aa3aa6f34f2c50985dabee6fa74902e3 | |
| parent | 06a049938a800a77d61bae9ed6daa562347dfa27 (diff) | |
extract resting state
| -rw-r--r-- | rubywarrior/alimo-beginner/player.rb | 20 | ||||
| -rw-r--r-- | rubywarrior/alimo-beginner/spec/player_spec.rb | 6 |
2 files changed, 24 insertions, 2 deletions
diff --git a/rubywarrior/alimo-beginner/player.rb b/rubywarrior/alimo-beginner/player.rb index 26c9390..a65b765 100644 --- a/rubywarrior/alimo-beginner/player.rb +++ b/rubywarrior/alimo-beginner/player.rb @@ -2,11 +2,27 @@ class Player def initialize @behaviours = [Rest.new, Attack.new, Walk.new] + @current_state = Resting.new end def play_turn(warrior) - @behaviours.each do |action| - action.play(warrior) if action.matches(warrior) + @current_state.play(warrior) + end +end + +class Resting + def initialize(good_health = GoodHealth.new) + @good_health = good_health + @behaviours = [Attack.new, Walk.new] + end + + def play(warrior) + if @good_health.matches(warrior) + @behaviours.each do |action| + action.play(warrior) if action.matches(warrior) + end + else + Rest.new(@good_health).play(warrior) end end end diff --git a/rubywarrior/alimo-beginner/spec/player_spec.rb b/rubywarrior/alimo-beginner/spec/player_spec.rb index 4fc4553..7dff3d8 100644 --- a/rubywarrior/alimo-beginner/spec/player_spec.rb +++ b/rubywarrior/alimo-beginner/spec/player_spec.rb @@ -8,6 +8,7 @@ describe Player do context "when there is no obstacle in the way" do let(:space) { OpenStruct.new(:empty? => true) } + before { warrior.stub(:health).and_return(20) } it "should walk forward" do warrior.stub(:feel).and_return(space) @@ -62,4 +63,9 @@ describe Player do end end end + context "when health is low" do + it "should stay resting" do + + end + end end |
