Skip to content

Instantly share code, notes, and snippets.

@dcoxall
Created July 28, 2013 10:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dcoxall/6098155 to your computer and use it in GitHub Desktop.
Save dcoxall/6098155 to your computer and use it in GitHub Desktop.
class Player
def play_turn(warrior)
# cool code goes here
@warrior = warrior
@previous_health ||= @warrior.health
forward_spaces = @warrior.look
backward_spaces = @warrior.look(:backward)
enemy_ahead = forward_spaces.any?(&:enemy?)
enemy_behind = backward_spaces.any?(&:enemy?)
captive_ahead = forward_spaces.any?(&:captive?)
stairs_ahead = forward_spaces.any?(&:stairs?)
if !enemy_ahead && !enemy_behind && @warrior.health < 20
@warrior.rest!
elsif @previous_health > @warrior.health
# Taking damage so head towards nearest enemy
if @warrior.feel.enemy?
@warrior.attack!
else
@warrior.walk!
end
elsif enemy_ahead && !captive_ahead
@warrior.shoot!
elsif forward_spaces[0].captive?
@warrior.rescue!
elsif forward_spaces.any?(&:wall?) && !stairs_ahead && !captive_ahead
@warrior.pivot!
else
@warrior.walk!
end
@previous_health = @warrior.health
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment