Skip to content

Instantly share code, notes, and snippets.

@caioertai
Created January 28, 2019 21:38
Show Gist options
  • Save caioertai/8e7acd1d62e25e436094667354dceebd to your computer and use it in GitHub Desktop.
Save caioertai/8e7acd1d62e25e436094667354dceebd to your computer and use it in GitHub Desktop.
puts "--------------------------"
puts "Welcome to the horse race!"
puts "--------------------------"
horses = ['Caio Andrade', 'Eduardo', 'Marina', 'Lucas', 'Sveta']
loop_input = 'y'
while loop_input == 'y' do
puts "Here are our horses:"
horses.each_with_index do |horse, index|
puts "#{index + 1}. #{horse}"
end
puts "--------------------------"
puts "Pick a horse to bet on:"
print '> '
bet_index = gets.chomp.to_i - 1
user_horse = horses[bet_index]
winner = horses.sample
puts "And the winner is:"
sleep 0.4
puts "."
sleep 0.4
puts ".."
sleep 0.4
puts "..."
puts "#{winner}!!!"
if user_horse == winner
puts "Your horse won! Congrats to you and #{user_horse}!"
else
puts "#{user_horse} lost... Better luck next time!"
end
puts "-------------------------------"
puts "Do you want to bet again? (y/n)"
print '> '
loop_input = gets.chomp
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment