Skip to content

Instantly share code, notes, and snippets.

@jnf
Last active January 29, 2016 03:30
Show Gist options
  • Save jnf/6198927 to your computer and use it in GitHub Desktop.
Save jnf/6198927 to your computer and use it in GitHub Desktop.
My code for level 9 of Ruby Warrior (https://www.bloc.io/ruby-warrior#/)
class Player
def play_turn(warrior)
@prev_health ||= 20
@warrior = warrior
@space = @warrior.feel
feel_it_out
@prev_health = warrior.health
end
protected
def feel_it_out
return about_face if @space.wall?
return be_a_hero if @space.captive?
return strike if @space.enemy?
return ddos if @warrior.look[2].enemy?
return reconsider if @warrior.health < @prev_health
return sleep_or_move if @space.empty?
end
def sleep_or_move
(@warrior.health < 20) ? sleep_it_off : move
end
def sleep_it_off
@warrior.rest!
end
def strike
@warrior.attack!
end
def ddos
@warrior.shoot!
end
def move(direction = :forward)
@warrior.walk! direction
end
def be_a_hero
@warrior.rescue!
end
def about_face
@warrior.pivot!
end
def reconsider
move(@warrior.health < 10 ? :backward : :forward)
end
end
@SebastianCarroll
Copy link

Nice! Thanks for sharing. I was completely stumped

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