Created
January 18, 2025 20:53
-
-
Save svoboda-jan/cc4d675bac8a966038c8aeb0a495b3ad to your computer and use it in GitHub Desktop.
A dice betting game using Opal Ruby to Javascript source-to-source compiler with JS interaction
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Dice Betting Game, https://opalrb.com/try/ | |
require "native" | |
bank = 100; | |
while bank > 0 do | |
bet = $$.prompt("Place your bet").to_i | |
dice1 = (rand * 6).ceil | |
dice2 = (rand * 6).ceil | |
outcome = dice1 == dice2 | |
bank += bet if outcome | |
bank -= bet unless outcome | |
puts "Numbers are: #{dice1} #{dice2}" | |
puts outcome_txt = outcome ? "You Win" : "You Lose" | |
outcome_txt += ", bank is now #{bank}" | |
puts "Bank is now #{bank}" | |
$$.alert(outcome_txt) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment