Created
March 18, 2014 16:38
-
-
Save jonoliver/9623920 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) | |
attack = AttackAction.new warrior | |
rest = RestAction.new warrior | |
walk = WalkAction.new warrior | |
for action in [attack, rest, walk] | |
if action.can? | |
action.go! | |
break | |
end | |
end | |
end | |
end | |
class AttackAction | |
def initialize warrior | |
@warrior = warrior | |
end | |
def can? | |
@warrior.feel.enemy? | |
end | |
def go! | |
@warrior.attack! | |
end | |
end | |
class WalkAction | |
def initialize warrior | |
@warrior = warrior | |
end | |
def can? | |
@warrior.feel.empty? | |
end | |
def go! | |
@warrior.walk! | |
end | |
end | |
class RestAction | |
def initialize warrior | |
@warrior = warrior | |
end | |
def can? | |
@warrior.feel.empty? and @warrior.health < 20 | |
end | |
def go! | |
@warrior.rest! | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment