Created
August 1, 2013 08:30
-
-
Save KentaKomai/6129542 to your computer and use it in GitHub Desktop.
ruby warrior level 6
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 play_turn(warrior) | |
# initialize health and map | |
if @health == nil then | |
@health = warrior.health | |
end | |
if @map == nil then | |
@map = {0 => 'E'} | |
@map_index = 0 | |
end | |
space_forward = warrior.feel :forward | |
space_back = warrior.feel :backward | |
# 後ろが何もなく、まだ歩いたことがない場合 | |
if space_back.empty? and @map[@map_index - 1] == nil then | |
warrior.walk! :backward | |
@map_index -= -1 | |
@map[@map_index] = 'E' | |
# 後ろが捕虜の場合 | |
elsif space_back.captive? then | |
warrior.rescue! :backward | |
@map[@map_index - 1] = 'E' | |
# 後ろが壁の場合 | |
elsif space_back.wall? then | |
warrior.walk! :forward | |
@map[@map_index - 1] = 'W' | |
# 前が何もない場合 | |
elsif space_forward.empty? | |
# ダメージがある場合 | |
if @health > warrior.health then | |
warrior.walk! :forward | |
@bow_flag = true | |
# ダメージがなく、rest_flgがtrueの場合 | |
elsif @rest_flag then | |
warrior.rest! | |
if warrior.health >= 15 then | |
@rest_flag = false | |
end | |
# ダメージなしでreset_flgもない場合 | |
else | |
warrior.walk! :forward | |
@map[@map_index] = 'E' | |
end | |
# 前が敵の場合 | |
elsif space_forward.enemy? | |
if warrior.health >= 15 then | |
warrior.attack! | |
elsif @bow_flag == nil | |
warrior.walk! :backward | |
@rest_flag = true | |
else | |
warrior.attack! | |
end | |
@map_index += 1 | |
@map[@map_index] = 'M' | |
elsif @rest_flag then | |
warrior.rest! | |
if warrior.health >= 15 then | |
@rest_flag = false | |
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