Created
July 31, 2013 08:48
-
-
Save caingougou/6120451 to your computer and use it in GitHub Desktop.
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 | |
@hero = nil | |
@health = 20 | |
@danger = 10 | |
@direction = :forward | |
end | |
def play_turn(warrior) | |
@hero = warrior | |
if in_battle? | |
if warrior.health > @danger | |
battle | |
else | |
escape | |
end | |
elsif warrior.health < 20 | |
warrior.rest! | |
else | |
if warrior.feel(@direction).captive? | |
warrior.rescue! @direction | |
elsif warrior.feel(@direction).wall? | |
turn_around! | |
# warrior.walk! @direction | |
else | |
warrior.walk! @direction | |
end | |
end | |
@health = warrior.health | |
end | |
def in_battle? | |
if @hero.health < @health | |
return true | |
elsif @hero.feel(@direction).enemy? | |
return true | |
else | |
return false | |
end | |
end | |
def battle | |
if @hero.feel(@direction).enemy? | |
@hero.attack! @direction | |
elsif @hero.feel(@direction).captive? | |
@hero.rescue! @direction | |
elsif @hero.feel(@direction).wall? | |
turn_around! | |
@hero.walk! @direction | |
else | |
@hero.walk! @direction | |
end | |
end | |
def escape | |
# turn_around! | |
@hero.walk! :backward | |
end | |
def turn_around! | |
@hero.pivot! | |
# if @direction == :forward | |
# @direction = :backward | |
# else | |
# @direction = :forward | |
# end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment