Skip to content

Instantly share code, notes, and snippets.

@zspencer
Forked from rickbacci/how_to_make_method.rb
Created May 7, 2012 17:15
Show Gist options
  • Save zspencer/2629046 to your computer and use it in GitHub Desktop.
Save zspencer/2629046 to your computer and use it in GitHub Desktop.
My rubywarrior
class Player
def initialize
end
def play_turn(warrior)
@warrior = warrior
move_forward
end
def move_forward
@warrior.walk!
end
end
class Player
def initialize
@health = 20
@direction = :forward
end
def play_turn(warrior)
if @health > warrior.health # under attack
if warrior.health < 10
warrior.walk!(:backward)
elsif warrior.look.enemy?
warrior.shoot!
else
warrior.walk!
end
else
if warrior.health < 20
warrior.rest!
else
warrior.look
end
if warrior.look[0].captive? || warrior.look[1].captive? || warrior.look[2].captive? == true
if warrior.look[0].captive?
warrior.rescue!
else
warrior.walk!
end
else
if warrior.look[2].enemy? || warrior.look[1].enemy?
warrior.shoot!
elsif warrior.look[0].enemy?
warrior.attack!
elsif warrior.look[0].wall?
warrior.pivot!
else
warrior.walk!
end
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