Created
August 1, 2013 19:29
-
-
Save lexun/6134448 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
# This early version gets me through level 5 | |
# It's just a start... I'll add more later | |
class Player | |
def play_turn(w) | |
@warrior = w | |
perform_next_move | |
update_status | |
end | |
def perform_next_move | |
if captive_ahead? | |
rescue! | |
elsif enemy_ahead? | |
attack! | |
elsif injured? && safe? | |
rest! | |
else | |
walk! | |
end | |
end | |
def update_status | |
@health = health | |
end | |
def enemy_ahead? | |
!clear_ahead? | |
end | |
def captive_ahead? | |
feel.captive? | |
end | |
def clear_ahead? | |
feel.empty? | |
end | |
def injured? | |
health < 20 | |
end | |
def taking_damage? | |
@health ||= health | |
health < @health | |
end | |
def safe? | |
!taking_damage? | |
end | |
def method_missing(m) | |
@warrior.send(m) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment