Spaces:
Running
Running
File size: 7,439 Bytes
8aeb522 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
<!DOCTYPE html>
<html lang="en">
<!-- Mirrored from es-teams-database2025.onrender.com/ttt-single.html by HTTrack Website Copier/3.x [XR&CO'2017], Fri, 14 Feb 2025 22:35:14 GMT -->
<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=UTF-8" /><!-- /Added by HTTrack -->
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Tic-Tac-Toe</title>
<script src="../external.html?link=https://cdn.tailwindcss.com/"></script>
<style>
body {
background: linear-gradient(135deg, #1a1a1a, #3a3a3a);
color: white;
font-family: Arial, sans-serif;
text-align: center;
}
.game-board {
display: grid;
grid-template-columns: repeat(3, 100px);
grid-template-rows: repeat(3, 100px);
gap: 5px;
margin: 20px auto;
}
.cell {
width: 100px;
height: 100px;
display: flex;
align-items: center;
justify-content: center;
font-size: 2rem;
font-weight: bold;
border: 2px solid white;
cursor: pointer;
transition: background-color 0.3s ease;
}
.win {
background-color: rgba(0, 255, 0, 0.5);
animation: flash 0.5s alternate infinite;
}
@keyframes flash {
from { background-color: rgba(0, 255, 0, 0.5); }
to { background-color: rgba(0, 255, 0, 0.8); }
}
.countdown {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
font-size: 5rem;
font-weight: bold;
opacity: 1;
animation: fadeout 3s linear forwards;
}
@keyframes fadeout {
0% { opacity: 1; }
100% { opacity: 0; visibility: hidden; }
}
.moving-text {
position: absolute;
top: 10px;
white-space: nowrap;
font-size: 1.5rem;
font-weight: bold;
animation: moveLeft 10s linear infinite;
}
@keyframes moveLeft {
from { left: 100%; }
to { left: -100%; }
}
.clock {
position: absolute;
top: 20px;
right: 20px;
font-size: 1.2rem;
font-weight: bold;
}
</style>
</head>
<body class="flex flex-col items-center justify-center min-h-screen">
<!-- Back Arrow -->
<div class="absolute top-2 left-2">
<button onclick="location.href='games-2.html'" class="text-white text-2xl">β¬
</button>
</div>
<!-- Moving Text -->
<div class="moving-text text-yellow-500">ππ¦ π§πππ π¦ π§πππ§πππ§π’π</div>
<!-- Clock -->
<div class="clock" id="clock"></div>
<!-- Countdown Before Start -->
<div id="countdown" class="countdown text-red-500"></div>
<!-- Game Info -->
<div id="player-info" class="text-xl mt-4"></div>
<!-- Game Board -->
<div class="game-board">
<div class="cell" onclick="makeMove(0)"></div>
<div class="cell" onclick="makeMove(1)"></div>
<div class="cell" onclick="makeMove(2)"></div>
<div class="cell" onclick="makeMove(3)"></div>
<div class="cell" onclick="makeMove(4)"></div>
<div class="cell" onclick="makeMove(5)"></div>
<div class="cell" onclick="makeMove(6)"></div>
<div class="cell" onclick="makeMove(7)"></div>
<div class="cell" onclick="makeMove(8)"></div>
</div>
<script>
let gameActive = false;
let board = Array(9).fill("");
let player, computer;
function startGame() {
document.getElementById("countdown").textContent = "3";
setTimeout(() => document.getElementById("countdown").textContent = "2", 1000);
setTimeout(() => document.getElementById("countdown").textContent = "1", 2000);
setTimeout(() => {
document.getElementById("countdown").style.display = "none";
gameActive = true;
board.fill("");
// Randomly assign X or O
player = Math.random() < 0.5 ? "X" : "O";
computer = player === "X" ? "O" : "X";
updateBoard();
document.getElementById("player-info").textContent = `You are ${player}, Computer is ${computer}`;
if (computer === "X") {
setTimeout(computerMove, 500);
}
}, 3000);
}
function makeMove(index) {
if (!gameActive || board[index]) return;
board[index] = player;
updateBoard();
if (!checkWin()) setTimeout(computerMove, 500);
}
function computerMove() {
if (!gameActive) return;
let bestMove = findBestMove();
board[bestMove] = computer;
updateBoard();
checkWin();
}
function findBestMove() {
let emptyCells = board.map((v, i) => v === "" ? i : null).filter(v => v !== null);
for (let pattern of [[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 [a, b, c] = pattern;
if (board[a] === player && board[b] === player && board[c] === "") return c;
if (board[a] === player && board[c] === player && board[b] === "") return b;
if (board[b] === player && board[c] === player && board[a] === "") return a;
}
return emptyCells[Math.floor(Math.random() * emptyCells.length)];
}
function updateBoard() {
document.querySelectorAll(".cell").forEach((cell, i) => {
cell.textContent = board[i];
cell.classList.remove("win");
cell.style.color = board[i] === "X" ? "blue" : board[i] === "O" ? "red" : "white";
});
}
function checkWin() {
for (let pattern of [[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 [a, b, c] = pattern;
if (board[a] && board[a] === board[b] && board[a] === board[c]) {
document.getElementById("player-info").textContent = `${board[a]} Wins!`;
pattern.forEach(i => document.querySelectorAll(".cell")[i].classList.add("win"));
gameActive = false;
setTimeout(startGame, 2000);
return true;
}
}
if (!board.includes("")) {
document.getElementById("player-info").textContent = "It's a Draw!";
gameActive = false;
setTimeout(startGame, 2000);
}
return false;
}
function updateClock() {
document.getElementById("clock").textContent = new Date().toLocaleTimeString();
setTimeout(updateClock, 1000);
}
updateClock();
startGame();
</script>
</body>
<!-- Mirrored from es-teams-database2025.onrender.com/ttt-single.html by HTTrack Website Copier/3.x [XR&CO'2017], Fri, 14 Feb 2025 22:35:15 GMT -->
</html> |