Skip to content

Instantly share code, notes, and snippets.

@ticktricktrack
Last active December 30, 2015 09:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ticktricktrack/7810422 to your computer and use it in GitHub Desktop.
Save ticktricktrack/7810422 to your computer and use it in GitHub Desktop.
class Player
def play_turn(warrior)
@health ||= 20
@attacked ||= false
@warrior = warrior
@space = warrior.feel(:forward)
@spaces = warrior.look(:forward)
check_health
act!
@health = @warrior.health
end
def act!
[:rescue_captive, :turn_around, :attack, :use_bow, :restore_health, :move].each do |action|
return if self.send(action)
end
end
def check_health
if @warrior.health < @health
@attacked = true
else
@attacked = false
end
end
def use_bow
@warrior.shoot! and return true if @spaces[2].enemy?
false
end
def attack
@warrior.attack! and return true if @space.enemy?
false
end
def turn_around
@warrior.pivot! and return true if @space.wall?
false
end
def move
@warrior.walk!
end
def rescue_captive
@warrior.rescue! and return true if @space.captive?
false
end
def restore_health
if @warrior.health < 20
@warrior.rest!
@attacked = false
return true
end
false
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment