From 50dce05f474b499444b451b867e62f4b261f2b36 Mon Sep 17 00:00:00 2001 From: mo khan Date: Wed, 24 Apr 2013 08:42:56 -0600 Subject: do not attack on the same turn that you are resting --- rubywarrior/alimo-beginner/player.rb | 8 ++++++-- rubywarrior/alimo-beginner/spec/player_spec.rb | 11 ++++++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/rubywarrior/alimo-beginner/player.rb b/rubywarrior/alimo-beginner/player.rb index aba09b9..50da2dc 100644 --- a/rubywarrior/alimo-beginner/player.rb +++ b/rubywarrior/alimo-beginner/player.rb @@ -1,12 +1,16 @@ class Player FIFTY_PERCENT = 0.5 + def play_turn(warrior) @initial_health ||= warrior.health if warrior.feel.empty? warrior.walk! else - warrior.rest! if health_is_low(warrior) - warrior.attack! + if health_is_low(warrior) + warrior.rest! + else + warrior.attack! + end end end diff --git a/rubywarrior/alimo-beginner/spec/player_spec.rb b/rubywarrior/alimo-beginner/spec/player_spec.rb index 8d7d016..4fc4553 100644 --- a/rubywarrior/alimo-beginner/spec/player_spec.rb +++ b/rubywarrior/alimo-beginner/spec/player_spec.rb @@ -42,19 +42,24 @@ describe Player do context "when our health reaches 50%" do let(:starting_health) { 20 } + let(:new_warrior) { fake } before :each do warrior.stub(:health).and_return(starting_health) player.play_turn(warrior) - end - it "should step back and rest" do - new_warrior = fake new_warrior.stub(:health).and_return(starting_health * 0.5) new_warrior.stub(:feel).and_return(space) player.play_turn(new_warrior) + end + + it "should step back and rest" do new_warrior.should have_received(:rest!) end + + it "should not attack" do + new_warrior.should_not have_received(:attack!) + end end end end -- cgit v1.2.3