Skip to content

Instantly share code, notes, and snippets.

@rickbacci
Created May 7, 2012 16:49
Show Gist options
  • Save rickbacci/2628912 to your computer and use it in GitHub Desktop.
Save rickbacci/2628912 to your computer and use it in GitHub Desktop.
My rubywarrior
class Player
def initialize
@warrior = 'warrior'
end
def play_turn(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
@rickbacci
Copy link
Author

I can't figure out how you made those methods. I've looked in my book, and followed the syntax, but I am obviously missing something

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