LoginSignup
0
0

More than 5 years have passed since last update.

#11 【攻略】RubyWarrior Level2 ~中級編~

Posted at

RubyWarrior Level2中級編をやっていきます。
前回同様道幅が広くなっているので、Level2でもちょっと難しめに感じます。

概要

道幅広い+敵が広がって行く手を阻んでいます。いい感じに倒しつつ進みましょう。
ゲームの案内文の、

Just like walking, you can attack! and feel in multiple directions (:forward, :left, :right, :backward).

がいいヒントになってます。

スクリプト

class Player
  def play_turn(warrior)
    dir = warrior.direction_of_stairs

    if warrior.feel(dir).empty?
      warrior.walk!(dir)
    else
      warrior.attack!(dir)
    end
  end
end

解説

まず、

dir = warrior.direction_of_stairs

でdirに階段の方向を入れてあげる。

そして、

if warrior.feel(dir).empty?
  warrior.walk!(dir)
else
  warrior.attack!(dir)
end

dirの方向がemptyならばその方向に進行、違ったらその方向に攻撃、といった感じ。

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