Last active
December 20, 2015 09:29
-
-
Save jasonhazel/6107702 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# 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