LoginSignup
0
0

More than 5 years have passed since last update.

#18 【攻略】RubyWarrior Level9 ~中級編~

Last updated at Posted at 2016-11-28

RubyWarrior攻略です。ついに最終回です。

概要

最後のステージは全てのマスに敵か捕虜が配置されています。爆弾攻撃で一気に敵を倒したいところですが、捕虜を巻き込んでしまうといけないので使用の際は注意しましょう。

スクリプト

class Player

  def initialize()
    @bomb = 0
    @walk = 0
  end

  def captive?(warrior)
    if warrior.feel(:right).captive?
      return :right
    elsif warrior.feel(:left).captive?
      return :left
    elsif warrior.feel(:forward).captive?
      return :forward
    elsif warrior.feel(:backward).captive?
      return :backward
    else
      return :none
    end
  end

  def enemy?(warrior)
    if warrior.feel(:right).enemy?
      return :right
    elsif warrior.feel(:left).enemy?
      return :left
    elsif warrior.feel(:forward).enemy?
      return :forward
    elsif warrior.feel(:backward).enemy?
      return :backward
    else
      return :none
    end
  end



  def play_turn(warrior)

    if @bomb < 3
      if warrior.feel.empty?
        if warrior.health < 10
          warrior.rest!
          return []
        else
          warrior.detonate!
          @bomb += 1
          return []
        end
      end
    end

    dir = enemy?(warrior)
    case dir
    when :left
      warrior.bind!(dir)
      return []
    when :right
      warrior.bind!(dir)
      return []
    when :forward
      if @bomb < 3
        warrior.detonate!
        @bomb += 1
        return []
      else
        warrior.attack!
        return []
      end
    end

    if warrior.health < 10
      warrior.rest!
      return []
    end


    if warrior.feel.empty?
      if @walk < 2
        warrior.walk!
        @walk += 1
        return []
      end
    end

    dir = captive?(warrior)
    case dir
    when :left
      warrior.rescue!(dir)
      return []
    when :right
      warrior.rescue!(dir)
      return []
    end




    dir = warrior.direction_of_stairs
    warrior.walk!(dir)



  end
end

解説

@bombは爆弾を投げた回数、@walkは前方に歩いた回数を保存しています。

爆弾を三回投げるとwarriorの目の前とその左右後ろの敵を倒すことができます。
また、前方に歩く回数を指定してあげることで効率良く捕虜を助けることができます。

全部終えてみての感想

RubyWarriorでやっていてよかったと思ったところは、

  • 超基本的なロジックの組み方を反復練習できる(if文とか)

  • (作ろうと思えば)メソッドを書く練習ができる

  • ゲーム感覚なのに(初心者にとって)程よい難度で成功体験が味わえる

逆によくないなと思ったところは、

  • やることが少し単調...?

  • Ruby頻出のメソッドとかを学ぶ機会ないので初心者は自分で調べなきゃいけない

ロジックの練習にはなるけど、RubyWarriorだけで完璧になったりとかRubyの組み込みのメソッド組み合わせるとかはできるようにはならないので、知識を補強しながらやるのがいいと思う。

0
0
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
0
0