Skip to content

Instantly share code, notes, and snippets.

@beezly
Created January 11, 2012 16:02
Show Gist options
  • Save beezly/1595352 to your computer and use it in GitHub Desktop.
Save beezly/1595352 to your computer and use it in GitHub Desktop.
Beezobot!
class Player
@@health = 0
@@direction = :forward
@@mode = :attack
def taking_damage(warrior)
@@health > warrior.health
end
def next_thingy(spaces)
spaces.each do |space|
unless space.empty?
return space
end
end
return spaces[0]
end
def play_turn(warrior)
if warrior.feel(@@direction).wall?
warrior.pivot!
elsif next_thingy(warrior.look(@@direction)).captive?
if warrior.feel(@@direction).captive?
warrior.rescue! @@direction
else
warrior.walk! @@direction
end
else
if warrior.health < 13 and next_thingy(warrior.look(@@direction)).enemy?
@@mode = :recuperate
end
if @@mode == :recuperate
if taking_damage warrior
if next_thingy(warrior.look(:forward)) == :archer
warrior.walk! :backward
else
unless warrior.feel(@@direction).enemy?
warrior.walk! :forward
else
@@mode = :attack
warrior.attack! @@direction
end
end
else
unless warrior.health == 20
warrior.rest!
else
warrior.walk! @@direction
@@mode = :attack
end
end
else
if next_thingy(warrior.look(:backward)).enemy?
warrior.shoot! :backward
elsif next_thingy(warrior.look(:forward)).enemy?
warrior.shoot! :forward
else
warrior.walk! @@direction
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