Created
March 18, 2014 16:31
-
-
Save shortdiv/9623788 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) | |
advance = Advance.new(warrior) | |
attack = Attack.new(warrior) | |
rest = Rest.new(warrior) | |
actions = [rest, advance, attack] | |
actions.each do |action| | |
if action.possible? | |
action.go! | |
break | |
end | |
end | |
end | |
end | |
class Action | |
def initialize(warrior) | |
@warrior = warrior | |
end | |
end | |
class Advance < Action | |
def possible? | |
@warrior.feel.empty? | |
end | |
def go! | |
@warrior.walk! | |
end | |
end | |
class Attack < Action | |
def possible? | |
not @warrior.feel.empty? | |
end | |
def go! | |
@warrior.attack! | |
end | |
end | |
class Rest < Action | |
def possible? | |
@warrior.health < 20 && @warrior.feel.empty? | |
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