Created
September 25, 2012 00:17
-
-
Save wwkeyboard/3779252 to your computer and use it in GitHub Desktop.
Player from the 9/24 class
This file contains hidden or 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 | |
attr_accessor :warrior | |
def initialize | |
@old_health = 20 | |
end | |
def play_turn(warrior) | |
@warrior = warrior | |
if warrior.feel.empty? | |
normal_move | |
else | |
obstruction_move | |
end | |
@old_health = warrior.health | |
end | |
def obstruction_move | |
if warrior.feel.captive? | |
warrior.rescue! | |
else | |
warrior.attack! | |
end | |
end | |
def normal_move | |
if healthy? or taking_damage? | |
@warrior.walk! | |
else | |
@warrior.rest! | |
end | |
end | |
def taking_damage? | |
@old_health > @warrior.health | |
end | |
def healthy? | |
@warrior.health == 20 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment