Roulette / More Fun with Random!

Hello fellow Axurians!

We at Axure HQ are adding another game to the Fun with Random series, continuing with the legacy of other great games such as AxZee!, Grub Guess, Axure Quest VII, Spot the Difference, Something Monsters, and A Game of Cards. Now it’s time to test your luck with the classic casino game Roulette.

This version is pretty close to the standard roulette game. Start off by betting however much of your bank you are willing to risk. Then place your chips on whichever bet you think the ball will land on. The payout of red, black, odd, or even is 1 to 1. The payout of the 2 to 1 squares is, as you would expect, 2 to 1. And if you’re lucky enough to have the ball land on your number that pays out 35 to 1. Lastly all you need to do is spin the ball and hope you get lucky. Now give it a try and see how much you can win!

See it live!


Randomizing the spin
Each time the ball is spun a random number is generated using the expression below:

This expression generates a random number between 1 and 38. The Math.random function first generates a random number between the desired values then the Math.floor function turns that number into an integer. The generated number is then used to decide which position on the wheel the ball will land on, with 37 and 38 corresponding to the 0’s.

Spin Animation
The animation for the ball’s spin is done using a dynamic panel with each state being the next number on the wheel and the animation simply setting the dynamic panel to the next state. When the ball is spun it completes two revolutions, the first at high speed and the second at a slightly slower speed. After that the ball then begins to slow down as it approaches the random number. This is accomplished by a series of actions to increase the animation time as the the ball approaches its section. The wheel is divided into four parts and the actions are timed so that depending on the quadrant the random number is in the ball will slow as it approaches that section.

Here is what the spin slow down interaction looks like:

The ball stops at its final location due to an interaction on the dynamic panel that is activated once the StopTime variable is set to 1. At that point the ball will continue to spin at 200 ms while the dynamic panel checks if the panel state and the random number are the same and if that is true it stops the animation. As is shown here:

The bank value is tracked using a global variable that is updated after the completion of each spin. When the chips are placed on the betting table a Bet global variable is set with the location of the bet. After the completion of a spin an interaction is fired to determine the Landed global variables. For example if the random number generated is 21 then the LandedColor variable is set to red and the LandedOddEven variable is set to Odd. The final interaction compares the Landed variables to the Bet variables and if any Bet variable is equal to a Landed variable the bet amount is multiplied by the payout and added to the Bank variable.

Now you understand how it all works so load up a game and test your luck!

If you would like to take a closer look at how it all works you can download the project here:
Game.rp (1.8 MB)

1 Like