Tic Tac Toe Blogger Gadget – 3D Look + Animations
Bring fun and interactivity to your blog with a stylish 3D game.
🎯 Introduction
This Blogger gadget is a fully interactive Tic Tac Toe game with a 3D look, smooth animations, confetti celebrations, and even an AI opponent. You can simply paste the code into Layout → Add a Gadget → HTML/JavaScript and it works right away.
📦 Structure of the Gadget
The gadget has three main parts:
- HTML: The board, buttons, and controls.
- CSS: Styling for the 3D board, animations, and theme.
- JavaScript: Game logic, AI, and animations.
🔹 HTML Layout
The HTML sets up the interface:
<div id="tictactoe-gadget">
<header>... Title and Subtitle ...</header>
<div class="options">... X or O choice ...</div>
<div class="board-wrap">
<div id="board" class="board"></div>
</div>
<div class="controls">
<button>New Game</button>
<button>Hint</button>
<button>Reset Score</button>
</div>
<div class="status">Ready</div>
</div>
- The .board
holds 9 cells.
- The .controls
let players reset, get hints, and reset scores.
- The .status
shows messages like “Your move”.
🎨 CSS Styling
The CSS gives the game its 3D and animated look:
- Cells use shadows, gradients, and hover tilts for depth.
- Board flips in at the start (
@keyframes boardFlipIn
). - Winning cells pulse with
@keyframes winPulse
. - Draws trigger a quick board shake animation.
⚙️ JavaScript Logic
The script handles gameplay:
// Track game state
let board = Array(9).fill(null);
let human = 'X';
let ai = 'O';
let currentPlayer = 'X';
let gameOver = false;
// Handle click on a cell
function onCellClick(i){
if(gameOver || board[i] || currentPlayer !== human) return;
makeMove(i, human);
update();
if(!gameOver) setTimeout(aiTurn, 260);
}
AI with Minimax
The “Hard” mode uses the Minimax algorithm – a classic AI approach that explores all possible moves to always play optimally. The “Easy” mode picks a random empty cell.
Animations & Effects
animateCellPop()
: makes newly placed marks pop.burstConfetti()
: throws colorful confetti when someone wins.draw-shake
: shakes the board in case of a draw.
📊 Score & Controls
Scores are tracked for both X and O. You can reset the game (New Game), clear scores (Reset Score), or get the AI to show you the best move (Hint).
🚀 How to Add to Blogger
- Go to your Blogger dashboard.
- Click Layout → Add a Gadget → HTML/JavaScript.
- Paste the gadget code inside.
- Save and refresh your blog – your readers can now play!
✨ Conclusion
With this Tic Tac Toe gadget, you’re adding both fun and professional style to your blog. The mix of AI, 3D visuals, and smooth animations will keep visitors engaged while showing your tech creativity.
0 Comments