Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.