Be1uga 2025. 6. 10. 13:45
<?php
$items = [];

if ($_SERVER["REQUEST_METHOD"] === "POST") {
    $count = intval($_POST["count"] ?? 0);
    $items = array_map('trim', array_slice($_POST["items"] ?? [], 0, $count));
}
?>
<!DOCTYPE html>
<html lang="ko">
<head>
    <meta charset="UTF-8">
    <title>ํ…์ŠคํŠธ ๋ฝ‘๊ธฐ</title>
    <style>
        @font-face {
            font-family: 'NanumSquare';
            src: url('/data/font/NanumSquareR.ttf') format('truetype');
        }
        body {
            background: #f9f9f9;
            font-family: 'NanumSquare', sans-serif;
            text-align: center;
            padding: 50px;
        }
        h1 {
            font-size: 48px;
        }
        #resultDisplay {
            font-size: 56px;
            margin-top: 40px;
            height: 80px;
            font-weight: bold;
            transition: all 0.2s ease-in-out;
        }
        #resultDisplay.running {
            animation: shake 0.1s infinite;
            color: #2980b9;
        }
        #resultFinal {
            font-size: 52px;
            margin-top: 30px;
            color: #e74c3c;
            font-weight: bold;
        }
        button {
            font-size: 40px;
            padding: 20px 50px;
            margin: 20px;
            border: none;
            border-radius: 8px;
            cursor: pointer;
            background-color: #2980b9;
            color: white;
        }
        input[type="number"], input[type="text"] {
            font-size: 38px;
            padding: 10px;
            margin: 12px 0;
        }
        label {
            font-size: 38px;
            display: inline-block;
            width: 200px;
            text-align: right;
            margin-right: 20px;
        }
        form {
            margin-top: 40px;
        }

        @keyframes shake {
            0%   { transform: translateX(-2px); }
            50%  { transform: translateX(2px); }
            100% { transform: translateX(-2px); }
        }
    </style>
</head>
<body>

<h1>๐ŸŽฒ ํ…์ŠคํŠธ ๋žœ๋ค ๋ฝ‘๊ธฐ</h1>

<?php if (empty($items)): ?>
    <?php if (!isset($_POST["count"])): ?>
        <form method="post">
            <label>ํ•ญ๋ชฉ ์ˆ˜:</label>
            <input type="number" name="count" min="2" max="20" required>
            <br>
            <button type="submit">๋‹ค์Œ</button>
        </form>
    <?php else: ?>
        <form method="post">
            <input type="hidden" name="count" value="<?= intval($_POST["count"]) ?>">
            <?php for ($i = 0; $i < intval($_POST["count"]); $i++): ?>
                <label>ํ•ญ๋ชฉ <?= $i+1 ?>:</label>
                <input type="text" name="items[]" required><br>
            <?php endfor; ?>
            <button type="submit">์‹œ์ž‘ํ•˜๊ธฐ</button>
        </form>
    <?php endif; ?>
<?php else: ?>

    <div id="resultDisplay">???</div>
    <div>
        <button id="toggleBtn">๋Œ๋ฆฌ๊ธฐ</button>
    </div>
    <div id="resultFinal"></div>

    <script>
        const items = <?= json_encode($items, JSON_UNESCAPED_UNICODE) ?>;
        const display = document.getElementById("resultDisplay");
        const final = document.getElementById("resultFinal");
        const toggleBtn = document.getElementById("toggleBtn");

        let interval = null;

        toggleBtn.addEventListener("click", () => {
            if (!interval) {
                // ์‹œ์ž‘
                final.textContent = "";
                toggleBtn.textContent = "๋ฉˆ์ถค";
                display.classList.add("running");
                interval = setInterval(() => {
                    const rand = items[Math.floor(Math.random() * items.length)];
                    display.textContent = rand;
                }, 10);
            } else {
                // ๋ฉˆ์ถค
                clearInterval(interval);
                interval = null;
                toggleBtn.textContent = "๋Œ๋ฆฌ๊ธฐ";
                display.classList.remove("running");
                final.textContent = "๐ŸŽ‰ ๋‹น์ฒจ!! โ†’ " + display.textContent;
            }
        });
    </script>

<?php endif; ?>
</body>
</html>