Last active
August 29, 2015 14:00
-
-
Save kevinnio/57b005bbd3d18c0f931d to your computer and use it in GitHub Desktop.
Código del nivel 9, 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 initialize | |
@health = 0 | |
end | |
def play_turn(warrior) | |
if warrior.feel.empty? | |
enemies_around = false | |
warrior.look.each do |space| | |
space.captive? ? enemies_around = false : enemies_around = space.enemy? # Don't attack if there's a captive in the way | |
end | |
if enemies_around | |
warrior.shoot! | |
elsif warrior.health < 20 and not taking_damage? warrior | |
warrior.rest! | |
else | |
(taking_damage? warrior and warrior.health < 10) ? warrior.walk!(:backward) : warrior.walk! | |
end | |
else | |
warrior.feel.captive? ? warrior.rescue! : (warrior.feel.wall? ? warrior.pivot! : warrior.attack!) | |
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