Created
August 15, 2013 02:32
-
-
Save hide24/6237720 to your computer and use it in GitHub Desktop.
ruby warrior level 9
適当に書き足したのでlv9では要らない機能もある。
全レベル対応したいけど、lv6(初手で後退して救出せねばならないやつ)対応が思いつかない。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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