Untitled

mail@pastecode.io avatar
unknown
plain_text
5 months ago
8.5 kB
4
Indexable
<!DOCTYPE html>
<html>
<head>
    <title>Flawless Dice</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            text-align: center;
        }
        #numbers span {
            font-size: 1.5em;
            margin: 0 5px;
        }
        #dice {
            width: 100px;
            height: 100px;
            margin: 20px auto;
            display: flex;
            justify-content: center;
            align-items: center;
            font-size: 2em;
            background: lightgrey;
            border: 2px solid black;
            border-radius: 10px;
        }
        .rolled {
            color: green;
        }
        .duplicate {
            color: red;
        }
        .history-item {
            display: flex;
            justify-content: space-between;
            margin: 5px 0;
        }
    </style>
</head>
<body>
    <h1>Flawless Dice</h1>
    <p>Starting Balance: $<span id="balance">10000</span></p>
    <p>Bet Amount: $<input type="number" id="betAmount" min="1" max="10000" value="100"></p>
    <button id="placeBetButton">Place Bet</button>
    <button id="rollDiceButton" disabled>Roll Dice</button>
    <button id="cashOutButton" disabled>Cash Out</button>
    <button id="autoBetButton">Auto Bet</button>
    <p>Auto Bet Games Left: <span id="autoBetGamesLeft">0</span></p>

    <div id="dice">1</div>
    <div id="numbers">
        <span id="num1">1</span> <span id="num2">2</span> <span id="num3">3</span> <span id="num4">4</span> <span id="num5">5</span>
        <span id="num6">6</span> <span id="num7">7</span> <span id="num8">8</span> <span id="num9">9</span> <span id="num10">10</span>
    </div>

    <p>Potential Cash Out: $<span id="potentialCashOut">0</span></p>
    <p>Potential Next Roll Payout: $<span id="potentialNextRoll">0</span></p>

    <h2>Game History (last 10 games)</h2>
    <ul id="history"></ul>

    <script>
        let balance = 10000;
        let betAmount = 100;
        let gameHistory = [];
        let numbersRolled = new Set();
        let highestRoll = 0;
        let gameOver = false;
        let firstRoll = false;
        let autoBetInterval;
        let remainingAutoBets = 0;

        document.getElementById('placeBetButton').addEventListener('click', placeBet);
        document.getElementById('rollDiceButton').addEventListener('click', rollDice);
        document.getElementById('cashOutButton').addEventListener('click', cashOut);
        document.getElementById('autoBetButton').addEventListener('click', toggleAutoBet);

        function updateBalance() {
            document.getElementById('balance').innerText = balance;
        }

        function updateHistory(result) {
            gameHistory.unshift(result);
            if (gameHistory.length > 10) gameHistory.pop();
            document.getElementById('history').innerHTML = gameHistory.map(r => `<li class="history-item">${r}</li>`).join('');
        }

        function placeBet() {
            if (!gameOver && numbersRolled.size > 0) {
                alert("Finish the current game by rolling or cashing out.");
                return;
            }
            betAmount = parseInt(document.getElementById('betAmount').value);
            if (betAmount > balance) {
                alert("Insufficient balance!");
                return;
            }
            balance -= betAmount;
            updateBalance();
            numbersRolled.clear();
            highestRoll = 0;
            gameOver = false;
            firstRoll = false;
            document.querySelectorAll('#numbers span').forEach(span => span.classList.remove('rolled', 'duplicate'));
            document.getElementById('placeBetButton').disabled = true;
            document.getElementById('rollDiceButton').disabled = false;
            document.getElementById('cashOutButton').disabled = true;
            updatePotentialPayouts();
        }

        function rollDice() {
            if (gameOver) return;

            const roll = Math.floor(Math.random() * 10) + 1;
            document.getElementById('dice').innerText = roll;

            if (numbersRolled.has(roll)) {
                document.getElementById(`num${roll}`).classList.add('duplicate');
                gameOver = true;
                document.getElementById('cashOutButton').disabled = true;
                document.getElementById('placeBetButton').disabled = false;
                document.getElementById('rollDiceButton').disabled = true;
                updateHistory(`Lost $${betAmount} (failed at ${numbersRolled.size + 1} roll)`);
                return;
            }
            numbersRolled.add(roll);
            highestRoll = Math.max(highestRoll, roll);
            document.getElementById(`num${roll}`).classList.add('rolled');
            document.getElementById('cashOutButton').disabled = false;
            firstRoll = true;
            updatePotentialPayouts();
        }

        function cashOut() {
            if (gameOver || !firstRoll) return;

            if (numbersRolled.size === 1) {
                balance += betAmount; // return the bet amount if only one roll
                updateHistory(`Cashed out after 1 roll (no loss or gain)`);
            } else if (numbersRolled.size > 1) {
                const payout = calculatePayout(numbersRolled.size);
                balance += payout;
                updateBalance();
                updateHistory(`Won $${(payout - betAmount).toFixed(2)} with ${numbersRolled.size} unique rolls`);
            } else {
                updateHistory(`Lost $${betAmount} (no unique rolls)`);
            }
            gameOver = true;
            document.getElementById('placeBetButton').disabled = false;
            document.getElementById('rollDiceButton').disabled = true;
            document.getElementById('cashOutButton').disabled = true;
            updatePotentialPayouts();
        }

        function calculatePayout(n) {
            const payouts = [1.11, 1.39, 1.98, 3.31, 6.61, 16.54, 55.11, 275.6, 2756];
            return betAmount * payouts[n - 2];  // since payouts start from n=2
        }

        function updatePotentialPayouts() {
            const uniqueCount = numbersRolled.size;
            const potentialPayout = uniqueCount > 1 ? calculatePayout(uniqueCount) : 0;
            document.getElementById('potentialCashOut').innerText = potentialPayout.toFixed(2);
            const nextRollPayout = uniqueCount > 0 && uniqueCount < 10 ? calculatePayout(uniqueCount + 1) : 0;
            document.getElementById('potentialNextRoll').innerText = nextRollPayout.toFixed(2);
        }

        function toggleAutoBet() {
            if (remainingAutoBets > 0) {
                stopAutoBet();
            } else {
                const rollsPerTurn = parseInt(prompt("Enter the number of rolls per turn:"));
                const numberOfTurns = parseInt(prompt("Enter the number of turns to play:"));

                if (isNaN(rollsPerTurn) || isNaN(numberOfTurns) || rollsPerTurn <= 0 || numberOfTurns <= 0) {
                    alert("Please enter positive integers.");
                    return;
                }

                remainingAutoBets = numberOfTurns;
                document.getElementById('autoBetGamesLeft').innerText = remainingAutoBets;
                document.getElementById('autoBetButton').innerText = "Stop AutoBet";

                autoBetTurn(rollsPerTurn);
            }
        }

        function autoBetTurn(rollsPerTurn) {
            if (remainingAutoBets <= 0) {
                stopAutoBet();
                return;
            }

            placeBet();
            let currentRoll = 0;

            const autoRollInterval = setInterval(() => {
                if (gameOver || currentRoll >= rollsPerTurn) {
                    clearInterval(autoRollInterval);
                    cashOut();
                    remainingAutoBets--;
                    document.getElementById('autoBetGamesLeft').innerText = remainingAutoBets;
                    return autoBetTurn(rollsPerTurn);
                }
                rollDice();
                currentRoll++;
            }, 300);
        }

        function stopAutoBet() {
            clearInterval(autoBetInterval);
            remainingAutoBets = 0;
            document.getElementById('autoBetButton').innerText = "Auto Bet";
            document.getElementById('autoBetGamesLeft').innerText = 0;
        }
    </script>
</body>

</html>
Leave a Comment