Skip to content

Instantly share code, notes, and snippets.

@krokrob
Created October 14, 2019 12:56
Show Gist options
  • Save krokrob/51837ff96f192344db67801c6e8e38a8 to your computer and use it in GitHub Desktop.
Save krokrob/51837ff96f192344db67801c6e8e38a8 to your computer and use it in GitHub Desktop.
require_relative 'race'
# interface.rb
# Pseudo-code:
# 1. Print welcome
puts "๐Ÿ‡" * 10
puts "๐Ÿ‡ RAPIDO ๐Ÿ‡"
puts "๐Ÿ‡" * 10
# define horses names in an array
horses = [
'Tempete du Desert',
'Jolly Jumper',
'Hermes',
'Hercules',
'Tornade'
]
# iterate through the array and display number and name
# 1 - Tempete du desert
# 2 - Jolly Jumper
# 3 - Hermes
# 4 - Tornade
# 5 - Hercules
display_list(horses)
# 2. Get user's bet
# ask user's bet
puts "What's your bet?"
print '> '
# get horse number
horse_number = gets.chomp.to_i
# get horse name with its index
horse_index = horse_number - 1
bet = horses[horse_index]
puts bet
# 3. Run the race ๐Ÿด
# repeat 4 times with a loop
mixed_horses = []
4.times do |lap|
sleep 3
# during 1 lap:
# mix horses in the array
# store mixed array
mixed_horses = horses.shuffle
# iterate through the mixed array to display the intermediate order
puts "Lap #{lap + 1}, here is the order:"
display_list(mixed_horses)
puts
end
# 4. Print results
# get first element of the final mixed array
winner = mixed_horses.first
# compare with user's bet
if winner == bet
# display if user wins or not
puts "You win!"
else
puts "Try again!"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment