Skip to content

Instantly share code, notes, and snippets.

@awesomescott
Last active August 29, 2015 14:20
Show Gist options
  • Save awesomescott/9d60105debf4c9323fe1 to your computer and use it in GitHub Desktop.
Save awesomescott/9d60105debf4c9323fe1 to your computer and use it in GitHub Desktop.
require './zoltar_module'
require './zoltar_helper'
include ZoltarSpeaks
intro
greeting
shall_we
which_fortune
answer = promptd
if answer == sign
sign
else
crystal_ball
end
end_game
# This formats the paragraph, separating comments for clarity.
def format1
puts
puts "---------------"
puts
end
# This provides spacing between comments.
def format2(text)
puts
puts text
end
# This is what happens when the game ends.
def end_game
format1
puts "Would you like to play again? (Y/N)"
play_again = promptd
if play_again == "y"
format1
replay
elsif play_again == "n"
exit
else
format1
puts "Zoltar does not care for your response."
end_game
end
end
# This loops the game so it can be played repeatedly.
def replay
format1
which_fortune
answer = promptd
if answer == sign
sign
else
crystal_ball
end
end_game
end
# This takes input and downcases it.
def promptd
gets.chomp.downcase
end
# This takes input and upcases it.
def promptc
gets.chomp.capitalize
end
# This gets input for the purpose of the test.
def empty_variable(var)
if var == nil
promptd
else
var
end
end
# Zoltar speaks mysteriously
def say_something_mysterious
@remarks = [
"The spirits are strong today.",
"You have come at an auspicious time...",
"I've been expecting you.",
"My metaphysical wisdom is at your disposal."
]
top_index = @remarks.size - 1
@random_index = rand(0..top_index)
@remarks[@random_index]
end
# Generates random horoscope fortune.
def horoscope_fortune
@sign = [
"I am sorry, my child. I see misfortune in your fortune.",
"3 is your lucky number. Look out for it.",
"Yikes! You will be hit by a truck on your way out of here.",
"When the stars align it shall be your time. Don't miss it.",
"Love is right around the corner.",
"Some fortunes are better than others. This one's a dud."
]
top_index = @sign.size - 1
random_index = rand(0..top_index)
@sign[@random_index]
end
# Generates random crystal ball fortune.
def crystal_ball_fortune
@crystal_ball = [
"Heavy thoughts are weighing on you.",
"Zombies will attack you on the fortnight.",
"You'll win $1 million, but due to an error, it's in pennies.",
"Help! Zoltar is holding me hostage in this ball!",
"You'd be wise to stay away from Wall Street.",
"Only Tom Hanks gets to be Big."
]
top_index = @crystal_ball.size - 1
@random_index = rand(0..top_index)
@crystal_ball[@random_index]
end
require "./zoltar_helper"
#Zoltar Speaks
#This is a text adventure REPL game.
#The game begins at the table of the all knowing Zoltar.
module ZoltarSpeaks
# This sets the scene for the game and sets the game in motion.
def intro
format1
puts <<-HERE
You stumble through a strange door in order to escape a
sudden rain storm. You encounter a strange, bejeweled man
in a funny hat. As you try to get your bearings, he speaks...
HERE
end
# Zoltar introduces himself and says something mysterious
def greeting
format1
puts "Greetings, I am Zoltar. #{say_something_mysterious}"
end
# Zoltar asks if you wish to play.
def shall_we
puts "You wish to know your future, dont't you, my child."
format2 "Is this true? (Y/N)"
play = empty_variable(play)
if play == "n"
format1
puts "You do not seek the mighty wisdom of Zoltar?"
puts "You are wasting my time. Get out of here!"
format2
end_game
elsif play == "y"
format1
puts "Zoltar will tell you what you need to know."
else
format1
puts "Zoltar does not care for your response."
shall_we
end
end
# User chooses fortune type.
def which_fortune
format2 "Shall I read your Horoscope or would you rather"
puts "I peer into my Crystal Ball?"
format2 "Options: Horoscope, Crystal Ball"
answer = empty_variable(answer)
if answer == "horoscope"
format1
puts "Of course,my child."
sign
elsif answer == "crystal ball"
format1
puts "As you wish my child."
crystal_ball
else
format1
puts "Zoltar does not care for your response."
which_fortune
end
end
# This gets users astrological sign and gives Horoscope.
def sign
format2 "What is your astrological sign?"
astro_sign = promptc
if ["Aquarius","Aries","Cancer","Capricorn","Gemini",
"Leo","Libra","Pisces","Sagittarius","Scorpio","Taurus","Virgo"].include?(astro_sign)
format2 "#{horoscope_fortune}"
end_game
else
puts "Zoltar does not care for your response."
sign
end
end
# This gives Crystal Ball fortune.
def crystal_ball
puts "As I gaze into the infinite...what's this I see...?"
format2 "#{crystal_ball_fortune}"
end_game
end
end
require "./zoltar_module"
include ZoltarSpeaks
# This tests a successful user case.
def pass_test
play = "y"
answer = "crystal ball"
end
# This tests that users will be reprompted
#when errors are made.
def fail_test
play = "t"
answer = "horscope"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment