Skip to content

Instantly share code, notes, and snippets.

@davidpaulhunt
Last active August 29, 2015 13:57
Show Gist options
  • Save davidpaulhunt/9921606 to your computer and use it in GitHub Desktop.
Save davidpaulhunt/9921606 to your computer and use it in GitHub Desktop.
def get_users_name
puts "Hi! Welcome to the psychic personality machine."
puts "First, tell me your name: "
@name = gets.chomp
@name.capitalize!
@first_name = @name
puts "\n\nAwesome #{@name}, nice to meet you!"
puts "Let's get started."
end
def ask_the_user_questions
puts "\nTell me about yourself.\n"
@questions.each do |a, b|
puts "\n\n"
puts b
@answers[a] = gets.chomp
end
end
def display_users_resluts
puts "Good job #{@name}, for only being #{@answers[:age]} years old you have a big personality. You're #{@power}, even for someone from #{@from} with #{@family} brothers and sisters. #{@have_langs} #{@music} #{@locale} #{@visit} #{@material} #{@animals}\n"
end
def add_user_to_all_users
@ary = {name: @name, score: @score}
@all_users.push(@ary)
end
def ask_for_next_user
puts "\nReady for your friend to go, too? Yes or No"
@go_ahead = gets.chomp
end
def calculate_the_score
@win_score = -100
if @all_users.length > 1
@winner = ""
@all_users.each do |a|
if a[:score] > @win_score
@win_score = a[:score]
@winner = a[:name]
end
end
end
end
def show_winner
if @win_score > 0 && @all_users.length > 1
puts "\n\nLooks like #{@winner} is the better person with an awesome score of #{@win_score}!"
puts "Thanks for playing everyone!"
elsif @all_users.length == 1
puts"\n\nLooks like you win! But maybe you should get off the computer and go out to meet some friends!\n"
else
puts "\n\nNo one wins since these scores are all terrible!"
end
end
#create variables for the hashes
@power = ""
@from = ""
@age = 0
@langs = 0
@animals = ""
@family = ""
@visit = ""
@material = ""
@locale = ""
@music = ""
#array for saving?
@all_users = []
# question & answer hashes
@questions = {
power: "Would you rather be:\n\na. invisible\nb. super strong\nc. fast as lightning\nd. a potato",
from: "Are you from the:\n\na. east coast\nb. west coast\nc. somewhere in between",
age: "How old are you?",
langs: "How many languages do you speak?",
animals: "Do you like animals that are:\n\na. furry\nb. fishy\nc. feathery\nd. i hate animals",
family: "How many siblings do you have?",
visit: "Where would you rather visit?\n\na. Paris\nb. the Bahamas\nc. Australia\nd. I'd rather stay home",
material: "What's more important to you?\n\na. money\nb. family\nc. the environment\nd. I only care about myself",
locale: "You prefer the:\n\na. city\nb. country\nc. beach\nd. my couch",
music: "Your iTunes is full of:\n\na. country music\nb. hip hop\nc. rock'n'roll\nd. a little bit of everything"
}
@answers = {
power: @power,
from: @from,
age: @age,
langs: @langs,
animals: @animals,
family: @family,
visit: @visit,
material: @material,
locale: @locale,
music: @music
}
#sentinel var
@go_ahead = "yes"
@count = 0
while @go_ahead.downcase == "yes"
@score = 0
@count += 1
@first_name = ""
get_users_name
ask_the_user_questions
#convert answers to usable strings
@answers[:power].downcase == "a" ? @power = "shy" : @power = "outgoing"
@power == "shy" ? @score -= 1 : @score += 3
@answers[:animals].downcase == "c" ? @animals = "Everyone likes animals, you're a monster!" : @animals = "You're all about the creatures of the earth, or at least treat your pets like real friends."
@answers[:animals].downcase == "c" ? @score -= 2 : @score += 1
case @answers[:visit].downcase
when "a"
@visit = "Seems to me you may care a lot about beautiful things, or at least art or architecture."
@score += 1
when "b"
@visit = "You must enjoy the surf and sun, maybe keeping fit, yeah?"
@score += 2
when "c"
@visit = "Well mate, you're the kind of person that enjoys the outdoors and new, interesting places."
@score += 3
else
@visit = "You can be quite boring, though."
@score -= 5
end
if @answers[:material].downcase == "a" || @answers[:material].downcase == "d"
@material = "And calling you selfish might be an understatement, and your \"friends\" may not be a #{@name} fan."
@score -= 5
else
@material = "You're the type to care about people and things other than yourself, like your community, and base decisions on their best interest."
@score += 4
end
@answers[:locale].downcase == "d" ? @locale = "You should try to exercise more, you're looking a little lazy." : "You're likely active and enjoy doing things other than sitting around watching tv."
@answers[:locale].downcase == "d" ? @score -= 2 : @score += 2
@answers[:music].downcase == "d" ? @music = "Having choices is important to you and variety in your life keeps it fresh." : "Seems like you're a little close minded, or at least you stick to what you enjoy and prefer being comfortable."
@answers[:music].downcase == "d" ? @score += 1 : @score -= 2
case @answers[:from].downcase
when "a"
@from = "the east coast"
when "b"
@from = "the west coast"
else
@from = "the middle of nowhere"
end
@family = @answers[:family]
@langs_num = @answers[:langs].to_i
if @langs_num > 1
@have_langs = "You're intelligent and are pretty darn good at problem solving."
@score += 1
else
@have_langs = "Problem solving can be challenging, but you seem to find a way to get it done."
@score -= 1
end
#line breaks
puts "\n\n"
display_users_resluts
add_user_to_all_users
ask_for_next_user
end
calculate_the_score
show_winner
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment