Created
January 5, 2014 16:52
-
-
Save per-gron/8270630 to your computer and use it in GitHub Desktop.
My girlfriend just wrote a text based adventure game in Ruby!
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
# encoding: utf-8 | |
____ = <<EOS | |
Welcome to the amazing maze! | |
You can go in these directions: | |
* North | |
* South | |
* East | |
* West | |
Where do you want to go? [N/S/E/W] | |
EOS | |
puts "Welcome to the amazing maze!" | |
puts | |
pos_x = 0 | |
pos_y = 0 | |
map = [ | |
["S", "", "S/E", "GOAL!"], | |
["N/E/S", "W/S/E", "W/N", ""], | |
["N", "S/N", "E", "W/S"], | |
["E", "N/W/E", "W/E", "W/N"] | |
] | |
while true do | |
row = map[pos_y] | |
allowed_directions = row[pos_x] | |
if allowed_directions == "GOAL!" | |
puts "You have now won the game. Eternal glory goes to you. Epic." | |
break | |
end | |
puts "Where do you want to go? [#{allowed_directions}]" | |
# puts "(#{pos_x},#{pos_y})" | |
direction = gets.strip.upcase | |
puts | |
if !allowed_directions.include? direction | |
puts "Naughty little you!" | |
puts | |
next | |
end | |
if direction == "N" | |
pos_y = pos_y - 1 | |
elsif direction == "S" | |
pos_y = pos_y + 1 | |
elsif direction == "E" | |
pos_x = pos_x + 1 | |
elsif direction == "W" | |
pos_x = pos_x - 1 | |
else | |
raise "WHAT ARE YOU DOING? Are you stupid?" | |
end | |
puts | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment