Skip to content

Instantly share code, notes, and snippets.

@kevinnio
Created May 7, 2014 01:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevinnio/4fb6695f95e88413751a to your computer and use it in GitHub Desktop.
Save kevinnio/4fb6695f95e88413751a to your computer and use it in GitHub Desktop.
Código del nivel 8, modo Beginner de RubyWarrior
class Player
def initialize
@health = 0
end
def play_turn(warrior)
if warrior.feel.empty?
if warrior.health < 20 and not taking_damage? warrior
warrior.rest!
else
enemies = warrior.look.select { |space| space.enemy?}
captives = warrior.look.select { |space| space.captive? }
if not enemies.empty? and captives.empty?
warrior.shoot!
else
(taking_damage? warrior and warrior.health < 10) ? warrior.walk!(:backward) : warrior.walk!
end
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