ruby Códigodelnivel 8,modo Beginner de RubyWarrior
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ruby Códigodelnivel 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
以上是关于ruby Códigodelnivel 8,modo Beginner de RubyWarrior的主要内容,如果未能解决你的问题,请参考以下文章