Skip to content

Instantly share code, notes, and snippets.

@AnthonyBloomer
Created September 30, 2018 18:28
Show Gist options
  • Save AnthonyBloomer/86d3f484b501588c82e27db22bdfe780 to your computer and use it in GitHub Desktop.
Save AnthonyBloomer/86d3f484b501588c82e27db22bdfe780 to your computer and use it in GitHub Desktop.
require 'colorize'
progression = 0
jackpot = 16
milestones = {
4 => '€500',
8 => '€2,500',
12 => '€100,000',
16 => '€250,000'
}
valid_choices = ['h', 'higher', 'l', 'lower', 'cashout', 'c']
def cashout_value(milestones, progression)
if progression >= 4 && progression < 8
milestones[4]
elsif progression >= 8 && progression < 12
milestones[8]
elsif progression >= 12 && progression < 16
milesstones[12]
elsif progression == 16
milestones[16]
else
return 0
end
end
def has_reached_milestone(milestones, progression)
if milestones.key?(progression)
"Milestone reached: " + milestones[progression]
end
end
while progression < jackpot do
a = rand(1..15)
while true do
b = rand(1..15)
if b != a
break
end
end
puts "Generated number: %s" % a
while true do
puts "Higher or lower: ".blue
user_choice = gets.chomp.downcase
if ! valid_choices.include? user_choice
puts 'Invalid input.'
next
end
if (user_choice == 'higher' || user_choice == 'h') && b > a
progression += 1
puts "That's correct".green
puts has_reached_milestone(milestones, progression)
break
elsif (user_choice == 'lower' || user_choice == 'l') && b < a
progression += 1
puts "That's correct.".green
puts has_reached_milestone(milestones, progression)
break
elsif user_choice == 'cashout' || user_choice == 'c'
if progression < 4
puts "Haven't reached milestone."
next
end
cashout_value = cashout_value(milestones, progression)
puts "Cashed out with value of " + cashout_value.to_s
exit
else
puts "Incorrect.".red
if progression >= 4
cashout_value = cashout_value(milestones, progression)
puts "Cashed out with value of " + cashout_value.to_s
end
exit
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment