arela
Version:
AI-powered CTO with multi-agent orchestration, code summarization, visual testing (web + mobile) for blazing fast development.
170 lines (154 loc) • 5.08 kB
HTML
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Tic Tac Toe</title>
<style>
body {
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
margin: 0;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}
.container {
text-align: center;
background: white;
padding: 2rem;
border-radius: 20px;
box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
h1 {
color: #667eea;
margin-bottom: 1rem;
}
.board {
display: grid;
grid-template-columns: repeat(3, 100px);
grid-gap: 10px;
margin: 20px auto;
}
.cell {
width: 100px;
height: 100px;
background: #f0f0f0;
border: none;
font-size: 2rem;
font-weight: bold;
cursor: pointer;
border-radius: 10px;
transition: all 0.3s;
}
.cell:hover:not(:disabled) {
background: #667eea;
color: white;
transform: scale(1.05);
}
.cell:disabled {
cursor: not-allowed;
}
.status {
font-size: 1.5rem;
margin: 20px 0;
color: #333;
min-height: 40px;
}
.reset {
background: #667eea;
color: white;
border: none;
padding: 10px 30px;
font-size: 1rem;
border-radius: 25px;
cursor: pointer;
transition: all 0.3s;
}
.reset:hover {
background: #764ba2;
transform: scale(1.05);
}
.winner {
color: #4CAF50;
font-weight: bold;
}
</style>
</head>
<body>
<div class="container">
<h1>🎮 Tic Tac Toe</h1>
<div class="status" id="status">Player X's turn</div>
<div class="board" id="board"></div>
<button class="reset" id="reset">New Game</button>
</div>
<script>
let currentPlayer = 'X';
let board = ['', '', '', '', '', '', '', '', ''];
let gameActive = true;
const statusDisplay = document.getElementById('status');
const boardElement = document.getElementById('board');
const resetButton = document.getElementById('reset');
const winningConditions = [
[0, 1, 2], [3, 4, 5], [6, 7, 8], // rows
[0, 3, 6], [1, 4, 7], [2, 5, 8], // columns
[0, 4, 8], [2, 4, 6] // diagonals
];
function createBoard() {
boardElement.innerHTML = '';
for (let i = 0; i < 9; i++) {
const cell = document.createElement('button');
cell.classList.add('cell');
cell.setAttribute('data-cell-index', i);
cell.addEventListener('click', handleCellClick);
boardElement.appendChild(cell);
}
}
function handleCellClick(e) {
const clickedCell = e.target;
const clickedCellIndex = parseInt(clickedCell.getAttribute('data-cell-index'));
if (board[clickedCellIndex] !== '' || !gameActive) {
return;
}
board[clickedCellIndex] = currentPlayer;
clickedCell.textContent = currentPlayer;
clickedCell.disabled = true;
checkResult();
}
function checkResult() {
let roundWon = false;
for (let i = 0; i < winningConditions.length; i++) {
const [a, b, c] = winningConditions[i];
if (board[a] && board[a] === board[b] && board[a] === board[c]) {
roundWon = true;
break;
}
}
if (roundWon) {
statusDisplay.textContent = `🎉 Player ${currentPlayer} wins!`;
statusDisplay.classList.add('winner');
gameActive = false;
return;
}
if (!board.includes('')) {
statusDisplay.textContent = "🤝 It's a draw!";
gameActive = false;
return;
}
currentPlayer = currentPlayer === 'X' ? 'O' : 'X';
statusDisplay.textContent = `Player ${currentPlayer}'s turn`;
}
function resetGame() {
currentPlayer = 'X';
board = ['', '', '', '', '', '', '', '', ''];
gameActive = true;
statusDisplay.textContent = "Player X's turn";
statusDisplay.classList.remove('winner');
createBoard();
}
resetButton.addEventListener('click', resetGame);
createBoard();
</script>
</body>
</html>