您的位置:首页 > 汽车 > 新车 > 国内大型游戏外包公司_营销网站制作流程_江苏seo哪家好_惠州百度seo哪里强

国内大型游戏外包公司_营销网站制作流程_江苏seo哪家好_惠州百度seo哪里强

2024/12/29 6:35:24 来源:https://blog.csdn.net/qq_36997660/article/details/144060756  浏览:    关键词:国内大型游戏外包公司_营销网站制作流程_江苏seo哪家好_惠州百度seo哪里强
国内大型游戏外包公司_营销网站制作流程_江苏seo哪家好_惠州百度seo哪里强

有没有万能公式,我现在只会33 35这种简单的

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Toggle Grid Game</title><style>body {font-family: Arial, sans-serif;text-align: center;margin: 0;padding: 0;display: flex;flex-direction: column;align-items: center;justify-content: center;height: 100vh;background-color: #f0f0f0;}.grid {display: grid;border: 2px solid red; /* Outer border in red */margin-top: 20px;}.cell {width: 30px;height: 30px;border: 1px solid red; /* Red border for each cell */margin: 0;padding: 0;background-color: white;cursor: pointer;}.cell.black {background-color: black;}.controls {margin-bottom: 20px;}.controls input,.controls button {margin-right: 10px;padding: 5px;}</style>
</head>
<body><h1>Toggle Grid Game</h1><div class="controls"><label for="rows">Rows:</label><input type="number" id="rows" value="3" min="1" max="50"><label for="cols">Columns:</label><input type="number" id="cols" value="3" min="1" max="50"><button onclick="initializeGrid()">Set Grid</button><button onclick="fillAllBlack()">Fill All Black</button></div><div id="gridContainer"></div><script>let rows = 3; // Default number of rowslet cols = 3; // Default number of columnslet grid = [];let clickCount = 0; // Counter for clicksconst container = document.getElementById("gridContainer");// Function to initialize gridfunction initializeGrid() {rows = parseInt(document.getElementById("rows").value, 10);cols = parseInt(document.getElementById("cols").value, 10);clickCount = 0; // Reset click count// Initialize grid with random 0s and 1sgrid = Array.from({ length: rows }, () => Array.from({ length: cols }, () => Math.random() < 0.5 ? 1 : 0));// Set grid layout styles dynamicallycontainer.style.gridTemplateRows = `repeat(${rows}, 30px)`; // Fixed height for rowscontainer.style.gridTemplateColumns = `repeat(${cols}, 30px)`; // Fixed width for columnscontainer.classList.add("grid");// Render gridcreateGrid();}// Function to render gridfunction createGrid() {container.innerHTML = ""; // Clear existing gridgrid.forEach((row, rowIndex) => {row.forEach((cell, colIndex) => {const button = document.createElement("button");button.className = `cell ${cell ? "black" : ""}`; // Black if 1, white if 0button.onclick = () => toggleCell(rowIndex, colIndex);container.appendChild(button);});});checkWin(); // Check for win condition after rendering}// Toggle cell and adjacent cellsfunction toggleCell(x, y) {clickCount++; // Increment click countgrid[x][y] ^= 1;if (x > 0) grid[x - 1][y] ^= 1; // Topif (x < rows - 1) grid[x + 1][y] ^= 1; // Bottomif (y > 0) grid[x][y - 1] ^= 1; // Leftif (y < cols - 1) grid[x][y + 1] ^= 1; // RightcreateGrid(); // Re-render the grid}// Fill all cells with blackfunction fillAllBlack() {grid = Array.from({ length: rows }, () => Array.from({ length: cols }, () => 1)); // All 1sclickCount = 0; // Reset click countcreateGrid(); // Re-render the grid}// Check if all cells are whitefunction checkWin() {const allWhite = grid.every(row => row.every(cell => cell === 0)); // Check if all cells are 0if (allWhite) {setTimeout(() => alert(`Congratulations! You turned all the cells white! 🎉\nYou completed the game in ${clickCount} steps.`), 100);}}// Initial renderinitializeGrid();</script>
</body>
</html>

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com