Created
May 7, 2014 00:49
-
-
Save kevinnio/a80d4a3e4854313190c9 to your computer and use it in GitHub Desktop.
Código del nivel 6, modo Beginner de RubyWarrior
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
class Player | |
def play_turn(warrior) | |
@health = 0 if not @health | |
@direction = :forward if not @direction | |
@direction = :forward if @direction == :backward and warrior.feel(@direction).wall? | |
if warrior.feel(@direction).empty? | |
if warrior.health < 20 and not taking_damage? warrior | |
warrior.rest! | |
else | |
@direction = :backward if taking_damage? warrior and warrior.health < 10 | |
warrior.walk! @direction | |
end | |
else | |
warrior.feel(@direction).captive? ? warrior.rescue!(@direction) : warrior.attack!(@direction) | |
end | |
@health = warrior.health | |
end | |
def taking_damage?(warrior) | |
@health > warrior.health | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment