🎁 挖宝箱 点击格子挖掘,找到 🔑×2 即可开箱! 🎉 宝箱开启! 再来一局 const NUM_LABELS = ['×1','×2','×3','×5']; const QUAL_LABELS = ['普通','稀有','史诗','传说']; const QUAL_COLORS = ['#aaa','#4fc3f7','#ab47bc','#ffab00']; let cells = []; // {type:'key'|'num'|'qual', value, revealed} let keysFound = 0; let gameOver = false; let totalGames = 0; let totalDigs = 0; function shuffle(arr) { for (let i = arr.length - 1; i > 0; i--) { const j = Math.floor(Math.random() * (i + 1)); [arr[i], arr[j]] = [arr[j], arr[i]]; } return arr; } function initGame() { keysFound = 0; gameOver = false; document.getElementById('overlay').classList.remove('show'); updateInfo(); // Build pool: 2 keys, 4 num, 4 qual const pool = []; for (let i = 0; i < 2; i++) pool.push({ type: 'key', value: null }); const nums = shuffle([...NUM_LABELS]); for (let i = 0; i < 4; i++) pool.push({ type: 'num', value: nums[i] }); const quals = shuffle([...QUAL_LABELS]); for (let i = 0; i < 4; i++) pool.push({ type: 'qual', value: quals[i] }); shuffle(pool); cells = pool.map(p => ({ ...p, revealed: false })); renderGrid(); } function renderGrid() { const grid = document.getElementById('grid'); grid.innerHTML = ''; cells.forEach((cell, idx) => { const div = document.createElement('div'); div.className = 'cell'; if (cell.revealed) { div.classList.add('revealed'); if (cell.type === 'key') { div.textContent = '🔑'; div.classList.add('key-found'); } else if (cell.type === 'num') { div.textContent = cell.value; div.classList.add('num'); } else { div.textContent = cell.value; div.classList.add('qual'); div.style.color = QUAL_COLORS[QUAL_LABELS.indexOf(cell.value)] || '#eee'; } } else { div.textContent = '❓'; if (gameOver) div.classList.add('disabled'); div.onclick = () => dig(idx); } grid.appendChild(div); }); } function dig(idx) { if (gameOver || cells[idx].revealed) return; cells[idx].revealed = true; totalDigs++; if (cells[idx].type === 'key') { keysFound++; if (keysFound >= 2) { gameOver = true; renderGrid(); setTimeout(showResult, 400); return; } } updateInfo(); renderGrid(); } function updateInfo() { const remaining = cells.filter(c => !c.revealed).length; document.getElementById('info').textContent = `已找到 🔑 ${keysFound}/2 | 剩余未挖 ${remaining} 格`; } function showResult() { totalGames++; const digs = cells.filter(c => c.revealed).length; const nums = cells.filter(c => c.revealed && c.type === 'num').map(c => c.value); const quals = cells.filter(c => c.revealed && c.type === 'qual').map(c => c.value); let text = `本次挖掘 ${digs} 格\n\n`; text += `数量加成:${nums.length ? nums.join('、') : '无'}\n`; text += `品质加成:${quals.length ? quals.join('、') : '无'}`; document.getElementById('resultText').innerText = text; document.getElementById('overlay').classList.add('show'); document.getElementById('stats').textContent = `累计 ${totalGames} 局 | 平均挖掘 ${(totalDigs / totalGames).toFixed(1)} 格`; } initGame();