Skip to content

Instantly share code, notes, and snippets.

@rrgayhart
Last active December 23, 2015 02:29
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 rrgayhart/6567604 to your computer and use it in GitHub Desktop.
Save rrgayhart/6567604 to your computer and use it in GitHub Desktop.
Ruby Warrior by Bloc Level 2 Solution
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.empty? != true
warrior.attack!
elsif warrior.health < 20
warrior.rest!
else
warrior.walk!
end
end
end
class Player
def initialize
@health = 20
end
def play_turn(warrior)
if warrior.feel.empty? != true
warrior.attack!
elsif warrior.health < 20 && warrior.health >= @health
warrior.rest!
else
warrior.walk!
end
@health = warrior.health
end
end
class Player
def initialize
@health = 20
@space = 0
end
def play_turn(warrior)
if warrior.feel.empty? != true && warrior.feel.captive? != true
warrior.attack!
elsif warrior.health < 20 && warrior.health >= @health
warrior.rest!
elsif warrior.feel.captive?
warrior.rescue!
elsif warrior.feel(:backward).captive?
warrior.rescue!:backward
elsif warrior.feel(:backward).wall? != true && @space < 2
warrior.walk!:backward
@space += 1
elsif warrior.health < @health
warrior.walk!:backward
else
warrior.walk!
end
@health = warrior.health
end
end
class Player
def initialize
@health = 20
@space = 0
end
def play_turn(warrior)
if warrior.feel.wall?
warrior.pivot!
elsif warrior.feel.empty? != true && warrior.feel.captive? != true
warrior.attack!
elsif warrior.health < 20 && warrior.health >= @health
warrior.rest!
elsif warrior.feel.captive?
warrior.rescue!
elsif warrior.feel(:backward).captive?
warrior.rescue!:backward
elsif warrior.feel(:backward).wall? != true && @space < 2
warrior.walk!:backward
@space += 1
elsif warrior.health < @health && warrior.health < 15
warrior.walk!:backward
else
warrior.walk!
end
@health = warrior.health
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment