Example: Slot Machine (with Lightbox)

#Example #Lightbox #Animation #concurrency #async #await #PromiseAll #Beer

Demonstrates

Links for this example

About this example

This example is a simple simulation of a Slot Machine. The user enters their name in the input field, and it’s passed to a Lightbox that opens to start the game. The user is greeted by name and is invited to play. Upon completion of a turn at the slot machine, the Lightbox is closed and the result of the game is returned to the Page .

As in a regular slot machine, three images that randomly “spin” determine the outcome of the game. Each image component has its own loop where the images are randomly alternated, and each new image is shown and hidden with randomly timed animation. A Promise.all waits for all three loops to finish and the result of the game can then be determined - if all three images are the same the user is a winner.

7 Likes

@yisrael-wix For President 2020 :tada::beers:

Hi @yisrael-wix !
Thanks for this !

I’m wondering if, when a logged user/member of a site play with this kind of game, the result could be saved in a “Member Profile Database” ?
For exemple, if the user win an immaterial gift (like ebook), the gift could be automatically added in his “Member Profile field” and so, the user could download it from his dashboard ?

Thanks for your answer,
Best regards,
Angeline

You can do whatever you want with results. If the user “wins”, you could save it in a collection of winners, or whatever else you want.