Created
July 11, 2011 09:50
-
-
Save athom/1075623 to your computer and use it in GitHub Desktop.
rubywarrior-step-by-step
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
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