Skip to content

Instantly share code, notes, and snippets.

@kevinnio
Created May 7, 2014 23:09
Show Gist options
  • Save kevinnio/527b999cdb4e00957ea7 to your computer and use it in GitHub Desktop.
Save kevinnio/527b999cdb4e00957ea7 to your computer and use it in GitHub Desktop.
Código del nivel 4, modo Intermediate de Ruby Warrior
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