Last active
December 20, 2015 19:18
-
-
Save jansanchez/6181792 to your computer and use it in GitHub Desktop.
Ruby Warrior - Level 5
This file contains 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
# ruby warrior level 5 | |
# | |
class Player | |
def play_turn(warrior) | |
@health = warrior.health | |
if @need_health == nil | |
if warrior.feel.empty? | |
unless warrior.feel.wall? | |
warrior.walk! | |
end | |
else | |
if warrior.feel.captive? | |
warrior.rescue! | |
else | |
if warrior.feel.enemy? | |
if @health < 8 | |
warrior.walk! :backward | |
@need_health = true | |
else | |
warrior.attack! | |
end | |
else | |
warrior.walk! :forward | |
end | |
end | |
end | |
else | |
warrior.rest! | |
@need_health = nil | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment