Created
May 7, 2014 23:09
-
-
Save kevinnio/527b999cdb4e00957ea7 to your computer and use it in GitHub Desktop.
Código del nivel 4, modo Intermediate de Ruby Warrior
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) | |
@dir = warrior.direction_of_stairs | |
if not enemies_around(warrior).empty? | |
warrior.bind! warrior.direction_of enemies_around(warrior).first | |
else | |
warrior.feel(@dir).empty? ? warrior.walk!(@dir) : warrior.attack!(@dir) | |
end | |
end | |
def enemies_around(warrior) | |
enemies = [] | |
[:forward, :backward, :left, :right].each do |d| | |
enemies.push warrior.feel(d) if d != @dir and warrior.feel(d).enemy? | |
end | |
return enemies | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment