#第6关 classPlayer @health @wall defplay_turn(warrior) if@wall == 1 if@health.to_i > warrior.health if warrior.feel.enemy? warrior.attack! else warrior.walk! end else if warrior.health < 20 #向后退到墙边加血 if (warrior.feel:backward).wall? warrior.rest! else warrior.walk!:backward @wall=0 end elsif warrior.feel.enemy? warrior.attack! else warrior.walk! end end else if (warrior.feel:backward).captive? warrior.rescue!:backward elsif (warrior.feel:backward).wall? @wall=1 else warrior.walk!:backward end end @health = warrior.health end end
#第7关 classPlayer @health defplay_turn(warrior) if warrior.feel.wall? if warrior.health < 20 warrior.rest! else warrior.pivot! end else if warrior.feel.enemy? warrior.attack! elsif@health.to_i > warrior.health if warrior.feel.enemy? warrior.attack! else warrior.walk! end else if warrior.health < 20 if@pivot == 1 warrior.walk! else warrior.pivot! @pivot = 1 end else warrior.walk! end end end @health = warrior.health end end
第8关代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#第8关 classPlayer defplay_turn(warrior) @status = warrior.look if@status[0].captive? warrior.rescue! elsif (@status[1].captive?)(@status[2].captive?) warrior.walk! elsif@status[0].enemy?@status[1].enemy?@status[2].enemy? warrior.shoot! else warrior.walk! end end end