kevinnio
5/7/2014 - 11:09 PM

Código del nivel 4, modo Intermediate de Ruby Warrior

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