Evil Vending Machine : A Game

I created this simple game using Ruby. I would like people with knowledge in programming to give me some feedback…is it alright?

to run this, you need to install ruby first then save the code in (.rb) file then run it from the shell.

so without further ado..

def machine
puts “You’re hungry, so you walk to the vending machine”
puts “1. insert a quarter for a bag of chips”
puts “2. insert 50 cents for a candy bar”

choice = $stdin.gets.chomp
choice = choice.to_i

if choice == 1
puts “you got sucked into a video game!”
forest_level_1
elsif choice == 2
puts “you got sucked into a video game!”
mad_king_level_1
else
puts “type either one or two. try again.”
machine
end
end

def forest_level_1
puts “you find yourself in a forest”
puts “there is an angry lion infront of you? what do you do?”
puts “run, fight or distract the lion?”

choice1 = $stdin.gets.chomp

if choice1 == “run”
puts “he’s faster than you!”
puts “he kills you and you return to the real world”
puts “sorry! no chips for you!”

elsif choice1 == “fight”
puts “really? fight a lion?”
puts “he kills you and you return to the real world”
puts “sorry! no chips for you!”

elsif choice1.include?”distract”
puts “Awesome! he’s looking the other way!”
forest_level_2
else
puts “i dunno what that means. try again”
forest_level_1
end
end

def forest_level_2
puts “you run and reach a river by a big tree. what do you do?”
puts “cry, use tree, or swim?”

choice2 = $stdin.gets.chomp

if choice2 == “cry”
puts “boohoo you cry baby!”
puts “no chips for you!”
elsif choice2 == “swim”
puts “you get eaten by a piranha!”
puts “no chips for you!”
elsif choice2.include?”tree”
puts “smart!, you cross to the other side!”
forest_level_3
else
puts “I dunno what that means. try again.”
forest_level_2
end
end

def forest_level_3
puts “now you are facing a canyon with a rope bridge. what do you do?”
puts “use bridge, do nothing or cry?”

choice3 = $stdin.gets.chomp

if choice3.include?”bridge”
puts “yay! you’re brave!”
puts “you’re back in the real world with your chips”
puts “bon appetite!”
elsif choice3.include?”nothing”
puts “you starve”
puts “no chips for you!”
exit(0)
elsif choice3.include?”cry”
puts “boohoo you cry baby!”
puts “you starve”
exit(0)
else
puts “i dunno what that means. try again.”
forest_level_3
end
end

def mad_king_level_1
puts “you find yourself in the throne room of a mad king.”
puts “entertain him or die!”
puts “sing ‘happy’, juggle or tell jokes?”

choice = $stdin.gets.chomp

if choice.include?”juggle”
puts “the king hates jugglers!”
puts “he kills you!”
exit (0)
elsif choice.include?”joke”
puts “you can’t think of any!”
puts “he’s pissed! he kills you!”

elsif choice.include?”sing”
puts “awesome! he’s singing along!”
mad_king_level_2
else
puts “i don’t get it. try again.”
mad_king_level_1
end
end

def mad_king_level_2
puts “now he’s hungry. what do you do?”
puts “cry, order pizza, or cook something?”

choice2 = $stdin.gets.chomp

if choice2 == “cry”
puts “boohoo you cry baby!”
puts “no candy for you!”
elsif choice2.include?”cook”
puts “you’re a bad cook”
puts “he kills you”
elsif choice2.include?”pizza”
puts “yummy!!”
puts “he says you can get your candy if you solve this riddle”
mad_king_level_3
else
puts “I don’t get it. try again”
end
end

def mad_king_level_3
puts “what goes around the world but stays in a corner?”

choice3 = $stdin.gets.chomp

if choice3 == “I don’t know”
puts “you’re his slave for ever now!”
elsif choice3.include?”stamp”
puts “old answer but still correct!”
puts “you’re back with your chips!”
puts “bon appetite!”
elsif choice3.include?”teenager”
puts “best answer!”
puts “you’re back with chips AND candy!”
puts “bon appetite!”
else
puts “wrong! you lose! he kills you!”
end
end

machine

Advertisements