diff --git a/src/ui/src/Apps/Casino/index.tsx b/src/ui/src/Apps/Casino/index.tsx index 1b3aa28d2..569036fae 100644 --- a/src/ui/src/Apps/Casino/index.tsx +++ b/src/ui/src/Apps/Casino/index.tsx @@ -1,15 +1,72 @@ -import { useEffect } from 'react'; +import { useEffect, useState } from 'react'; import { TopNavigation } from '../../components/Navigation/TopNavigation'; +/** + * Add jackpot icon, and bar to the symbols array + */ +const symbols = ['🍒', '🍋', '🍊', '🍉', '🍇', '⭐', '🔔', '🎰', '🍀']; + +const getRandomSymbol = () => symbols[Math.floor(Math.random() * symbols.length)]; + +const useInterval = (callback: () => void, delay: number) => { + useEffect(() => { + const id = setInterval(callback, delay); + return () => clearInterval(id); + }, [callback, delay]); +}; + export const CasinoApp = () => { + const [reels, setReels] = useState([getRandomSymbol(), getRandomSymbol(), getRandomSymbol()]); + const [spinning, setSpinning] = useState(false); + const [winner, setWinner] = useState(false); + useEffect(() => { document.title = 'Casino'; }, []); + const spinReels = () => { + setSpinning(true); + setWinner(false); + setTimeout(() => { + const newReels = [getRandomSymbol(), getRandomSymbol(), getRandomSymbol()]; + setReels(newReels); + setSpinning(false); + checkWinner(newReels); + }, 1000); + }; + + useInterval(() => { + if (spinning) { + setReels([getRandomSymbol(), getRandomSymbol(), getRandomSymbol()]); + } + }, 100); + + const checkWinner = (reels: string[]) => { + if (reels[0] === reels[1] && reels[1] === reels[2]) { + setWinner(true); + } + }; + return (