diff options
| author | mo khan <mo@mokhan.ca> | 2013-04-24 17:25:39 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2013-04-24 17:25:39 -0600 |
| commit | 27816feca037b8e5c1dd34c404b27564f02f2601 (patch) | |
| tree | 62cdcdd1864491a9718f44d70f1f1b44f5c7b584 | |
| parent | 5a825d1f28630ea21e62af66ea01a7ab69eecf35 (diff) | |
re-use good health in Rest behaviour
| -rw-r--r-- | rubywarrior/alimo-beginner/player.rb | 13 |
1 files changed, 4 insertions, 9 deletions
diff --git a/rubywarrior/alimo-beginner/player.rb b/rubywarrior/alimo-beginner/player.rb index 34262a9..7044745 100644 --- a/rubywarrior/alimo-beginner/player.rb +++ b/rubywarrior/alimo-beginner/player.rb @@ -43,23 +43,18 @@ class Attack end class Rest - FIFTY_PERCENT = 0.5 + def initialize(good_health = GoodHealth.new) + @good_health = good_health + end def matches(warrior) @initial_health ||= warrior.health - warrior.feel.empty? == false && health_is_low(warrior) + warrior.feel.empty? == false && @good_health.matches(warrior) == false end def play(warrior) warrior.rest! end - - private - - def health_is_low(warrior) - threshold = FIFTY_PERCENT * @initial_health - warrior.health <= threshold - end end class Walk |
