Skip to content

Instantly share code, notes, and snippets.

@kek
Created July 29, 2013 17:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kek/6106042 to your computer and use it in GitHub Desktop.
Save kek/6106042 to your computer and use it in GitHub Desktop.
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