Skip to content

Instantly share code, notes, and snippets.

@shortdiv
Created March 18, 2014 16:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shortdiv/9623788 to your computer and use it in GitHub Desktop.
Save shortdiv/9623788 to your computer and use it in GitHub Desktop.
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