打地鼠游戏代码!Claude Sonnet 4 生成

图片[1]-打地鼠游戏代码!Claude Sonnet 4 生成-零度博客

图片[2]-打地鼠游戏代码!Claude Sonnet 4 生成-零度博客

图片[3]-打地鼠游戏代码!Claude Sonnet 4 生成-零度博客

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>打地鼠游戏</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Comic Sans MS', cursive;
            background: linear-gradient(45deg, #87CEEB, #98FB98);
            min-height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            overflow: hidden;
        }

        .game-container {
            background: rgba(255, 255, 255, 0.9);
            border-radius: 20px;
            padding: 20px;
            box-shadow: 0 10px 30px rgba(0,0,0,0.3);
            text-align: center;
            backdrop-filter: blur(10px);
        }

        .game-header {
            margin-bottom: 20px;
        }

        .game-title {
            font-size: 2.5em;
            color: #2c3e50;
            text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
            margin-bottom: 10px;
            animation: bounce 2s infinite;
        }

        @keyframes bounce {
            0%, 20%, 50%, 80%, 100% { transform: translateY(0); }
            40% { transform: translateY(-10px); }
            60% { transform: translateY(-5px); }
        }

        .game-stats {
            display: flex;
            justify-content: space-around;
            margin-bottom: 20px;
            font-size: 1.2em;
            font-weight: bold;
        }

        .stat {
            background: linear-gradient(45deg, #FF6B6B, #4ECDC4);
            color: white;
            padding: 10px 20px;
            border-radius: 15px;
            box-shadow: 0 4px 8px rgba(0,0,0,0.2);
        }

        .game-board {
            display: grid;
            grid-template-columns: repeat(3, 120px);
            grid-template-rows: repeat(3, 120px);
            gap: 15px;
            justify-content: center;
            margin: 20px 0;
        }

        .hole {
            position: relative;
            width: 120px;
            height: 120px;
            background: radial-gradient(circle, #8B4513 0%, #654321 70%, #3c2415 100%);
            border-radius: 50%;
            overflow: hidden;
            cursor: pointer;
            box-shadow: inset 0 5px 15px rgba(0,0,0,0.5);
            transition: transform 0.1s;
        }

        .hole:active {
            transform: scale(0.95);
        }

        .mole {
            position: absolute;
            bottom: -80px;
            left: 50%;
            transform: translateX(-50%);
            width: 80px;
            height: 80px;
            background: linear-gradient(45deg, #D2691E, #CD853F);
            border-radius: 50% 50% 40% 40%;
            transition: bottom 0.3s ease-in-out;
            cursor: pointer;
        }

        .mole::before {
            content: '';
            position: absolute;
            top: 15px;
            left: 20px;
            width: 12px;
            height: 12px;
            background: #000;
            border-radius: 50%;
            box-shadow: 25px 0 0 #000;
        }

        .mole::after {
            content: '';
            position: absolute;
            top: 35px;
            left: 35px;
            width: 10px;
            height: 8px;
            background: #FF69B4;
            border-radius: 50%;
        }

        .mole.up {
            bottom: 20px;
            animation: wiggle 0.5s ease-in-out infinite;
        }

        .mole.hit {
            animation: hit 0.3s ease-out;
        }

        @keyframes wiggle {
            0%, 100% { transform: translateX(-50%) rotate(-5deg); }
            50% { transform: translateX(-50%) rotate(5deg); }
        }

        @keyframes hit {
            0% { transform: translateX(-50%) scale(1); }
            50% { transform: translateX(-50%) scale(1.2) rotate(15deg); }
            100% { transform: translateX(-50%) scale(0.8); bottom: -80px; }
        }

        .controls {
            margin-top: 20px;
        }

        .btn {
            background: linear-gradient(45deg, #FF6B6B, #4ECDC4);
            color: white;
            border: none;
            padding: 15px 30px;
            border-radius: 25px;
            font-size: 1.1em;
            font-weight: bold;
            cursor: pointer;
            box-shadow: 0 4px 15px rgba(0,0,0,0.2);
            transition: all 0.3s;
            margin: 0 10px;
        }

        .btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 6px 20px rgba(0,0,0,0.3);
        }

        .btn:active {
            transform: translateY(0);
        }

        .btn:disabled {
            background: #ccc;
            cursor: not-allowed;
            transform: none;
        }

        .game-over {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0,0,0,0.8);
            display: none;
            justify-content: center;
            align-items: center;
            z-index: 1000;
        }

        .game-over-content {
            background: white;
            padding: 40px;
            border-radius: 20px;
            text-align: center;
            box-shadow: 0 10px 30px rgba(0,0,0,0.5);
        }

        .game-over h2 {
            color: #2c3e50;
            font-size: 2em;
            margin-bottom: 20px;
        }

        .final-score {
            font-size: 1.5em;
            color: #e74c3c;
            margin-bottom: 20px;
        }

        .score-popup {
            position: absolute;
            color: #e74c3c;
            font-size: 2em;
            font-weight: bold;
            pointer-events: none;
            animation: scoreFloat 1s ease-out forwards;
        }

        @keyframes scoreFloat {
            0% { transform: translateY(0) scale(1); opacity: 1; }
            100% { transform: translateY(-50px) scale(1.2); opacity: 0; }
        }

        .miss-popup {
            position: absolute;
            color: #3498db;
            font-size: 1.5em;
            font-weight: bold;
            pointer-events: none;
            animation: scoreFloat 1s ease-out forwards;
        }

        .clouds {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            pointer-events: none;
            z-index: -1;
        }

        .cloud {
            position: absolute;
            background: rgba(255, 255, 255, 0.8);
            border-radius: 50px;
            animation: float 20s infinite linear;
        }

        .cloud::before,
        .cloud::after {
            content: '';
            position: absolute;
            background: rgba(255, 255, 255, 0.8);
            border-radius: 50px;
        }

        .cloud1 {
            width: 100px;
            height: 40px;
            top: 20%;
            animation-duration: 25s;
        }

        .cloud1::before {
            width: 50px;
            height: 40px;
            top: -20px;
            left: 10px;
        }

        .cloud1::after {
            width: 60px;
            height: 20px;
            top: -10px;
            right: 10px;
        }

        .cloud2 {
            width: 80px;
            height: 30px;
            top: 60%;
            animation-duration: 30s;
            animation-delay: -10s;
        }

        .cloud2::before {
            width: 40px;
            height: 30px;
            top: -15px;
            left: 15px;
        }

        .cloud2::after {
            width: 50px;
            height: 15px;
            top: -8px;
            right: 15px;
        }

        @keyframes float {
            0% { left: -120px; }
            100% { left: 100%; }
        }
    </style>
</head>
<body>
    <div class="clouds">
        <div class="cloud cloud1"></div>
        <div class="cloud cloud2"></div>
    </div>

    <div class="game-container">
        <div class="game-header">
            <h1 class="game-title">🔨 打地鼠大作战 🐹</h1>
            <div class="game-stats">
                <div class="stat">得分: <span id="score">0</span></div>
                <div class="stat">时间: <span id="time">60</span>s</div>
                <div class="stat">连击: <span id="combo">0</span></div>
            </div>
        </div>

        <div class="game-board" id="gameBoard">
            <!-- 9个洞口 -->
        </div>

        <div class="controls">
            <button class="btn" id="startBtn">开始游戏</button>
            <button class="btn" id="pauseBtn" disabled>暂停</button>
            <button class="btn" id="resetBtn">重置</button>
        </div>
    </div>

    <div class="game-over" id="gameOver">
        <div class="game-over-content">
            <h2>🎉 游戏结束 🎉</h2>
            <div class="final-score">最终得分: <span id="finalScore">0</span></div>
            <div>最高连击: <span id="maxCombo">0</span></div>
            <br>
            <button class="btn" onclick="restartGame()">再来一局</button>
        </div>
    </div>

    <script>
        class WhackAMoleGame {
            constructor() {
                this.score = 0;
                this.timeLeft = 60;
                this.combo = 0;
                this.maxCombo = 0;
                this.isPlaying = false;
                this.isPaused = false;
                this.gameTimer = null;
                this.moleTimer = null;
                this.difficulty = 1;
                this.holes = [];
                
                this.initGame();
                this.bindEvents();
            }

            initGame() {
                const gameBoard = document.getElementById('gameBoard');
                gameBoard.innerHTML = '';
                
                // 创建9个洞口
                for (let i = 0; i < 9; i++) {
                    const hole = document.createElement('div');
                    hole.className = 'hole';
                    hole.innerHTML = '<div class="mole" data-hole="' + i + '"></div>';
                    gameBoard.appendChild(hole);
                    this.holes.push(hole);
                }
            }

            bindEvents() {
                document.getElementById('startBtn').addEventListener('click', () => this.startGame());
                document.getElementById('pauseBtn').addEventListener('click', () => this.pauseGame());
                document.getElementById('resetBtn').addEventListener('click', () => this.resetGame());
                
                // 绑定地鼠点击事件
                document.addEventListener('click', (e) => {
                    if (e.target.classList.contains('mole') && e.target.classList.contains('up')) {
                        this.hitMole(e.target);
                    } else if (this.isPlaying && !this.isPaused) {
                        this.miss(e);
                    }
                });
            }

            startGame() {
                this.isPlaying = true;
                this.isPaused = false;
                this.score = 0;
                this.timeLeft = 60;
                this.combo = 0;
                this.maxCombo = 0;
                this.difficulty = 1;
                
                this.updateDisplay();
                
                document.getElementById('startBtn').disabled = true;
                document.getElementById('pauseBtn').disabled = false;
                
                this.startTimer();
                this.spawnMole();
            }

            pauseGame() {
                if (this.isPaused) {
                    this.isPaused = false;
                    document.getElementById('pauseBtn').textContent = '暂停';
                    this.startTimer();
                    this.spawnMole();
                } else {
                    this.isPaused = true;
                    document.getElementById('pauseBtn').textContent = '继续';
                    clearInterval(this.gameTimer);
                    clearTimeout(this.moleTimer);
                }
            }

            resetGame() {
                this.isPlaying = false;
                this.isPaused = false;
                clearInterval(this.gameTimer);
                clearTimeout(this.moleTimer);
                
                this.score = 0;
                this.timeLeft = 60;
                this.combo = 0;
                this.maxCombo = 0;
                
                this.updateDisplay();
                this.hideAllMoles();
                
                document.getElementById('startBtn').disabled = false;
                document.getElementById('pauseBtn').disabled = true;
                document.getElementById('pauseBtn').textContent = '暂停';
                document.getElementById('gameOver').style.display = 'none';
            }

            startTimer() {
                this.gameTimer = setInterval(() => {
                    this.timeLeft--;
                    this.updateDisplay();
                    
                    if (this.timeLeft <= 0) {
                        this.endGame();
                    }
                    
                    // 随着时间推移增加难度
                    if (this.timeLeft % 15 === 0 && this.timeLeft > 0) {
                        this.difficulty += 0.2;
                    }
                }, 1000);
            }

            spawnMole() {
                if (!this.isPlaying || this.isPaused) return;
                
                const randomHole = Math.floor(Math.random() * 9);
                const mole = this.holes[randomHole].querySelector('.mole');
                
                if (!mole.classList.contains('up')) {
                    mole.classList.add('up');
                    
                    // 地鼠停留时间随难度降低
                    const stayTime = Math.max(800 - (this.difficulty * 100), 400);
                    
                    setTimeout(() => {
                        if (mole.classList.contains('up')) {
                            mole.classList.remove('up');
                            this.combo = 0; // 地鼠自动消失时重置连击
                            this.updateDisplay();
                        }
                    }, stayTime);
                }
                
                // 下次地鼠出现时间随难度降低
                const nextSpawn = Math.max(1200 - (this.difficulty * 150), 600);
                this.moleTimer = setTimeout(() => this.spawnMole(), nextSpawn);
            }

            hitMole(mole) {
                if (!this.isPlaying || this.isPaused) return;
                
                mole.classList.remove('up');
                mole.classList.add('hit');
                
                this.combo++;
                this.maxCombo = Math.max(this.maxCombo, this.combo);
                
                // 连击加分
                const baseScore = 10;
                const comboBonus = Math.floor(this.combo / 3) * 5;
                const scoreGain = baseScore + comboBonus;
                
                this.score += scoreGain;
                this.updateDisplay();
                
                // 显示得分动画
                this.showScorePopup(mole.parentElement, '+' + scoreGain);
                
                setTimeout(() => {
                    mole.classList.remove('hit');
                }, 300);
            }

            miss(e) {
                // 点击空白处,连击归零
                if (this.combo > 0) {
                    this.combo = 0;
                    this.updateDisplay();
                    this.showMissPopup(e, '连击断了!');
                }
            }

            showScorePopup(element, text) {
                const popup = document.createElement('div');
                popup.className = 'score-popup';
                popup.textContent = text;
                popup.style.left = '50%';
                popup.style.top = '50%';
                popup.style.transform = 'translate(-50%, -50%)';
                
                element.style.position = 'relative';
                element.appendChild(popup);
                
                setTimeout(() => {
                    if (popup.parentElement) {
                        popup.parentElement.removeChild(popup);
                    }
                }, 1000);
            }

            showMissPopup(e, text) {
                const popup = document.createElement('div');
                popup.className = 'miss-popup';
                popup.textContent = text;
                popup.style.left = e.clientX + 'px';
                popup.style.top = e.clientY + 'px';
                popup.style.position = 'fixed';
                
                document.body.appendChild(popup);
                
                setTimeout(() => {
                    if (popup.parentElement) {
                        popup.parentElement.removeChild(popup);
                    }
                }, 1000);
            }

            hideAllMoles() {
                this.holes.forEach(hole => {
                    const mole = hole.querySelector('.mole');
                    mole.classList.remove('up', 'hit');
                });
            }

            updateDisplay() {
                document.getElementById('score').textContent = this.score;
                document.getElementById('time').textContent = this.timeLeft;
                document.getElementById('combo').textContent = this.combo;
            }

            endGame() {
                this.isPlaying = false;
                clearInterval(this.gameTimer);
                clearTimeout(this.moleTimer);
                
                this.hideAllMoles();
                
                document.getElementById('finalScore').textContent = this.score;
                document.getElementById('maxCombo').textContent = this.maxCombo;
                document.getElementById('gameOver').style.display = 'flex';
                
                document.getElementById('startBtn').disabled = false;
                document.getElementById('pauseBtn').disabled = true;
            }
        }

        // 初始化游戏
        const game = new WhackAMoleGame();

        function restartGame() {
            document.getElementById('gameOver').style.display = 'none';
            game.startGame();
        }
    </script>
</body>
</html>
THE END
喜欢就支持一下吧
点赞1678 分享
相关推荐
美颜相机APP一网打尽!瘦身、变脸、美肤免费用!-零度博客

美颜相机APP一网打尽!瘦身、变脸、美肤免费用!

  1.美颜相机:【点击下载】 2.FaceU:【点击下载】 3.轻颜:【点击下载】 4.B612相机:【点击下载】 5.黄油美颜:【点击下载】
admin的头像-零度博客admin
1.4W+1527
Telegram 最新版下载!配合安全设置保证电报不被黑-零度博客

Telegram 最新版下载!配合安全设置保证电报不被黑

  1.Telegram 官方网站:【链接直达】2.最新版下载:【点击前往】3.网盘下载:【点击前往】【注意】:虽然官方提供了最新版的Telegram的下载,但是未曾说明已修复了高危漏洞,所以建议大家在...
admin的头像-零度博客admin
1.5W+1530
2021年真正强大、最值得推荐的的视频播放器!(全平台)-零度博客

2021年真正强大、最值得推荐的的视频播放器!(全平台)

1.MacOS最强视频播放器 IINA:https://iina.io 2.Windows系统上最好用的视频播放器 PotPlayer:https://potplayer.daum.net VLC:https://www.videolan.org KMPlayer:https://www.kmplayer.com 3.A...
隐私政策-零度博客

隐私政策

零度博客非常重视您的隐私和您对我们的信任。本隐私政策介绍了我们如何收集、使用和披露信息。 1. 关于本隐私政策 本隐私政策适用于您访问或使用我们的网站、应用程序和其他服务的活动,包括参...
admin的头像-零度博客admin
1.7W+1682
疯狂游戏的真实体验! 制作流程和教程-零度博客

疯狂游戏的真实体验! 制作流程和教程

第1套: 电路 GITHUB代码 【下载码】   第2套: 从游戏中读取马的正确速度 通过串口向Arduino发送速度数据 使用速度数据控制气缸 脚步 使用此处的教程创建 MOD:https : //youtu.be/4rzi...
admin的头像-零度博客admin
1.5W+2251
免费使用GPT-4 的3种方法! 一分钱不花,白嫖 ChatGPT 专业版、DALL·E 3、GPT-4 Turbo等大模型 | 零度解说-零度博客

免费使用GPT-4 的3种方法! 一分钱不花,白嫖 ChatGPT 专业版、DALL·E 3、GPT-4 Turbo等大模型 | 零度解说

https://youtu.be/lJZ8vUvD6D0 ------------------------------------- 🔔 1.Coze AI 注册地址:https://www.freedidi.com/12085.html 2.Microsoft Copilot :https://www.freedidi.com/12091.h...
admin的头像-零度博客admin
1.5W+1528
手机远程连接Windows 电脑 客户端下载-零度博客

手机远程连接Windows 电脑 客户端下载

  1.动态域名:https://www.dynu.com 2.端口映射  3.手机客户端:【安卓版】 【 iOS版】
admin的头像-零度博客admin
1.6W+2252
Proton 为Chrome、Edge、Firefox等浏览器提供免费VPN扩展,不限流量!-零度博客

Proton 为Chrome、Edge、Firefox等浏览器提供免费VPN扩展,不限流量!

  Proton VPN 是目前最受欢迎的虚拟专用网络服务之一,它发布了一个新的免费浏览器扩展,而之前一直将其作为付费福利。它适用于所有基于 Chromium 的浏览器,包括Google浏览器和微软 Edge ...
admin的头像-零度博客admin
15.8W+2229
如何找到 Windows 10 桌面上我的電腦-零度博客

如何找到 Windows 10 桌面上我的電腦

要開啟這個設定其實不難!我们只要在桌面上右鍵點選個人化就可以進行調整, 可以把資源回收桶、控制台、使用者文件、網路呼叫出來,當然也可以全部再關閉不顯示, 接下來就讓我們看看如何找回你...