Skip to content

Instantly share code, notes, and snippets.

@KentaKomai
Created August 1, 2013 09:07
Show Gist options
  • Save KentaKomai/6129744 to your computer and use it in GitHub Desktop.
Save KentaKomai/6129744 to your computer and use it in GitHub Desktop.
ruby warrior level 9
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
look_forward = warrior.look :forward
look_back = warrior.look :backward
@acted = true
look_back.each do |space|
if space.captive? then
break
elsif space.enemy? and
warrior.shoot! :backward
@acted = false
break
end
end
look_forward.each do |space|
if space.captive? then
break
elsif space.enemy? and @acted and
warrior.shoot! :forward
@acted = false
break
end
end
if @acted then
if space_forward.wall? then
warrior.pivot!
# 前が何もない場合
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 space_forward.captive? then
warrior.rescue!
elsif @rest_flag then
warrior.rest!
if warrior.health >= 15 then
@rest_flag = false
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