Skip to content

Instantly share code, notes, and snippets.

@eliseworthy
Created December 29, 2011 02:16
Show Gist options
  • Save eliseworthy/1531192 to your computer and use it in GitHub Desktop.
Save eliseworthy/1531192 to your computer and use it in GitHub Desktop.
Shopping game
$basket = []
$money = 70
def money_check
if $money < 0
dead("Guard attacks! You spent more money than you had!")
else
puts "Nice, still on budget!"
end
end
def prompt
print "> "
end
def dead(reason)
puts "#{reason} Better luck next time!"
Process.exit(0)
end
def get_move
prompt
gets.chomp.downcase
end
def start
puts "You are going Christmas shopping, but you waited until the last minute."
puts "It's now Christmas eve, and you have to go to the mall to buy presents."
puts "You only have $70."
puts "You need to get a book, golf clubs, and socks."
puts "You enter the mall."
entry
end
def entry
puts "You can either go left, right, or leave. Which way?"
while true
case get_move
when "left" then left_side
when "right" then right_side
when "leave" then exit
else puts ("What? Pick left or right, dude.")
end
end
end
def exit
if $basket.length == 3
puts "You successfully completed your holiday shopping!"
Process.exit(0)
else
dead("You left before buying everything! Your family will be PISSED!")
end
end
def left_side()
puts "You went to the left."
puts "You can go up the escalator, keep walking ahead, or go back."
puts "Which way do you want to go?"
while true
prompt; next_move = gets.chomp()
if ["ahead", "keep"].include?(next_move)
department_stores()
elsif next_move.include? "up"
upstairs()
elsif next_move == "go back"
start()
else
puts "What? Either keep walking ahead or go up the escalator."
end
end
end
def department_stores()
puts "There are two department stores in front of you."
puts "Do you want to go into WALMART or Nordstroms? You can also go back."
while true
prompt; next_move = gets.chomp()
next_move = next_move.downcase
if next_move.include? "walmart"
dead("Massive horde at the blue light special! You're trampled to death.")
elsif next_move.include? "nordstrom"
nordstroms()
elsif next_move == "go back"
left_side()
else
puts "What? I have no idea what store that is."
end
end
end
def nordstroms
puts "You're now in Nordstroms. What do you want to buy?"
while true
case get_move
when "book" then puts "They don't sell books at Nordstroms!"
when "golf clubs" then puts "They don't sell golf clubs at Nordstroms!"
when "socks"
if $basket.include?("socks")
puts "You already have socks!"
nordstroms()
else
puts "They have socks here, but they're $25!"
puts "You decide to buy them anyway and keep shopping."
puts "You go back into the hall."
$basket.push("socks")
$money = $money - 25
puts "You now have these items: #{$basket} and $#{$money}"
money_check
puts
department_stores()
end
when "nothing" then
puts "There's nothing here you want? Okay!"
puts "You go back into the hall."
department_stores()
else
puts "They don't sell that at Nordstroms! That's not even on your list!"
nordstroms()
end
end
end
def upstairs
puts "You can turn left, turn right, or go back."
while true
case get_move
when "left" then upstairs_left
when "right" then upstairs_right
when "go back" then
puts "You go back down the escalator."
left_side
else
puts "You can only go back, go left, or go right. Which way?"
end
end
end
def upstairs_left
puts "There's a food court and a Starbucks. Which do you want to enter?"
puts "You can also go back."
while true
case get_move
when "starbucks" then starbucks
when "food court" then food_court
when "go back" then
puts "You turn away from the delicious noms."
upstairs
else puts "You can't go there! Starbucks, food court, or go back?"
end
end
end
def starbucks
puts "You're in the Starbucks."
puts "Peppermint lattes are calling you!"
puts "Do you drink or go back?"
while true
case get_move
when "drink"
puts "You fork out $4 for your peppermint latte, but it's delicious!"
$money = $money - 4
puts "You now have $#{$money}"
money_check
puts "You head out."
puts
upstairs_left
when "go back"
puts "You decide to save your wallet."
puts "You head out."
puts
upstairs_left
else puts "You can only drink or go back, dude."
end
end
end
def food_court
puts "You're starving and have to eat."
puts "There's Panda Express, Chipotle, McDonalds, and Gyro World."
puts "What do you want?"
while true
prompt; restaurant = gets.chomp.downcase
if["panda express", "chipotle", "gyro world"].include?(restaurant)
puts "OM NOM NOM, you can't resist. You buy food at #{restaurant} for $8 and scarf out."
$money = $money - 8
puts "You now have $#{$money}."
money_check
puts "You head back, tummy full."
puts
upstairs_left
elsif restaurant.include? ("mcdonalds")
puts "You scarf down three cheeseburgers!"
dead("You have a heart attack!")
else
puts "They don't have #{restaurant} here! Pick something else!"
end
end
end
def upstairs_right
puts "In front of you is the only bathroom in the mall, and a sports store."
puts "Which one do you want to go to? You can also go back."
while true
case get_move
when "bathroom" then bathroom
when "sports store" then sports_store
when "go back" then upstairs
else puts "What?! Bathroom, sports store, or go back are your only options."
end
end
end
def bathroom
dead("There are #{rand(99999999)} people in line! It's Christmas, after all. You die waiting.")
end
def sports_store
puts "You're in the sports store. What do you want to buy?"
while true
prompt; answer = gets.chomp.downcase
if ["book", "puppy"].include?(answer)
puts "You can't get a #{answer} at the sports store!"
elsif answer.include?("socks")
puts "You can't buy socks at the sports store!"
elsif answer.include?("golf clubs")
if $basket.include?("golf clubs")
puts "You already have golf clubs!"
sports_store()
else
puts "Great idea! Golf clubs!"
puts "You buy them for $50 and head back out."
$basket.push("golf clubs")
$money = $money - 50
puts "You now have these items: #{$basket} and $#{$money}"
money_check
puts
upstairs_right
end
elsif answer.include?("nothing")
puts "You decide to leave."
puts
upstairs_right
else
puts "What the heck is #{answer}?! That's not even on your list!"
sports_store()
end
end
end
def right_side
puts "In front of you is a bookstore. Want to go in, keep walking, or go back?"
while true
case get_move
when "go in" then bookstore
when "keep walking" then right_continue
when "go back" then entry
else puts ("What?! You can only go in, keep walking, or go back.")
end
end
end
def bookstore
puts "You go into the bookstore, and you can't believe it!"
puts "BOOKS, everywhere! Want to buy one?"
while true
case get_move
when "yes"
if $basket.include?("mystery novel")
puts "You already bought a book!"
bookstore()
else
puts "Cool. You buy a mystery novel for $15."
puts "You head back out to the hall."
$basket.push("mystery novel")
$money = $money - 15
puts "You now have these items: #{$basket} and $#{$money}"
money_check
puts
right_side
end
when "no"
puts "You head back out to the hall."
puts
right_side
else
puts "What? Yes or no, man."
end
end
end
def right_continue
puts "In front of you is a sock store and a drug store."
puts "Which one do you want to go in? You can also go back."
while true
case get_move
when "sock store" then sock_store
when "drug store" then drug_store
when "go back" then right_side
else puts ("What?! Dude. Sock store, drug store, or go back.")
end
end
end
def sock_store
puts "OH SNAP! SO MANY SOCKS!"
puts "Want to buy some?!"
while true
case get_move
when "yes"
if $basket.include?("socks")
puts "You already bought socks!"
sock_store()
else
puts "You buy some frilly socks for $5."
puts "You head back out into the hall."
$basket.push("socks")
$money = $money - 5
puts "You now have these items: #{$basket} and $#{$money}"
money_check
puts
right_continue
end
when "no"
puts "You head back out into the hall."
puts
right_continue
else puts ("HUH WHA? Yes or no!")
end
end
end
def drug_store
puts "There's a lot of random stuff in here. What do you want to buy?"
prompt; answer = gets.chomp
puts "What?! #{answer}?! They don't sell that here. Do you want to leave?"
while true
case get_move
when "yes"
right_continue
when "no"
drug_store
else puts ("What?! Yes or no!")
end
end
end
start()
@codezilla-xx
Copy link

You are awesome!

@austenito
Copy link

this is leet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment