Skip to content

Instantly share code, notes, and snippets.

@dvoryankin
Created September 4, 2016 16:04
Show Gist options
  • Save dvoryankin/46d7a236084893ec73fb2e787603d589 to your computer and use it in GitHub Desktop.
Save dvoryankin/46d7a236084893ec73fb2e787603d589 to your computer and use it in GitHub Desktop.
English version
print "How old are you? "
age = gets.to_i
print "Continue? (Y/N) "
answer = gets.strip.capitalize
if answer == "Y" && age >= 18
puts "Ok, let's play!"
money = 100
add_money_proc = lambda { |sum, money|
puts "You earned #{sum} dollars"
money + sum
}
sub_money_proc = lambda { |sum, money|
puts "You lost #{sum} dollars"
money - sum
}
actions =
{
"000" => lambda { |money|
puts "You loose!"
0
},
"111" => [10, add_money_proc],
"222" => [20, add_money_proc],
"333" => [30, add_money_proc],
"444" => [40, add_money_proc],
"555" => [50, add_money_proc],
"666" => lambda { |money|
puts "You lost half of your money"
money / 2
},
"777" => [70, sub_money_proc],
"888" => [80, sub_money_proc],
"999" => [90, sub_money_proc],
"123" => [123, sub_money_proc],
}
1000.times do
puts "Press Enter to play"
gets
num = rand(0..9).to_s + rand(0..9).to_s + rand(0..9).to_s
puts "Your combination is #{num}"
if actions.has_key?(num)
if actions[num].is_a?(Array)
money = actions[num][1].call(actions[num][0], money)
elsif actions[num].is_a?(Proc)
money = actions[num].call(money)
end
end
puts "Your money: #{money} dollars"
if money == 0
puts "Your money is over"
break
elsif money < 0
puts "See you next time"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment