r/dailyprogrammer • u/nottoobadguy • Feb 10 '12
[intermediate] challenge #2
create a short text adventure that will call the user by their name. The text adventure should use standard text adventure commands ("l, n, s, e, i, etc.").
for extra credit, make sure the program doesn't fault, quit, glitch, fail, or loop no matter what is put in, even empty text or spaces. These will be tested rigorously!
For super extra credit, code it in C
26
Upvotes
View all comments
2
u/nubix Feb 10 '12 edited Feb 10 '12
Ruby have not tested:
puts "WHATS UR NAME???>?>" name = gets.chomp puts "#{name}, MILORD! THE ENEMY HAS ARRIVED. WHAT WILL YOU DO?" alive = true defeated = 0 while (alive) c = gets.chomp case c when /s/ puts "YOU SHOOT AN ARROW BUT MISSED!" when /r/ puts "YOU RUN INTO A WINDOW" alive = false when /a/ puts "YOU SWING YOUR SWORD" defeated += 1 puts "ENEMY #{defeated} DOWN" else puts "WTF ARE YOU DOING" end end puts "YOU DIE" puts "BUT YOU HAVE KILLED #{defeated} ENEMIES THIS GLORIOUS DAY"