Created
May 7, 2012 16:49
-
-
Save rickbacci/2628912 to your computer and use it in GitHub Desktop.
My rubywarrior
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Player | |
def initialize | |
@warrior = 'warrior' | |
end | |
def play_turn(warrior) | |
move_forward | |
end | |
def move_forward | |
@warrior.walk! | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
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