Permalink
Browse files

Allow warrior to recuperate and get all health back

  • Loading branch information...
1 parent 0d6eccc commit ab0a7dc78c73ad328eba467b5ed8f0d197b1934e @gabebw committed Sep 26, 2010
Showing with 15 additions and 3 deletions.
  1. +15 −3 player.rb
View
@@ -12,8 +12,10 @@ class Player
def play_turn(warrior)
# warrior.action returns [:latest_action, :direction_it_was_performed]
@warrior = warrior
- @previous_health ||= current_health
+ @previous_health ||= current_health # set first
@previous_space ||= current_location
+ # If true, then rest until at max health before continuing
+ @recuperating ||= false
perform_action!(warrior)
@@ -61,6 +63,7 @@ def perform_action!(warrior)
else
puts "Should rest, but not in safe space. Moving towards it."
move_toward_safe_space!
+ @recuperating = true
end
elsif space.captive?
warrior.rescue!(direction)
@@ -127,15 +130,24 @@ def in_safe_space?
# Is a given location safe?
def is_safe_location?(location)
- @safe_locations.include?(location)
+ @safe_locations and @safe_locations.include?(location)
end
# Should the warrior rest? Note that this doesn't take into account
# whether it's safe for the warrior to rest, it just recommends that he
# should.
def should_rest?
# No need to rest when we're about to clear the level
- low_on_health? and not @warrior.feel(direction).stairs?
+ return false if @warrior.feel(direction).stairs?
+ return false if @warrior.health == MAX_HEALTH
+
+ if @recuperating
+ # Stop recuperating if at max health
+ @recuperating = @warrior.health < MAX_HEALTH
+ return @recuperating
+ else
+ low_on_health?
+ end
end
# Is an enemy in an adjacent space?

0 comments on commit ab0a7dc

Please sign in to comment.