-
个人简介
濠梁之辩)?
#include<bits/stdc++.h> using namespace std; int N;//庄子与惠子互怼句数,这里用奇数 string dui; int main(){ cin>>N; ios::sync_with_stdio(0); cout.tie(0); cout<<"庄子与惠子游于濠梁之上。\n\ 庄子曰:“鲦鱼出游从容,是鱼之乐也。”\n\ 惠子曰:“子非鱼,安知鱼之乐?”\n"; for(int i=1;i<=N;i++) { cout<<((i&1)? "庄子曰:“子非我,安知": "惠子曰:“子非我,安知"); dui+=((i&1)?"我不知":"子不知"); cout<<dui; cout<<"鱼之乐?”\n"; } cout<<"惠子曰:“我非子,固不知子矣;子固非鱼也,子之不知鱼之乐,全矣!”\n\ 庄子曰:“请循其本。子曰‘汝安知鱼乐’云者,既已知吾知之而问我,我知之濠上也。”"; return 0; }好玩的html
<!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>2048 游戏</title> <style> * { margin: 0; padding: 0; box-sizing: border-box; font-family: "Arial", sans-serif; } body { background-color: #faf8ef; display: flex; flex-direction: column; align-items: center; padding: 20px; } .game-container { width: 100%; max-width: 420px; } .game-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; } .game-title { font-size: 48px; font-weight: bold; color: #776e65; } .score-container { background-color: #bbada0; padding: 10px 15px; border-radius: 6px; color: white; text-align: center; } .score-label { font-size: 14px; color: #eee4da; } .score-value { font-size: 24px; font-weight: bold; } .game-buttons { display: flex; gap: 10px; margin-bottom: 20px; } button { padding: 10px 15px; border: none; border-radius: 6px; background-color: #8f7a66; color: white; font-size: 16px; cursor: pointer; transition: background 0.2s; } button:hover { background-color: #9f8b77; } .game-board { width: 400px; height: 400px; background-color: #bbada0; border-radius: 10px; padding: 10px; display: grid; grid-template-columns: repeat(4, 1fr); grid-template-rows: repeat(4, 1fr); gap: 10px; } .tile { background-color: #cdc1b4; border-radius: 6px; display: flex; align-items: center; justify-content: center; font-size: 32px; font-weight: bold; color: #776e65; transition: transform 0.15s ease, background-color 0.15s ease; } /* 不同数字方块样式 */ .tile-2 { background-color: #eee4da; } .tile-4 { background-color: #ede0c8; } .tile-8 { background-color: #f2b179; color: white; } .tile-16 { background-color: #f59563; color: white; } .tile-32 { background-color: #f67c5f; color: white; } .tile-64 { background-color: #f65e3b; color: white; } .tile-128 { background-color: #edcf72; color: white; font-size: 28px; } .tile-256 { background-color: #edcc61; color: white; font-size: 28px; } .tile-512 { background-color: #edc850; color: white; font-size: 28px; } .tile-1024 { background-color: #edc53f; color: white; font-size: 24px; } .tile-2048 { background-color: #edc22e; color: white; font-size: 24px; } /* 游戏提示遮罩 */ .game-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(238, 228, 218, 0.7); display: none; flex-direction: column; align-items: center; justify-content: center; z-index: 100; } .overlay-text { font-size: 48px; font-weight: bold; color: #776e65; margin-bottom: 20px; } </style> </head> <body> <div class="game-container"> <div class="game-header"> <div class="game-title">2048</div> <div class="score-container"> <div class="score-label">分数</div> <div class="score-value" id="score">0</div> </div> </div> <div class="game-buttons"> <button id="newGameBtn">新游戏</button> </div> <div class="game-board" id="board"></div> <div class="game-overlay" id="gameOver"> <div class="overlay-text">游戏结束</div> <button id="restartBtn">重新开始</button> </div> <div class="game-overlay" id="gameWin"> <div class="overlay-text">你赢了!</div> <button id="continueBtn">继续游戏</button> </div> </div> <script> // 游戏核心变量 const board = document.getElementById('board'); const scoreElement = document.getElementById('score'); const gameOverOverlay = document.getElementById('gameOver'); const gameWinOverlay = document.getElementById('gameWin'); let grid = []; let score = 0; let hasWon = false; // 初始化游戏 function initGame() { grid = [ [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0] ]; score = 0; hasWon = false; updateScore(); gameOverOverlay.style.display = 'none'; gameWinOverlay.style.display = 'none'; // 生成两个初始方块 addRandomTile(); addRandomTile(); renderBoard(); } // 渲染棋盘 function renderBoard() { board.innerHTML = ''; for (let row = 0; row < 4; row++) { for (let col = 0; col < 4; col++) { const tile = document.createElement('div'); tile.classList.add('tile'); const value = grid[row][col]; if (value !== 0) { tile.textContent = value; tile.classList.add(`tile-${value}`); } board.appendChild(tile); } } } // 随机生成新方块(2或4) function addRandomTile() { let emptyCells = []; for (let row = 0; row < 4; row++) { for (let col = 0; col < 4; col++) { if (grid[row][col] === 0) { emptyCells.push({row, col}); } } } if (emptyCells.length === 0) return; const randomCell = emptyCells[Math.floor(Math.random() * emptyCells.length)]; grid[randomCell.row][randomCell.col] = Math.random() < 0.9 ? 2 : 4; } // 更新分数显示 function updateScore() { scoreElement.textContent = score; } // 键盘控制 document.addEventListener('keydown', (e) => { if (gameOverOverlay.style.display === 'flex') return; let moved = false; switch (e.key) { case 'ArrowUp': moved = moveUp(); break; case 'ArrowDown': moved = moveDown(); break; case 'ArrowLeft': moved = moveLeft(); break; case 'ArrowRight': moved = moveRight(); break; } if (moved) { addRandomTile(); renderBoard(); checkWin(); checkGameOver(); } }); // 移动逻辑 - 左 function moveLeft() { let moved = false; for (let row = 0; row < 4; row++) { let originalRow = [...grid[row]]; let newRow = compressRow(originalRow); grid[row] = newRow; if (originalRow.toString() !== newRow.toString()) { moved = true; } } return moved; } // 移动逻辑 - 右 function moveRight() { let moved = false; for (let row = 0; row < 4; row++) { let originalRow = [...grid[row]]; let reversedRow = originalRow.reverse(); let newRow = compressRow(reversedRow).reverse(); grid[row] = newRow; if (originalRow.toString() !== newRow.toString()) { moved = true; } } return moved; } // 移动逻辑 - 上 function moveUp() { let moved = false; for (let col = 0; col < 4; col++) { let column = [grid[0][col], grid[1][col], grid[2][col], grid[3][col]]; let originalCol = [...column]; let newCol = compressRow(column); for (let row = 0; row < 4; row++) { grid[row][col] = newCol[row]; } if (originalCol.toString() !== newCol.toString()) { moved = true; } } return moved; } // 移动逻辑 - 下 function moveDown() { let moved = false; for (let col = 0; col < 4; col++) { let column = [grid[0][col], grid[1][col], grid[2][col], grid[3][col]]; let originalCol = [...column]; let reversedCol = column.reverse(); let newCol = compressRow(reversedCol).reverse(); for (let row = 0; row < 4; row++) { grid[row][col] = newCol[row]; } if (originalCol.toString() !== newCol.toString()) { moved = true; } } return moved; } // 压缩行/列(合并相同数字) function compressRow(row) { let newRow = row.filter(num => num !== 0); for (let i = 0; i < newRow.length - 1; i++) { if (newRow[i] === newRow[i + 1]) { newRow[i] *= 2; score += newRow[i]; newRow[i + 1] = 0; } } newRow = newRow.filter(num => num !== 0); while (newRow.length < 4) { newRow.push(0); } updateScore(); return newRow; } // 检查胜利 function checkWin() { if (hasWon) return; for (let row = 0; row < 4; row++) { for (let col = 0; col < 4; col++) { if (grid[row][col] === 2048) { hasWon = true; gameWinOverlay.style.display = 'flex'; return; } } } } // 检查游戏结束 function checkGameOver() { // 有空格则未结束 for (let row = 0; row < 4; row++) { for (let col = 0; col < 4; col++) { if (grid[row][col] === 0) return; } } // 检查相邻是否可合并 for (let row = 0; row < 4; row++) { for (let col = 0; col < 4; col++) { const current = grid[row][col]; // 检查右侧 if (col < 3 && grid[row][col + 1] === current) return; // 检查下方 if (row < 3 && grid[row + 1][col] === current) return; } } // 无空格无可合并 → 游戏结束 gameOverOverlay.style.display = 'flex'; } // 按钮事件 document.getElementById('newGameBtn').addEventListener('click', initGame); document.getElementById('restartBtn').addEventListener('click', initGame); document.getElementById('continueBtn').addEventListener('click', () => { gameWinOverlay.style.display = 'none'; }); // 启动游戏 window.onload = initGame; </script> </body> </html> -
通过的题目
-
最近活动
题目标签
- 语法
- 4
- 2015
- 2
- NOIP 普及组
- 2
- 其他
- 2
- 2005
- 1
- 字符串
- 1
- stl
- 1
- NOIP
- 1
- 提高组
- 1
- A
- 1
- 质数分解
- 1
- 递归
- 1
- 快速幂
- 1
- 教程
- 1
- 数学
- 1
- 模拟
- 1