Created
August 5, 2013 04:41
-
-
Save leckylao/6153567 to your computer and use it in GitHub Desktop.
Ruby Warrior Epic Mode:
Level Score: 74
Time Bonus: 5
Clear Bonus: 16
Level Grade: A
Total Score: 510 + 95 = 605
Your average grade for this tower is: A Level 1: S Level 2: A Level 3: S Level 4: S Level 5: A Level 6: A Level 7: S Level 8: S Level 9: A
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) | |
@direction ||= :forward | |
@opposite_direction = opposite_direction(@direction) | |
@warrior = warrior | |
@rest ||= false | |
@action = false | |
@health ||= warrior.health | |
@turn ||= 1 | |
@hit_at_start ||= false | |
@captive_at_start ||= false | |
rest_mode | |
# Check if being hit at the start | |
if @health > @warrior.health && @turn == 2 | |
@hit_at_start = true | |
end | |
handle_hit_at_start if @hit_at_start | |
# Check if captive at the start | |
spaces = warrior.look(@opposite_direction) | |
if spaces[1].captive? && @turn == 1 | |
@captive_at_start = true | |
end | |
handle_captive_at_start if @captive_at_start | |
space = warrior.feel(@direction) | |
handle_space(space) | |
spaces = warrior.look(@direction) | |
handle_spaces(spaces) | |
@warrior.walk!(@direction) unless @action | |
@health = warrior.health | |
@turn += 1 | |
end | |
def opposite_direction(direction) | |
if direction == :backward | |
:forward | |
else | |
:backward | |
end | |
end | |
def handle_space(space) | |
if space.wall? | |
@warrior.pivot!(@opposite_direction) unless @action | |
@action = true | |
@direction = @opposite_direction | |
@opposite_direction = opposite_direction(@direction) | |
elsif space.enemy? | |
@warrior.attack!(@direction) unless @action | |
@action = true | |
elsif space.captive? | |
@warrior.rescue!(@direction) unless @action | |
@action = true | |
elsif space.empty? && @warrior.health < 12 | |
@rest = true # Rest Mode | |
rest_mode | |
end | |
end | |
def handle_spaces(spaces) | |
if spaces[1].enemy? || (spaces[2].enemy? && !spaces[1].captive?) | |
@warrior.shoot!(@direction) unless @action | |
@action = true | |
end | |
end | |
def rest_mode | |
if @rest | |
@rest = false if @warrior.health > 16 | |
# Being hit | |
if @health > @warrior.health | |
@warrior.walk!(@opposite_direction) unless @action | |
@action = true | |
else | |
@warrior.rest! unless @action | |
@action = true | |
end | |
end | |
end | |
def handle_hit_at_start | |
spaces = @warrior.look(@opposite_direction) | |
if spaces[2].enemy? | |
@warrior.shoot!(@opposite_direction) unless @action | |
@action = true | |
else | |
@hit_at_start = false | |
end | |
end | |
def handle_captive_at_start | |
if @warrior.feel(@opposite_direction).captive? | |
@warrior.rescue!(@opposite_direction) unless @action | |
@action = true | |
@captive_at_start = false | |
else | |
@warrior.walk!(@opposite_direction) unless @action | |
@action = true | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment