Skip to content

Instantly share code, notes, and snippets.

@athom
Created July 11, 2011 09:50
Show Gist options
  • Save athom/1075623 to your computer and use it in GitHub Desktop.
Save athom/1075623 to your computer and use it in GitHub Desktop.
rubywarrior-step-by-step
require "readline"
class Player
def play_turn(w)
# add your code here
buf = Readline.readline("> ", true )
action=buf[0]
direction=buf[1]
abilities = {'w' => 'w.walk!', 'a' => 'w.attack!', 'r' => 'w.rest!', 'c' => 'w.rescue!', 's' => 'w.shoot!', 'b' => 'w.bind!', 'd' => 'w.detonate!'}
directions = {'l' => ':forward', 'h' => ':backward', 'j' => ':right', 'k' => ':left'}
abilities.each_pair do |a, act|
if a == action
if action == 'r'
w.rest!
return
end
directions.each_pair do |d, dir|
if d == direction
eval act+dir
end
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment