Skip to content

Instantly share code, notes, and snippets.

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