From ccfd9cd5a9f6340ec6de66d9c64579a3bb045c6f Mon Sep 17 00:00:00 2001 From: mo khan Date: Fri, 26 Apr 2013 17:36:51 -0600 Subject: extract resting state --- rubywarrior/alimo-beginner/player.rb | 20 ++++++++++++++++++-- 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 -- cgit v1.2.3