Skip to content

Instantly share code, notes, and snippets.

@hide24
Created August 15, 2013 02:32
Show Gist options
  • Save hide24/6237720 to your computer and use it in GitHub Desktop.
Save hide24/6237720 to your computer and use it in GitHub Desktop.
ruby warrior level 9 適当に書き足したのでlv9では要らない機能もある。 全レベル対応したいけど、lv6(初手で後退して救出せねばならないやつ)対応が思いつかない。
class Player
def play_turn(warrior)
spaces = warrior.look
space = spaces.first
backwards = warrior.look(:backward)
health = warrior.health
if space.enemy?
warrior.attack!
elsif space.captive?
warrior.rescue!
elsif space.wall?
warrior.pivot!
elsif !spaces.any?{|s| s.captive?} && spaces.any?{|s| s.enemy?} && !backwards.any?{|s| s.enemy?}
warrior.shoot!
elsif health < 10 && @health > health
warrior.walk!(:backward)
elsif health < 20 && @health <= health
warrior.rest!
else
warrior.walk!
end
@health = warrior.health
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment