Created
July 29, 2013 17:35
-
-
Save kek/6106042 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Player | |
attr_reader :warrior | |
def play_turn(warrior) | |
@warrior = warrior | |
if warrior.feel(:backward).captive? | |
@has_rescued = true | |
warrior.rescue!(:backward) | |
elsif not @has_rescued | |
warrior.walk!(:backward) | |
elsif warrior.feel.enemy? | |
warrior.attack! | |
elsif damaged? and taking_damage? | |
warrior.walk!(:backward) | |
elsif !healthy? and !taking_damage? | |
warrior.rest! | |
else | |
warrior.walk! | |
end | |
@old_health = warrior.health | |
end | |
private | |
def taking_damage? | |
warrior.health < old_health | |
end | |
def old_health | |
@old_health or 20 | |
end | |
def damaged? | |
warrior.health < 10 | |
end | |
def healthy? | |
warrior.health == 20 | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment