Skip to content

Instantly share code, notes, and snippets.

@elpargo
Created August 23, 2013 06:12
Show Gist options
  • Save elpargo/6316040 to your computer and use it in GitHub Desktop.
Save elpargo/6316040 to your computer and use it in GitHub Desktop.
class Player
def initialize()
@health = 21
@forward = :forward
@backward = :backward
@direction = @forward
end
def play_turn(warrior)
spaces = warrior.look(:forward)
if spaces.first.wall?
warrior.pivot!
else
action(warrior,spaces)
end
end
def action(warrior,spaces)
if spaces.first.captive?
warrior.rescue!(@direction)
elsif spaces.first.enemy?
warrior.attack!
elsif spaces[2].enemy?
warrior.shoot!(@direction)
elsif warrior.health < 10
if warrior.health < @health
warrior.walk!(:backward) #retreat
else
warrior.rest!
end
elsif warrior.health < 20
if warrior.health < @health
warrior.walk! #charge!
else
warrior.rest!
end
else
warrior.walk!(@direction)
end
@health = warrior.health
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment