打开/关闭搜索
搜索
打开/关闭菜单
933
1525
112
1.4万
植物大战僵尸杂交版Wiki
导航
首页
最近更改
随机页面
MediaWiki帮助
特殊页面
上传文件
打开/关闭外观设置菜单
notifications
打开/关闭个人菜单
未登录
未登录用户的IP地址会在进行任意编辑后公开展示。
user-interface-preferences
个人工具
创建账号
登录
查看“︁微件:ZombieGame”︁的源代码
来自植物大战僵尸杂交版Wiki
查看
阅读
查看源代码
查看历史
associated-pages
微件
讨论
更多操作
←
微件:ZombieGame
因为以下原因,您没有权限编辑该页面:
您请求的操作仅限属于该用户组的用户执行:
用户
您没有权限编辑
微件
命名空间内的页面。
您可以查看和复制此页面的源代码。
<includeonly> <style> .zombie-game { position: relative; width: 100%; max-width: 600px; height: 250px; background: #5a8f4a; border: 4px solid #3a5c2f; border-radius: 12px; overflow: hidden; margin: 20px auto; cursor: pointer; user-select: none; touch-action: manipulation; } .zombie-game .nut { position: absolute; bottom: 20px; left: 50px; width: 50px; height: 60px; background: #8B4513; border-radius: 10px 10px 0 0; transition: top 0.15s; display: flex; align-items: center; justify-content: center; font-size: 30px; } .zombie-game .nut.jumping { bottom: 80px; } .zombie-game .zombie { position: absolute; bottom: 20px; right: -50px; width: 40px; height: 60px; background: #4a4a4a; border-radius: 5px; display: flex; align-items: center; justify-content: center; font-size: 30px; } .zombie-game .score { position: absolute; top: 10px; right: 15px; font-size: 18px; font-weight: bold; color: #fff; text-shadow: 1px 1px 2px #000; } .zombie-game .game-over { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); font-size: 28px; font-weight: bold; color: #fff; text-shadow: 2px 2px 4px #000; display: none; text-align: center; line-height: 1.5; } .zombie-game .restart-btn { display: block; margin: 10px auto; padding: 8px 20px; font-size: 16px; background: #f44336; color: #fff; border: none; border-radius: 8px; cursor: pointer; } </style> <div class="zombie-game" id="zombie-game"> <div class="nut" id="nut">🌰</div> <div class="score" id="score">0 分</div> <div class="game-over" id="game-over"> 💀 游戏结束<br> <span style="font-size:16px;">得分: <span id="final-score">0</span></span> <br><button class="restart-btn" id="restart-btn">再来一局</button> </div> </div> <script> (function() { var game = document.getElementById('zombie-game'); var nut = document.getElementById('nut'); var scoreEl = document.getElementById('score'); var gameOverEl = document.getElementById('game-over'); var finalScoreEl = document.getElementById('final-score'); var restartBtn = document.getElementById('restart-btn'); var score = 0; var isJumping = false; var isGameOver = false; var zombies = []; var gameSpeed = 3; var spawnTimer = null; var moveTimer = null; function jump() { if (isJumping || isGameOver) return; isJumping = true; nut.classList.add('jumping'); setTimeout(function() { nut.classList.remove('jumping'); isJumping = false; }, 400); } function spawnZombie() { if (isGameOver) return; var zombie = document.createElement('div'); zombie.className = 'zombie'; zombie.textContent = '🧟'; zombie.style.right = '-50px'; game.appendChild(zombie); zombies.push({ el: zombie, x: -50 }); } function moveZombies() { if (isGameOver) return; for (var i = zombies.length - 1; i >= 0; i--) { var z = zombies[i]; z.x += gameSpeed; z.el.style.right = z.x + 'px'; // 碰撞检测 var nutLeft = 50; var nutRight = 100; var zombieLeft = 600 - z.x - 40; var zombieRight = 600 - z.x; if (zombieLeft < nutRight && zombieRight > nutLeft && !isJumping) { gameOver(); return; } // 跳过僵尸加分 if (zombieLeft < nutRight && zombieRight > nutLeft && isJumping && !z.scored) { z.scored = true; score++; scoreEl.textContent = score + ' 分'; if (score % 10 === 0) gameSpeed += 0.5; } // 移除屏幕外的僵尸 if (z.x > 700) { z.el.remove(); zombies.splice(i, 1); } } } function gameOver() { isGameOver = true; clearInterval(spawnTimer); clearInterval(moveTimer); finalScoreEl.textContent = score; gameOverEl.style.display = 'block'; } function restart() { isGameOver = false; score = 0; gameSpeed = 3; scoreEl.textContent = '0 分'; gameOverEl.style.display = 'none'; zombies.forEach(function(z) { z.el.remove(); }); zombies = []; spawnTimer = setInterval(spawnZombie, 1500); moveTimer = setInterval(moveZombies, 30); } game.addEventListener('click', jump); game.addEventListener('touchstart', function(e) { e.preventDefault(); jump(); }); restartBtn.addEventListener('click', function(e) { e.stopPropagation(); restart(); }); restart(); })(); </script> </includeonly>
返回
微件:ZombieGame
。
查看“︁微件:ZombieGame”︁的源代码
来自植物大战僵尸杂交版Wiki