o1-mini-2024-09-12· OpenAI
WildChat-4.8M (AI2)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta…
- User
body { display: flex; justify-content: center; align-items: center; height: 100vh; background: linear-gradient(135deg, #f0f0f0, #c0c0c0); } .container { text-align: center; } h1 { margin-bottom: 20px; color: #333; } #game { display: grid; grid-template-columns: repeat(3, 100px); grid-template-rows: repeat(3, 100px); gap: 10px; margin: 0 auto; } .cell { background: #fff; border-radius: 10px; box-shadow: 0 4px 6px rgba(0,0,0,0.1); display: flex; justify-content: center; align-items: center; font-size: 2.5rem; cursor: pointer; position: relative; transition: transform 0.2s ease-in-out, background 0.3s; } .cell:hover { transform: scale(1.05); background: #f9f9f9; } .cell.X::before { content: "X"; color: #e74c3c; animation: fadeIn 0.3s ease-in-out; } .cell.O::before { content: "O"; color: #3498db; animation: fadeIn 0.3s ease-in-out; } @keyframes fadeIn { from { opacity: 0; transform: scale(0.5); } to { opacity: 1; transform: scale(1); } } .message { margin-top: 20px; font-size: 1.2rem; color: #555; } .restart-btn { margin-top: 15px; padding: 10px 20px; font-size: 1rem; background: #3498db; color: #fff; border: none; border-radius: 5px; cursor: pointer; transition: background 0.3s; } .restart-btn:hover { background: #2980b9; } @media (max-width: 500px) { #game { grid-template-columns: repeat(3, 80px); grid-template-rows: repeat(3, 80px); gap: 8px; } .cell { font-size: 2rem; } } </style><script> (function() { const cells = document.querySelectorAll('.cell'); const message = document.getElementById('message'); const restartBtn = document.getElementById('restartBtn'); const winningCombinations = [ [0,1,2], [3,4,5], [6,7,8], [0,3,6], [1,4,7], [2,5,8], [0,4,8], [2,4,6] ]; let board = ['', '', '', '', '', '', '', '', '']; let currentPlayer = 'X'; let isGameActive = true; const handleCellClick = (e) => { const index = e.target.getAttribute('data-index'); if (board[index] !== '' || !isGameActive) return; updateCell(e.target, index); checkResult(); }; const updateCell = (cell, index) => { board[index] = currentPlayer; cell.classList.add(currentPlayer); cell.style.pointerEvents = 'none'; // Animation handled via CSS }; const switchPlayer = () => { currentPlayer = currentPlayer === 'X' ? 'O' : 'X'; message.textContent = `Player ${currentPlayer}'s turn`; }; const checkResult = () => { let roundWon = false; for (let condition of winningCombinations) { const [a, b, c] = condition; if (board[a] && board[a] === board[b] && board[a] === board[c]) { roundWon = true; highlightWinningCells(condition); break; } } if (roundWon) { message.textContent = `Player ${currentPlayer} Wins! 🎉`; isGameActive = false; return; } if (!board.includes('')) { message.textContent = `It's a Draw! 🤝`; isGameActive = false; return; } switchPlayer(); }; const highlightWinningCells = (condition) => { condition.forEach(index => { cells[index].style.background = currentPlayer === 'X' ? '#ffe6e6' : '#e6f0ff'; }); }; const restartGame = () => { board = ['', '', '', '', '', '', '', '', '']; isGameActive = true; currentPlayer = 'X'; message.textContent = `Player ${currentPlayer}'s turn`; cells.forEach(cell => { cell.classList.remove('X', 'O'); cell.style.background = '#fff'; cell.style.pointerEvents = 'auto'; }); }; cells.forEach(cell => { cell.addEventListener('click', handleCellClick); }); restartBtn.addEventListener('click', restartGame); })(); </script> - Assistant