Created
April 23, 2014 18:08
-
-
Save robtarr/11226529 to your computer and use it in GitHub Desktop.
Ruby Warrior Levels - simple solutions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Player | |
def play_turn(warrior) | |
warrior.walk! | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Player | |
def play_turn(warrior) | |
if warrior.feel.empty? | |
warrior.walk! | |
else | |
warrior.attack! | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Player | |
def play_turn(warrior) | |
if warrior.feel.enemy? | |
warrior.attack! | |
elsif warrior.health < 15 | |
warrior.rest! | |
else | |
warrior.walk! | |
end | |
end | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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