Skip to content

Instantly share code, notes, and snippets.

@fl00r
Created December 8, 2013 00:58
Show Gist options
  • Save fl00r/7852033 to your computer and use it in GitHub Desktop.
Save fl00r/7852033 to your computer and use it in GitHub Desktop.
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