2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

#3 【攻略】RubyWarrior Level3

2
Posted at

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!で攻撃を優先させる。

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?