Download single-file.html from ajcodes07/tic-tac-toe-titanium-thunder: direct link, hf CLI and curl.
- Browser
- Download file 20.7 kB
-
https://huggingface.co/spaces/ajcodes07/tic-tac-toe-titanium-thunder/resolve/main/single-file.html
- Command line
-
hf download hf://spaces/ajcodes07/tic-tac-toe-titanium-thunder/single-file.html
-
curl -L -o single-file.html https://huggingface.co/spaces/ajcodes07/tic-tac-toe-titanium-thunder/resolve/main/single-file.html
20.7 kB
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>XOXO Showdown: Tic Tac Toe Royale</title> | |
| <script src="https://cdn.tailwindcss.com"></script> | |
| <script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script> | |
| <script src="https://unpkg.com/feather-icons"></script> | |
| <style> | |
| /* Background animation */ | |
| body { | |
| min-height: 100vh; | |
| margin: 0; | |
| padding: 0; | |
| overflow-x: hidden; | |
| font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; | |
| } | |
| /* Confetti effect for wins */ | |
| .confetti { | |
| position: fixed; | |
| width: 10px; | |
| height: 10px; | |
| background-color: #f00; | |
| opacity: 0.7; | |
| animation: confetti 5s ease-in-out infinite; | |
| z-index: 1000; | |
| } | |
| @keyframes confetti { | |
| 0% { | |
| transform: translateY(0) rotate(0deg); | |
| top: -10px; | |
| } | |
| 100% { | |
| transform: translateY(100vh) rotate(360deg); | |
| top: 100%; | |
| } | |
| } | |
| /* Custom styles for game cells */ | |
| .cell { | |
| aspect-ratio: 1/1; | |
| display: flex; | |
| align-items: center; | |
| justify-content: center; | |
| font-size: 3rem; | |
| font-weight: bold; | |
| cursor: pointer; | |
| transition: all 0.2s ease; | |
| } | |
| .cell:hover { | |
| transform: scale(1.05); | |
| } | |
| .cell-x { | |
| color: #3B82F6; /* blue-500 */ | |
| } | |
| .cell-o { | |
| color: #EC4899; /* pink-500 */ | |
| } | |
| .winning-cell { | |
| animation: pulse 0.8s infinite, rainbow 1.5s infinite, glow 1s infinite alternate; | |
| z-index: 10; | |
| position: relative; | |
| } | |
| @keyframes glow { | |
| from { | |
| box-shadow: 0 0 5px rgba(255, 255, 255, 0.7); | |
| } | |
| to { | |
| box-shadow: 0 0 20px rgba(255, 255, 255, 0.9); | |
| } | |
| } | |
| @keyframes rainbow { | |
| 0% { background-color: #3B82F6; } | |
| 20% { background-color: #EC4899; } | |
| 40% { background-color: #10B981; } | |
| 60% { background-color: #F59E0B; } | |
| 80% { background-color: #6366F1; } | |
| 100% { background-color: #3B82F6; } | |
| } | |
| @keyframes pulse { | |
| 0%, 100% { | |
| transform: scale(1); | |
| box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.4); | |
| } | |
| 50% { | |
| transform: scale(1.05); | |
| box-shadow: 0 0 0 10px rgba(59, 130, 246, 0); | |
| } | |
| } | |
| /* Responsive adjustments */ | |
| @media (max-width: 640px) { | |
| .cell { | |
| font-size: 2rem; | |
| } | |
| } | |
| /* Header styles */ | |
| .game-header { | |
| background: linear-gradient(135deg, #3B82F6 0%, #EC4899 100%); | |
| animation: headerPulse 8s infinite alternate; | |
| color: white; | |
| box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1); | |
| } | |
| @keyframes headerPulse { | |
| 0% { background: linear-gradient(135deg, #3B82F6 0%, #EC4899 100%); } | |
| 25% { background: linear-gradient(135deg, #EC4899 0%, #10B981 100%); } | |
| 50% { background: linear-gradient(135deg, #10B981 0%, #F59E0B 100%); } | |
| 75% { background: linear-gradient(135deg, #F59E0B 0%, #6366F1 100%); } | |
| 100% { background: linear-gradient(135deg, #6366F1 0%, #3B82F6 100%); } | |
| } | |
| /* Footer styles */ | |
| .game-footer { | |
| background-color: #1F2937; | |
| color: #E5E7EB; | |
| } | |
| .social-links a { | |
| transition: all 0.2s ease; | |
| } | |
| .social-links a:hover { | |
| transform: translateY(-2px); | |
| } | |
| /* Confetti container */ | |
| .confetti-container { | |
| position: fixed; | |
| top: 0; | |
| left: 0; | |
| width: 100%; | |
| height: 100%; | |
| pointer-events: none; | |
| z-index: 1000; | |
| } | |
| .confetti-piece { | |
| position: absolute; | |
| width: 10px; | |
| height: 10px; | |
| opacity: 0.7; | |
| animation: confetti-fall 5s linear forwards; | |
| } | |
| @keyframes confetti-fall { | |
| 0% { | |
| transform: translateY(-10px) rotate(0deg); | |
| top: 0; | |
| } | |
| 100% { | |
| transform: translateY(100vh) rotate(360deg); | |
| top: 100%; | |
| } | |
| } | |
| </style> | |
| </head> | |
| <body class="bg-gray-100 min-h-screen flex flex-col"> | |
| <header class="game-header py-6 px-4"> | |
| <div class="flex flex-col items-center text-center"> | |
| <h1 class="text-3xl md:text-4xl mb-2 animate-bounce">Tic Tac Toe Titanium Thunder</h1> | |
| <p class="text-lg md:text-xl">Battle Royale with Automatic Mayhem!</p> | |
| <button id="startAutoPlay" class="mt-4 px-6 py-2 bg-indigo-600 hover:bg-indigo-700 text-white font-bold rounded-full transition-all transform hover:scale-105 shadow-lg"> | |
| Start Automatic Mode | |
| </button> | |
| </div> | |
| </header> | |
| <main class="flex-grow container mx-auto px-4 py-8 flex flex-col items-center"> | |
| <div class="w-full max-w-md bg-white rounded-xl shadow-lg p-6 mb-8"> | |
| <div class="flex justify-between items-center mb-6"> | |
| <h2 class="text-2xl font-bold text-gray-800">Game Mode</h2> | |
| <div class="flex space-x-2"> | |
| <button id="playerMode" class="px-4 py-2 bg-blue-500 text-white rounded-lg font-medium shadow hover:bg-blue-600 transition">Player vs Player</button> | |
| <button id="aiMode" class="px-4 py-2 bg-gray-200 text-gray-700 rounded-lg font-medium shadow hover:bg-gray-300 transition">Player vs AI</button> | |
| <button id="autoPlay" class="px-4 py-2 bg-purple-500 text-white rounded-lg font-medium shadow hover:bg-purple-600 transition">Auto Play</button> | |
| </div> | |
| </div> | |
| <div class="mb-6 text-center"> | |
| <h3 id="currentPlayer" class="text-xl font-semibold text-gray-700">Player X's Turn</h3> | |
| <p id="gameStatus" class="text-gray-500">Game in progress</p> | |
| </div> | |
| <div class="grid grid-cols-3 gap-3 mb-6" id="gameBoard"> | |
| <!-- Game board will be generated by JavaScript --> | |
| </div> | |
| <div class="flex justify-center"> | |
| <button id="resetGame" class="px-6 py-2 bg-red-500 text-white rounded-lg font-medium shadow hover:bg-red-600 transition flex items-center"> | |
| <i data-feather="refresh-cw" class="mr-2 w-4 h-4"></i> | |
| Reset Game | |
| </button> | |
| </div> | |
| </div> | |
| <div class="w-full max-w-md bg-white rounded-xl shadow-lg p-6"> | |
| <h2 class="text-2xl font-bold text-gray-800 mb-4">Scoreboard</h2> | |
| <div class="grid grid-cols-2 gap-4"> | |
| <div class="bg-blue-50 p-4 rounded-lg"> | |
| <h3 class="text-lg font-semibold text-blue-700">Player X</h3> | |
| <p id="scoreX" class="text-3xl font-bold text-blue-700">0</p> | |
| </div> | |
| <div class="bg-pink-50 p-4 rounded-lg"> | |
| <h3 class="text-lg font-semibold text-pink-700">Player O</h3> | |
| <p id="scoreO" class="text-3xl font-bold text-pink-700">0</p> | |
| </div> | |
| </div> | |
| </div> | |
| </main> | |
| <footer class="game-footer py-8 px-4"> | |
| <div class="flex flex-col items-center text-center"> | |
| <div class="social-links flex space-x-4 mb-4"> | |
| <a href="#" class="text-gray-300 hover:text-white"> | |
| <i data-feather="github"></i> | |
| </a> | |
| <a href="#" class="text-gray-300 hover:text-white"> | |
| <i data-feather="twitter"></i> | |
| </a> | |
| <a href="#" class="text-gray-300 hover:text-white"> | |
| <i data-feather="instagram"></i> | |
| </a> | |
| </div> | |
| <p class="text-sm text-gray-400">© <span id="currentYear"></span> XOXO Showdown. All rights reserved.</p> | |
| </div> | |
| </footer> | |
| <div id="confettiContainer" class="confetti-container"></div> | |
| <script> | |
| // Game sounds | |
| const sounds = { | |
| click: new Audio('https://assets.mixkit.co/sfx/preview/mixkit-arcade-game-jump-coin-216.mp3'), | |
| win: new Audio('https://assets.mixkit.co/sfx/preview/mixkit-winning-chimes-2015.mp3'), | |
| draw: new Audio('https://assets.mixkit.co/sfx/preview/mixkit-retro-arcade-lose-2027.mp3'), | |
| reset: new Audio('https://assets.mixkit.co/sfx/preview/mixkit-quick-jump-arcade-game-239.mp3'), | |
| background: new Audio('https://assets.mixkit.co/music/preview/mixkit-game-show-suspense-waiting-668.mp3'), | |
| modeChange: new Audio('https://assets.mixkit.co/sfx/preview/mixkit-arcade-mechanical-bling-210.mp3') | |
| }; | |
| sounds.background.loop = true; | |
| // Game state | |
| let board = ['', '', '', '', '', '', '', '', '']; | |
| let autoPlayInterval = null; | |
| let currentPlayer = 'X'; | |
| let gameActive = true; | |
| let gameMode = 'player'; // 'player' or 'ai' | |
| let scores = { X: 0, O: 0 }; | |
| // DOM elements | |
| const bodyElement = document.body; | |
| const boardElement = document.getElementById('gameBoard'); | |
| const currentPlayerElement = document.getElementById('currentPlayer'); | |
| const gameStatusElement = document.getElementById('gameStatus'); | |
| const scoreXElement = document.getElementById('scoreX'); | |
| const scoreOElement = document.getElementById('scoreO'); | |
| const resetButton = document.getElementById('resetGame'); | |
| const playerModeButton = document.getElementById('playerMode'); | |
| const aiModeButton = document.getElementById('aiMode'); | |
| const autoPlayButton = document.getElementById('autoPlay'); | |
| const startAutoPlayButton = document.getElementById('startAutoPlay'); | |
| const confettiContainer = document.getElementById('confettiContainer'); | |
| const currentYearElement = document.getElementById('currentYear'); | |
| // Set current year in footer | |
| currentYearElement.textContent = new Date().getFullYear(); | |
| // Apply dynamic background with animated gradient | |
| function applyDynamicBackground() { | |
| const colors = [ | |
| ['#3B82F6', '#EC4899'], | |
| ['#EC4899', '#10B981'], | |
| ['#10B981', '#F59E0B'], | |
| ['#F59E0B', '#6366F1'], | |
| ['#6366F1', '#3B82F6'], | |
| ['#8B5CF6', '#F43F5E'], | |
| ['#F43F5E', '#14B8A6'] | |
| ]; | |
| const [color1, color2] = colors[Math.floor(Math.random() * colors.length)]; | |
| bodyElement.style.background = `linear-gradient(135deg, ${color1} 0%, ${color2} 100%)`; | |
| bodyElement.style.backgroundAttachment = 'fixed'; | |
| bodyElement.style.backgroundSize = '200% 200%'; | |
| bodyElement.style.animation = 'gradientPulse 6s ease infinite'; | |
| } | |
| // Add gradient animation keyframes to style | |
| const style = document.createElement('style'); | |
| style.textContent = ` | |
| @keyframes gradientPulse { | |
| 0% { background-position: 0% 50%; } | |
| 50% { background-position: 100% 50%; } | |
| 100% { background-position: 0% 50%; } | |
| } | |
| `; | |
| document.head.appendChild(style); | |
| // Create confetti effect | |
| function createConfetti() { | |
| const colors = ['#f44336', '#e91e63', '#9c27b0', '#673ab7', '#3f51b5', '#2196f3', '#03a9f4', '#00bcd4', '#009688', '#4CAF50', '#8BC34A', '#CDDC39', '#FFEB3B', '#FFC107', '#FF9800', '#FF5722']; | |
| confettiContainer.innerHTML = ''; | |
| for (let i = 0; i < 150; i++) { | |
| const confetti = document.createElement('div'); | |
| confetti.className = 'confetti-piece'; | |
| confetti.style.backgroundColor = colors[Math.floor(Math.random() * colors.length)]; | |
| confetti.style.left = `${Math.random() * 100}%`; | |
| confetti.style.width = `${Math.random() * 10 + 5}px`; | |
| confetti.style.height = `${Math.random() * 10 + 5}px`; | |
| confetti.style.animationDuration = `${Math.random() * 3 + 2}s`; | |
| confetti.style.animationDelay = `${Math.random() * 2}s`; | |
| confettiContainer.appendChild(confetti); | |
| setTimeout(() => { | |
| confetti.remove(); | |
| }, 7000); | |
| } | |
| } | |
| // Initialize the game | |
| function initGame() { | |
| if (autoPlayInterval) { | |
| clearInterval(autoPlayInterval); | |
| autoPlayInterval = null; | |
| autoPlayButton.textContent = 'Auto Play'; | |
| autoPlayButton.classList.remove('bg-yellow-500'); | |
| autoPlayButton.classList.add('bg-purple-500'); | |
| } | |
| sounds.background.currentTime = 0; | |
| sounds.background.volume = 0.2; | |
| sounds.background.play(); | |
| board = ['', '', '', '', '', '', '', '', '']; | |
| currentPlayer = 'X'; | |
| gameActive = true; | |
| renderBoard(); | |
| updateGameInfo(); | |
| } | |
| // Render the game board | |
| function renderBoard() { | |
| boardElement.innerHTML = ''; | |
| board.forEach((cell, index) => { | |
| const cellElement = document.createElement('div'); | |
| cellElement.className = `cell bg-gray-50 rounded-lg shadow-md flex items-center justify-center ${cell === 'X' ? 'cell-x' : 'cell-o'}`; | |
| cellElement.textContent = cell; | |
| cellElement.addEventListener('click', () => handleCellClick(index)); | |
| boardElement.appendChild(cellElement); | |
| }); | |
| } | |
| // Auto play mode with enhanced visuals | |
| function toggleAutoPlay() { | |
| if (autoPlayInterval) { | |
| clearInterval(autoPlayInterval); | |
| autoPlayInterval = null; | |
| autoPlayButton.textContent = 'Auto Play'; | |
| autoPlayButton.classList.remove('bg-yellow-500'); | |
| autoPlayButton.classList.add('bg-purple-500'); | |
| gameActive = true; | |
| } else { | |
| sounds.modeChange.play(); | |
| autoPlayButton.textContent = 'Stop Auto Play'; | |
| autoPlayButton.classList.remove('bg-purple-500'); | |
| autoPlayButton.classList.add('bg-yellow-500'); | |
| initGame(); | |
| autoPlayInterval = setInterval(() => { | |
| if (!gameActive) { | |
| setTimeout(() => { | |
| applyDynamicBackground(); | |
| initGame(); | |
| }, 1500); | |
| return; | |
| } | |
| const emptyCells = board.map((cell, index) => cell === '' ? index : null).filter(val => val !== null); | |
| if (emptyCells.length > 0) { | |
| const randomIndex = Math.floor(Math.random() * emptyCells.length); | |
| handleCellClick(emptyCells[randomIndex], true); | |
| } | |
| }, 600); | |
| } | |
| } | |
| // Handle cell click | |
| function handleCellClick(index, isAutoPlay = false) { | |
| if (!gameActive || board[index] !== '') return; | |
| // Make move | |
| sounds.click.play(); | |
| board[index] = currentPlayer; | |
| renderBoard(); | |
| applyDynamicBackground(); | |
| // Check for win or draw | |
| if (checkWin()) { | |
| sounds.win.play(); | |
| createConfetti(); | |
| handleWin(); | |
| } else if (checkDraw()) { | |
| sounds.draw.play(); | |
| handleDraw(); | |
| } else { | |
| // Switch player | |
| currentPlayer = currentPlayer === 'X' ? 'O' : 'X'; | |
| updateGameInfo(); | |
| // AI move if in AI mode | |
| if (gameMode === 'ai' && currentPlayer === 'O' && gameActive) { | |
| setTimeout(makeAIMove, 500); | |
| } | |
| } | |
| } | |
| // AI move logic (simple random move) | |
| function makeAIMove() { | |
| const emptyCells = board.map((cell, index) => cell === '' ? index : null).filter(val => val !== null); | |
| if (emptyCells.length > 0) { | |
| const randomIndex = Math.floor(Math.random() * emptyCells.length); | |
| handleCellClick(emptyCells[randomIndex]); | |
| } | |
| } | |
| // Check for win | |
| function checkWin() { | |
| const winPatterns = [ | |
| [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 | |
| ]; | |
| return winPatterns.some(pattern => { | |
| const [a, b, c] = pattern; | |
| return board[a] !== '' && board[a] === board[b] && board[a] === board[c]; | |
| }); | |
| } | |
| // Check for draw | |
| function checkDraw() { | |
| return board.every(cell => cell !== ''); | |
| } | |
| // Handle win | |
| function handleWin() { | |
| gameActive = false; | |
| scores[currentPlayer]++; | |
| updateScores(); | |
| gameStatusElement.textContent = `Player ${currentPlayer} wins!`; | |
| highlightWinningCells(); | |
| } | |
| // Handle draw | |
| function handleDraw() { | |
| gameActive = false; | |
| gameStatusElement.textContent = "It's a draw!"; | |
| } | |
| // Highlight winning cells | |
| function highlightWinningCells() { | |
| const winPatterns = [ | |
| [0, 1, 2], [3, 4, 5], [6, 7, 8], | |
| [0, 3, 6], [1, 4, 7], [2, 5, 8], | |
| [0, 4, 8], [2, 4, 6] | |
| ]; | |
| const winningPattern = winPatterns.find(pattern => { | |
| const [a, b, c] = pattern; | |
| return board[a] !== '' && board[a] === board[b] && board[a] === board[c]; | |
| }); | |
| if (winningPattern) { | |
| winningPattern.forEach(index => { | |
| boardElement.children[index].classList.add('winning-cell'); | |
| }); | |
| } | |
| } | |
| // Update game info | |
| function updateGameInfo() { | |
| currentPlayerElement.textContent = `Player ${currentPlayer}'s Turn`; | |
| } | |
| // Update scores | |
| function updateScores() { | |
| scoreXElement.textContent = scores.X; | |
| scoreOElement.textContent = scores.O; | |
| } | |
| // Event listeners | |
| resetButton.addEventListener('click', () => { | |
| sounds.reset.play(); | |
| initGame(); | |
| applyDynamicBackground(); | |
| }); | |
| autoPlayButton.addEventListener('click', toggleAutoPlay); | |
| startAutoPlayButton.addEventListener('click', toggleAutoPlay); | |
| playerModeButton.addEventListener('click', () => { | |
| gameMode = 'player'; | |
| playerModeButton.classList.remove('bg-gray-200', 'text-gray-700'); | |
| playerModeButton.classList.add('bg-blue-500', 'text-white'); | |
| aiModeButton.classList.remove('bg-blue-500', 'text-white'); | |
| aiModeButton.classList.add('bg-gray-200', 'text-gray-700'); | |
| initGame(); | |
| }); | |
| aiModeButton.addEventListener('click', () => { | |
| gameMode = 'ai'; | |
| aiModeButton.classList.remove('bg-gray-200', 'text-gray-700'); | |
| aiModeButton.classList.add('bg-blue-500', 'text-white'); | |
| playerModeButton.classList.remove('bg-blue-500', 'text-white'); | |
| playerModeButton.classList.add('bg-gray-200', 'text-gray-700'); | |
| initGame(); | |
| }); | |
| // Initialize with intro animation | |
| document.addEventListener('DOMContentLoaded', () => { | |
| feather.replace(); | |
| setTimeout(() => { | |
| applyDynamicBackground(); | |
| initGame(); | |
| }, 500); | |
| }); | |
| </script> | |
| </body> | |
| </html> |