Skip to content

Instantly share code, notes, and snippets.

@Videmor
Last active December 30, 2015 21:09
Show Gist options
  • Select an option

  • Save Videmor/7886010 to your computer and use it in GitHub Desktop.

Select an option

Save Videmor/7886010 to your computer and use it in GitHub Desktop.
Ruby Warrior - Level 4 : No new abilities this time, but you must be careful not to rest while taking damage. Save a @health instance variable and compare it on each turn to see if you're taking damage.
class Player
def play_turn(warrior)
# cool code goes here
@health = warrior.health unless @health
if warrior.feel.enemy?
warrior.attack!
elsif warrior.health < 8 or @health < warrior.health
warrior.rest!
else
warrior.walk!
end
@health = warrior.health
end
end
@Videmor
Copy link
Author

Videmor commented Dec 10, 2013

demo

class Player
def play_turn(warrior)
# cool code goes here

@health = warrior.health unless @health

if warrior.feel.enemy?
  warrior.attack!
elsif warrior.health < 15 and @health <= warrior.health
  warrior.rest!
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