Last active
December 30, 2015 09:39
-
-
Save ticktricktrack/7810422 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 ||= 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