Skip to content

Instantly share code, notes, and snippets.

@jonoliver
Created March 18, 2014 16:38
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 jonoliver/9623920 to your computer and use it in GitHub Desktop.
Save jonoliver/9623920 to your computer and use it in GitHub Desktop.
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