Skip to content

Instantly share code, notes, and snippets.

@nienkedekker
Created October 17, 2016 12:27
Show Gist options
  • Save nienkedekker/a5bba8408e9a4fe751fb8f145bc927f4 to your computer and use it in GitHub Desktop.
Save nienkedekker/a5bba8408e9a4fe751fb8f145bc927f4 to your computer and use it in GitHub Desktop.
# Found this on StackOverflow and it allows the use of colors within the Terminal (OSX, should work on Windows as well).
class String
def black; "\033[30m#{self}\033[0m" end
def red; "\033[31m#{self}\033[0m" end
def green; "\033[32m#{self}\033[0m" end
def brown; "\033[33m#{self}\033[0m" end
def blue; "\033[34m#{self}\033[0m" end
def magenta; "\033[35m#{self}\033[0m" end
def cyan; "\033[36m#{self}\033[0m" end
def gray; "\033[37m#{self}\033[0m" end
def bg_black; "\033[40m#{self}\033[0m" end
def bg_red; "\033[41m#{self}\033[0m" end
def bg_green; "\033[42m#{self}\033[0m" end
def bg_brown; "\033[43m#{self}\033[0m" end
def bg_blue; "\033[44m#{self}\033[0m" end
def bg_magenta; "\033[45m#{self}\033[0m" end
def bg_cyan; "\033[46m#{self}\033[0m" end
def bg_gray; "\033[47m#{self}\033[0m" end
def bold; "\033[1m#{self}\033[22m" end
def reverse_color; "\033[7m#{self}\033[27m" end
end
count = 0
# First, we have to peel the apples.
def peel_apples(count)
counter = 1
while counter < 2
puts "Peel apples..."
sleep 1
counter += 1
end
puts "------------------------------------------------------------------------"
puts "Done peeling the apples! ┗ (^∀^)┛ ".bg_magenta
puts "------------------------------------------------------------------------\n\n"
count += 1
what_to_do(count)
end
# Then we gotta chop the apples into chunks.
def chop_apples(count)
counter = 1
while counter < 2
puts "Chop apples.."
sleep 1
counter += 1
end
puts "------------------------------------------------------------------------"
puts "Done chopping the apples into chunks! ".bg_cyan
puts "------------------------------------------------------------------------\n\n"
count += 1
what_to_do(count)
end
# count is two
# Then we'll cover the chunks with SUGAR! At first I forgot the return here, which meant when the user input was larger than 5 it would start adding sugar again after the program had run its course.
def cover_chunks(count)
puts "How many tablespoons of sugar and cinnamon would you like to add?"
userinput = gets.chomp
if userinput.to_i > 5
puts "You can't add more than 5 tablespoons!\n\n"
what_to_do(count)
return
end
counter = 1
until counter > userinput.to_i
puts "Adding sugar and cinnamon.."
sleep 1
counter += 1
end
count += 1
if userinput.include? "1"
puts "------------------------------------------------------------------------"
puts "You added a just one tablespoon of sugar and cinnamon! ♡ ".bg_blue
puts "------------------------------------------------------------------------\n\n"
else
puts "------------------------------------------------------------------------"
puts "You added #{userinput} tablespoons of sugar and cinnamon! ♡ ".bg_green
puts "------------------------------------------------------------------------\n\n"
end
what_to_do(count)
end
# count is three
# Next up, make the dough.
def make_dough(count)
kneads = 5
loop do
kneads -= 1
puts "Making and kneading the dough...."
sleep 1
break if kneads == 0
end
puts "------------------------------------------------------------------------"
puts "Done making the dough! ≧ω≦ ".bg_magenta
puts "------------------------------------------------------------------------\n\n"
count += 1
what_to_do(count)
end
#count is four
# Pre-bake the dough. We don't want soggy apple pie.
def prebake(count)
minutes = 15
loop do
minutes -= 1
next if minutes % 5 != 0
puts "#{minutes} minutes left.."
puts "Smells good already!"
sleep 1
break if minutes == 0
end
puts "------------------------------------------------------------------------"
puts "Done pre-baking! (ؑ⸍⸍ᵕؑ̇⸍⸍)◞✧ ".black.bg_gray
puts "------------------------------------------------------------------------\n\n"
count += 1
what_to_do(count)
end
#count is five
# Adding the chopped apple to our par-baked dough.
def add_apple_to_dough(count)
chunks = [1, 2, 3, 4, 5, 6]
chunks.each do |chunk|
puts "Adding chunks.\n"
sleep 1
end
puts "Cover with some more sugar..\n"
sleep 1
puts "------------------------------------------------------------------------"
puts "Done with the preparations! ୧(﹒︠ᴗ﹒︡)୨ ".bg_brown
puts "------------------------------------------------------------------------\n\n"
count += 1
what_to_do(count)
end
#count is six
# Put it in the oven!
def bake(count)
minutes = 45
loop do
minutes -= 1
next if minutes % 5 != 0
puts "#{minutes} minutes left.."
puts "Not done yet!\n\n"
sleep 1.5
break if minutes == 0
end
puts "------------------------------------------------------------------------"
puts "Done baking! ".bg_cyan
puts "------------------------------------------------------------------------\n\n"
count += 1
what_to_do(count)
end
#count is seven
# We'll put it in the window sill to let it our pie cool.
def let_it_cool(count)
counter = 1
until counter == 2
puts "Put the pie in the window sill to let it cool!"
sleep 1
puts "Still cooling"
sleep 1
puts "Almost done.."
sleep 1
counter += 1
end
puts "------------------------------------------------------------------------"
puts "Done cooling and ready to eat! ♡♡ ♡ ".bg_blue
puts "------------------------------------------------------------------------\n\n"
count += 1
what_to_do(count)
end
#count is eight
# Now we can eat the pie!
def eat_the_pie(count)
counter = 1
until counter == 2
puts "We're cutting our first piece.."
sleep 1
puts "Put it onto a plate.."
sleep 1
puts "Take our first bite.."
sleep 1
counter += 1
end
puts "|-----------------------------------------------------------------------|".bg_cyan
puts "| IT'S SO GOOD! |".bg_cyan
puts "| bye-bye! |".bg_cyan
puts "| Ψ(≧ω≦)Ψ |".bg_cyan
puts "|-----------------------------------------------------------------------|".bg_cyan
count += 1
end
#count is eight
#Computer input
def welcome(count)
puts "\n\n\n\n"
puts "|--------------------------------------------------------------------|".bg_magenta
puts "| ヽ( ・∀・)ノ |".bg_magenta
puts "| LET'S BAKE AN APPLE PIE! |".black.bg_cyan
puts "| ヽ(´∀`ヽ) |".bg_magenta
puts "|--------------------------------------------------------------------|".bg_magenta
puts "\n\n"
end
def what_to_do(count)
puts "Type 'Go' for our preparation list!"
answer = gets.chomp
if answer.include? "go" or answer.include? "Go"
unless count < 0
puts "You can choose between the following:"
sleep 0.1
end
unless count > 0
puts "Peel the apples"
sleep 0.1
end
unless count > 1
puts "Chop the apples into chunks"
sleep 0.1
end
unless count > 2
puts "Cover the chunks with sugar"
sleep 0.1
end
unless count > 3
puts "Make the dough"
sleep 0.1
end
unless count > 4
puts "Pre-bake the dough"
sleep 0.1
end
unless count > 5
puts "Add apples to dough"
sleep 0.1
end
unless count > 6
puts "Put it in the oven"
sleep 0.1
end
unless count > 7
puts "Cool the pie"
sleep 0.1
end
unless count > 8
puts "EAT THE PIE!"
sleep 0.1
end
puts "Exit\n\n"
answer = gets.chomp
end
#Possible answers. Surely there must be a way to simplify this..
if answer.include? "peel" or answer.include? "peel the apples" or answer.include? "peeling" or answer.include? "peel apples" and count == 0
peel_apples(count)
elsif answer.include? "chop" or answer.include? "chop the apples" or answer.include? "chop apples" and count == 1
chop_apples(count)
elsif answer.include? "add sugar" or answer.include? "add sugar to chunks" or answer.include? "sugar" or answer.include? "cover with sugar" or answer.include? "cover" or answer.include? "cinnamon" or answer.include? "cover cinnamon" or answer.include? "cover with cinnamon and sugar" or answer.include? "cover with sugar and cinnamon" and count == 2
cover_chunks(count)
elsif answer.include? "make dough" or answer.include? "knead dough" or answer.include? "kneading" or answer.include? "create dough" or answer.include? "make the dough" or answer.include? "knead the dough" and count == 3
make_dough(count)
elsif answer.include? "prebake" or answer.include? "parbake" or answer.include? "pre-bake the dough" or answer.include? "prebake dough" or answer.include? "parbake the dough" or answer.include? "parbake dough" and count == 4
prebake(count)
elsif answer.include? "add apple to dough" or answer.include? "add the apples to the dough" or answer.include? "add apples" or answer.include? "add apples" or answer.include? "add apple" and count == 5
add_apple_to_dough(count)
elsif answer.include? "bake" or answer.include? "bake the pie" or answer.include? "bake pie" or answer.include? "bake the cake" or answer.include? "put the pie into the oven" or answer.include? "put in oven" or answer.include? "put in the oven" and count == 6
bake(count)
elsif answer.include? "let it cool" or answer.include? "cool down" or answer.include? "cool pie" or answer.include? "cool the pie" or answer.include? "cool" and count == 7
let_it_cool(count)
elsif answer.include? "eat" or answer.include? "eat the pie" or answer.include? "eat it" or answer.include? "eat pie" or answer.include? "nom nom" and count == 8
eat_the_pie(count)
elsif answer.include? "exit" or answer.include? "Exit"
exit
else
puts "That's not the right order! Try again. Type Go for available commands."
sleep 1
try_again(count)
end
end
def try_again(count)
what_to_do(count)
end
welcome(count)
what_to_do(count)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment