Skip to content

Instantly share code, notes, and snippets.

@robtarr
Created April 23, 2014 18:08
Show Gist options
  • Save robtarr/11226529 to your computer and use it in GitHub Desktop.
Save robtarr/11226529 to your computer and use it in GitHub Desktop.
Ruby Warrior Levels - simple solutions
class Player
def play_turn(warrior)
warrior.walk!
end
end
class Player
def play_turn(warrior)
if warrior.feel.empty?
warrior.walk!
else
warrior.attack!
end
end
end
class Player
def play_turn(warrior)
if warrior.feel.enemy?
warrior.attack!
elsif warrior.health < 15
warrior.rest!
else
warrior.walk!
end
end
end
class Player
def initialize
@last_health = 20
end
def play_turn(warrior)
if warrior.feel.enemy?
warrior.attack!
elsif warrior.health < 15 and warrior.health >= @last_health
warrior.rest!
else
warrior.walk!
end
@last_health = warrior.health
end
end
class Player
def initialize
@last_health = 20
end
def play_turn(warrior)
if warrior.feel.captive?
warrior.rescue!
elsif warrior.feel.enemy?
warrior.attack!
elsif warrior.health < 15 and warrior.health >= @last_health
warrior.rest!
else
warrior.walk!
end
@last_health = warrior.health
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment