-
-
Save zspencer/2629046 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 | |
end | |
def play_turn(warrior) | |
@warrior = 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