Last active
December 20, 2015 11:39
-
-
Save GeoffCrittenden/6124713 to your computer and use it in GitHub Desktop.
I'm running through Ruby Warrior, and I'm at Level 6 (https://www.bloc.io/ruby-warrior/#/warriors/26290/levels/6). I've completed the level, but I need to clean up the code. I'm not sure exactly what the problem is. This code doesn't stop and rest in one spot until health == 20. It keeps walking around while resting. The code 'as is' is successf…
This file contains hidden or 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 | |
@health = 20 | |
@wall = 0 | |
end | |
def play_turn(warrior) | |
if @health >= warrior.health | |
if warrior.feel.enemy? then warrior.attack! | |
elsif warrior.health < 20 then warrior.rest! | |
elsif warrior.feel(:backward).captive? then warrior.rescue!(:backward) | |
elsif warrior.feel.captive? then warrior.rescue! | |
elsif warrior.feel(:backward).wall? then warrior.walk! | |
@wall = 1 | |
elsif @wall == 1 then warrior.walk! | |
else warrior.walk!(:backward) | |
end | |
else | |
if warrior.feel.enemy? && warrior.health > 6 then warrior.attack! | |
elsif warrior.feel.empty? && warrior.health > 13 then warrior.walk! | |
else warrior.walk!(:backward) | |
end | |
end | |
@health = warrior.health | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
SOLVED: I was assuming incorrectly about when the game was adding/subtracting health from the warrior. Once I realized that, I figured it out.