Skip to content

Instantly share code, notes, and snippets.

@robinboening
Last active January 13, 2019 06:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robinboening/6139277 to your computer and use it in GitHub Desktop.
Save robinboening/6139277 to your computer and use it in GitHub Desktop.
ruby-warrior level6
class Player
FULL_HEALTH = 20
def play_turn(warrior)
@warrior = warrior
if need_to_rest?
if able_to_rest?
warrior.rest!
else
warrior.walk!(:backward)
end
else
if warrior.feel.captive?
warrior.rescue!
elsif warrior.feel.empty?
warrior.walk!
else
warrior.attack!
end
end
@previous_health = current_health
end
def need_to_rest?
resting_not_completed_yet || current_health < 10
end
def resting_not_completed_yet
current_health < FULL_HEALTH && current_health > @previous_health
end
def able_to_rest?
@warrior.feel.empty? and not taken_damage?
end
def taken_damage?
return false if @previous_health.nil?
@previous_health > current_health
end
def current_health
@warrior.health
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment