Created
July 28, 2013 06:40
-
-
Save soheil-zz/6097679 to your computer and use it in GitHub Desktop.
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) | |
@health = 0 if warrior.feel.empty? && @health == -1 | |
shootableEnemy = false | |
@pivoted = false | |
warrior.look.each do |space| | |
shootableEnemy |= space.enemy? | |
end | |
if !warrior.feel.enemy? && warrior.look.last.enemy? | |
warrior.shoot! | |
elsif warrior.feel.wall? | |
warrior.pivot! | |
@pivoted = true | |
elsif warrior.feel.captive? | |
warrior.rescue! | |
@rescued = true | |
elsif warrior.feel(:backward).captive? | |
warrior.rescue! :backward | |
@rescued = true | |
#elsif @rescued.nil? | |
# warrior.walk! :backward | |
elsif warrior.health < 20 && @health != -1 && warrior.feel.empty? | |
if [email protected]? && warrior.health < @health | |
@health = -1 | |
if warrior.feel.enemy? | |
warrior.attack! | |
else | |
warrior.walk! | |
end | |
else | |
@health = warrior.health | |
warrior.rest! | |
end | |
elsif warrior.health < 9 && @health != -1 | |
if warrior.feel.enemy? | |
warrior.walk! :backward | |
@health = warrior.health | |
else | |
if @health == warrior.health | |
warrior.rest! | |
else | |
warrior.walk! :forward | |
@health = -1 | |
end | |
end | |
elsif warrior.feel.enemy? | |
warrior.attack! | |
else | |
warrior.walk! | |
if @walked.nil? | |
@walked = 1 | |
else | |
@walked += 1 | |
end | |
end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment