Created
July 30, 2013 19:14
-
-
Save acrookston/6115938 to your computer and use it in GitHub Desktop.
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 od(dir) | |
return dir == :backward ? :forward : :backward | |
end | |
def play_turn(warrior) | |
w = warrior | |
@direction = :forward if @direction == nil | |
@back = 0 if @back == nil | |
@rest = false if @rest == nil | |
if w.feel(@direction).wall? | |
@direction = od(@direction) | |
end | |
# raise [w.feel(:backward).wall?, @direction].inspect | |
if w.health < 9 || @rest | |
@rest = true | |
if w.feel(od(@direction)).empty? && @back < 3 | |
@back += 1 | |
w.walk! od(@direction) | |
else | |
w.rest! | |
if w.health >= 18 | |
@back = 0 | |
@rest = false | |
end | |
end | |
elsif shoot? w, od(@direction) | |
w.shoot! od(@direction) | |
elsif shoot? w, @direction | |
w.shoot! @direction | |
elsif w.feel(@direction).empty? | |
w.walk!(@direction) | |
elsif w.feel(@direction).captive? | |
w.rescue!(@direction) | |
elsif w.feel(@direction).enemy? | |
w.attack!(@direction) | |
@rest = true | |
end | |
end | |
def shoot?(w, dir) | |
w.look(dir).each do |s| | |
if s.captive? | |
return false | |
elsif s.enemy? | |
return true | |
end | |
end | |
return false | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment