summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2013-04-24 08:42:56 -0600
committermo khan <mo@mokhan.ca>2013-04-24 08:42:56 -0600
commit50dce05f474b499444b451b867e62f4b261f2b36 (patch)
treebc53324284930d26e0fe0d8f8d58f7321661e775
parentd64bb991bdaa4240a3f7ec38b92f675048e2b27c (diff)
do not attack on the same turn that you are resting
-rw-r--r--rubywarrior/alimo-beginner/player.rb8
-rw-r--r--rubywarrior/alimo-beginner/spec/player_spec.rb11
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