Skip to content

Instantly share code, notes, and snippets.

@jasonhazel
Last active December 20, 2015 09:29
Show Gist options
  • Save jasonhazel/6107702 to your computer and use it in GitHub Desktop.
Save jasonhazel/6107702 to your computer and use it in GitHub Desktop.
# https://www.bloc.io/ruby-warrior
class Player
def initialize
@health = 20
@begining = false
@action = false
@direction = :backward
end
def play_turn(warrior)
@action = false
@warrior = warrior
@direction = :forward if move_forward?
retreat unless @action
heal unless @action
move unless @action
attack unless @action
save unless @action
@health = warrior.health
end
def move_forward?
@warrior.feel(:backward).wall?
end
def retreat?
damaged? && feels_empty? && min_health?
end
def retreat
if retreat?
@warrior.walk! :backward
@action = true
end
end
def heal?
!damaged? && !full_health?
end
def heal
if heal?
@warrior.rest!
@action = true
end
end
def save
if feels_captive?
@warrior.rescue!(@direction)
@action = true
end
end
def move
if feels_empty?
@warrior.walk!(@direction)
@action = true
end
end
def attack
unless feels_empty?
unless @warrior.feel(@direction).captive?
@warrior.attack!(@direction)
@action = true
end
end
end
def feels_captive?
@warrior.feel(@direction).captive?
end
def feels_empty?
@warrior.feel(@direction).empty?
end
def full_health?
@warrior.health == 20
end
def min_health?
@warrior.health < 15
end
def damaged?
@warrior.health < @health
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment