Ruby Warrior
- 勇者を
ruby
コードで操って、レベルをクリアしていくゲーム -
オリジナルは
Rogue
みたいな見た目のテキストゲームでryanb
さん作。10年くらい前に公開 - オリジナルを Bloc が Web ゲームにしたようだ。 Good Job!
ルール
- コードの中の
def play_turn(warrior) ... end
の部分が1ターンで、ここにコードを書く - ターンを繰り返して、敵を倒しながら、脱出すればよい
- 1ターンで1回しか
warrior.action!
できない(ターン内でループの処理もできない)1 - レベルが進むごとにスキル
warrior.action!
が増えていく - 初心者モードと中級者モードがある(今回は初心者モードでやってみた)
Level 1
You see before yourself a long hallway with stairs at the end. There is nothing in the way.
class Player
def play_turn(warrior)
# cool code goes here
warrior.walk!
end
end
このレベルの見所: 楽しく歩く
Level 2
It is too dark to see anything, but you smell sludge nearby.
class Player
def play_turn(warrior)
if warrior.feel.empty?
warrior.walk!
else
warrior.attack!
end
end
end
このレベルの見所: 初めての敵
-
warrior.attack!
を獲得
Level 3
The air feels thicker than before. There must be a horde of sludge.
class Player
def play_turn(warrior)
if warrior.feel.empty?
if warrior.health < 15
warrior.rest!
else
warrior.walk!
end
else
warrior.attack!
end
end
end
このレベルの見所: 休む時は休む
-
warrior.rest!
を獲得
Level 4
You can hear bow strings being stretched.
class Player
def play_turn(warrior)
@health = warrior.health unless @health
if warrior.feel.empty?
if @health <= warrior.health && warrior.health < 12
warrior.rest!
else
warrior.walk!
end
else
warrior.attack!
end
@health = warrior.health
end
end
このレベルの見所: 体調管理
-
warrior.health
を獲得
Level 5
You hear cries for help. Captives must need rescuing.
class Player
def play_turn(warrior)
@health = warrior.health unless @health
if warrior.feel.captive?
warrior.rescue!
elsif warrior.feel.empty?
if @health <= warrior.health && warrior.health < 13
warrior.rest!
else
warrior.walk!
end
else
warrior.attack!
end
@health = warrior.health
end
end
このレベルの見所: 敵か味方か?
-
warrior.rescue!
を獲得
Level 6
The wall behind you feels a bit further away in this room. And you hear more cries for help.
class Player
def initialize()
@captive = true
end
def play_turn(warrior)
@health = warrior.health unless @health
if @captive
if warrior.feel(:backward).captive?
warrior.rescue!(:backward)
@captive = false
else
warrior.walk!(:backward)
end
else
if warrior.feel.empty?
if @health > warrior.health && warrior.health < 10
warrior.walk!(:backward)
elsif @health <= warrior.health && warrior.health < 20
warrior.rest!
else
warrior.walk!
end
else
warrior.attack!
end
@health = warrior.health
end
end
end
このレベルの見所: ヒット & アウェイ
captive
がいるかどうかをフラグでもっておいてそれで処理を変えようとしていろいろうまくいかなかったが、最終的に initialize()
に書いてうまくいった
Level 7
You feel a wall right in front of you and an opening behind you.
class Player
def play_turn(warrior)
@health = warrior.health unless @health
if warrior.feel.wall?
warrior.pivot!
else
if warrior.feel.empty?
if @health > warrior.health && warrior.health < 10
warrior.walk!(:backward)
elsif @health <= warrior.health && warrior.health < 20
warrior.rest!
else
warrior.walk!
end
else
warrior.attack!
end
end
@health = warrior.health
end
end
このレベルの見所: 振り向けば、いつかみた風景
-
warrior.pivot!
を獲得
Level 8
You hear the mumbling of wizards. Beware of their deadly wands! Good thing you found a bow.
class Player
def initialize()
@captive = true
end
def play_turn(warrior)
@health = warrior.health unless @health
if @captive
if warrior.feel.captive?
warrior.rescue!
@captive = false
else
warrior.walk!
end
else
if warrior.look.any?{|s| s.enemy?}
warrior.shoot!
else
warrior.walk!
end
end
end
end
このレベルの見所: 遠いもんがちー
-
warrior.look
とwarrior.shoot!
を獲得 - ウィザードっぽいのが遠隔から一撃で
11
くらいライフ削ってくるので、二発くらうと死ぬ... でも意外とレンジは短い -
any?
のおかげでスッキリかけたのではないか
Level 9
Time to hone your skills and apply all of the abilities that you have learned.
class Player
def initialize()
@left_captive = true
end
def play_turn(warrior)
if @left_captive
if warrior.look(:backward).any?{|s| s.enemy?}
warrior.shoot!(:backward)
elsif warrior.feel(:backward).captive?
warrior.rescue!(:backward)
@left_captive = false
else
warrior.walk!(:backward)
end
else
if warrior.look.any?{|s| s.enemy?}
warrior.shoot!
elsif warrior.feel.captive?
warrior.rescue!
elsif warrior.feel.wall?
warrior.pivot!
else
warrior.walk!
end
end
end
end
このレベルの見所: ムーンウォーク
- めっちゃ弓だけに頼った勝ち方!後ろ向きで矢を放ち、一回も
warrior.rest!
しない無鉄砲野郎。学んだことを使っていない。こんなんでいいのか?
Ruby Warrior になろう
もっといいコードがあったら教えてください!
-
Only one action can be performed per turn.
のエラーがでる ↩