Skip to content

Instantly share code, notes, and snippets.

@GeoffCrittenden
Last active December 20, 2015 11:39
Show Gist options
  • Save GeoffCrittenden/6124713 to your computer and use it in GitHub Desktop.
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…
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
@GeoffCrittenden
Copy link
Author

SOLVED: I was assuming incorrectly about when the game was adding/subtracting health from the warrior. Once I realized that, I figured it out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment