Created
December 8, 2013 00:58
-
-
Save fl00r/7852033 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) | |
@max_health ||= warrior.health | |
case state(warrior) | |
when :lost | |
warrior.pivot! | |
when :captive | |
warrior.rescue! | |
when :enemyfar | |
warrior.shoot! and @rest = false | |
when :enemyclose | |
warrior.attack! and @rest = false | |
when :bleeding | |
warrior.rest! and @rest = true | |
else | |
warrior.walk! | |
end | |
@prev_health = warrior.health | |
end | |
def state(warrior) | |
return :lost if warrior.feel.wall? | |
return :captive if warrior.feel.captive? | |
return :enemyclose if warrior.feel.enemy? | |
return :underattack if @prev_health && warrior.health < @prev_health | |
return :enemyfar if (space = warrior.look.detect{ |s| s.enemy? || s.captive? }) && space.enemy? | |
return :bleeding if warrior.health < @max_health | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment