RubyWarriorのLevel3の攻略
参考サイト: http://tumiki.hatenablog.jp/entry/2015/06/23/003951
スクリプト
class Player
def play_turn(warrior)
if warrior.feel.empty?
if warrior.health < 10
warrior.rest!
else
warrior.walk!
end
else
warrior.attack!
end
end
end
解説
warrior.healthでプレイヤーの体力の数値を確認できるので、これが10以下のときにwarrior.rest!してやる。
けど、敵がいるときにwarrior.rest!を実行すると回復が敵の攻撃に追いつかなくなるのでwarrior.feel.empty?がtrueを出したときのみwarrior.rest!させる。
warrior.feel.empty?がfalse(敵がいる)の場合はwarrior.attack!で攻撃を優先させる。