Scan to open on your phone
Point a camera at the QR code - it opens this exact paste, no app needed.
https://codepastes.com/zzgsxwdsem2raqfruntitledPlain Text
<!DOCTYPE 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: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background: #1a1a2e;
color: #fff;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
margin: 0;
}
h1 {
margin-bottom: 10px;
font-size: 2.5rem;
color: #00fff0;
text-shadow: 0 0 10px rgba(0, 255, 240, 0.5);
}
.status {
font-size: 1.2rem;
margin-bottom: 20px;
font-weight: bold;
}
.board {
display: grid;
grid-template-columns: repeat(3, 100px);
grid-template-rows: repeat(3, 100px);
gap: 10px;
background-color: #162447;
padding: 10px;
border-radius: 10px;
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}
.cell {
background-color: #1f4068;
border: none;
border-radius: 5px;
font-size: 2.5rem;
font-weight: bold;
color: #fff;
cursor: pointer;
transition: background-color 0.2s, transform 0.1s;
}
.cell:hover {
background-color: #e43f5a;
}
.cell.x {
color: #00fff0;
}
.cell.o {
color: #e43f5a;
}
.reset-btn {
margin-top: 25px;
padding: 10px 20px;
font-size: 1rem;
font-weight: bold;
background-color: #00fff0;
color: #1a1a2e;
border: none;
border-radius: 5px;
cursor: pointer;
box-shadow: 0 4px 10px rgba(0, 255, 240, 0.3);
transition: all 0.2s;
}
.reset-btn:hover {
background-color: #fff;
transform: scale(1.05);
}
</style>
</head>
<body>
<h1>Tic Tac Toe</h1>
<div class="status" id="status">Player X's turn</div>
<div class="board" id="board">
<button class="cell" data-index="0"></button>
<button class="cell" data-index="1"></button>
<button class="cell" data-index="2"></button>
<button class="cell" data-index="3"></button>
<button class="cell" data-index="4"></button>
<button class="cell" data-index="5"></button>
<button class="cell" data-index="6"></button>
<button class="cell" data-index="7"></button>
<button class="cell" data-index="8"></button>
</div>
<button class="reset-btn" id="resetBtn">Reset Game</button>
<script>
const boardElement = document.getElementById('board');
const cells = document.querySelectorAll('.cell');
const statusElement = document.getElementById('status');
const resetBtn = document.getElementById('resetBtn');
let currentPlayer = 'X';
let gameState = ["", "", "", "", "", "", "", "", ""];
let isGameActive = true;
const winningConditions = [
[0, 1, 2],
[3, 4, 5],
[6, 7, 8],
[0, 3, 6],
[1, 4, 7],
[2, 5, 8],
[0, 4, 8],
[2, 4, 6]
];
function handleCellClick(e) {
const clickedCell = e.target;
const clickedCellIndex = parseInt(clickedCell.getAttribute('data-index'));
if (gameState[clickedCellIndex] !== "" || !isGameActive) {
return;
}
gameState[clickedCellIndex] = currentPlayer;
clickedCell.textContent = currentPlayer;
clickedCell.classList.add(currentPlayer.toLowerCase());
checkResult();
}
function checkResult() {
let roundWon = false;
for (let i = 0; i < winningConditions.length; i++) {
const [a, b, c] = winningConditions[i];
if (gameState[a] === "" || gameState[b] === "" || gameState[c] === "") {
continue;
}
if (gameState[a] === gameState[b] && gameState[b] === gameState[c]) {
roundWon = true;
break;
}
}
if (roundWon) {
statusElement.textContent = `Player ${currentPlayer} Wins! 🎉`;
statusElement.style.color = currentPlayer === 'X' ? '#00fff0' : '#e43f5a';
isGameActive = false;
return;
}
if (!gameState.includes("")) {
statusElement.textContent = "It's a Tie! 🤝";
statusElement.style.color = '#fff';
isGameActive = false;
return;
}
currentPlayer = currentPlayer === 'X' ? 'O' : 'X';
statusElement.textContent = `Player ${currentPlayer}'s turn`;
}
function resetGame() {
currentPlayer = 'X';
gameState = ["", "", "", "", "", "", "", "", ""];
isGameActive = true;
statusElement.textContent = "Player X's turn";
statusElement.style.color = '#fff';
cells.forEach(cell => {
cell.textContent = "";
cell.className = "cell";
});
}
cells.forEach(cell => cell.addEventListener('click', handleCellClick));
resetBtn.addEventListener('click', resetGame);
</script>
</body>
</html>
5,731 chars · codepastes.com