A dual-mode Tic-Tac-Toe game built entirely with vanilla HTML, CSS, and JavaScript โ no frameworks, no libraries. Features Player vs Computer and Player vs Friend modes with responsive design, smooth animations, and win detection.
- ๐ฅ๏ธ Player vs Computer โ Play against a random AI opponent
- ๐ซ Player vs Friend โ Local multiplayer on the same device
- ๐ Win Detection โ Checks all 8 combinations (3 rows, 3 columns, 2 diagonals)
- โจ Winning Highlight โ Line-through effect with color change on winning cells
- ๐ค Draw Detection โ Automatically announces a draw when the board is full
- ๐ Auto Reset โ Board resets when switching between modes
- ๐ฌ Typewriter Animation โ Animated welcome text on the landing page
- ๐ฑ Fully Responsive โ Desktop, Tablet, and Mobile layouts
- ๐ Hover Effects โ Interactive feedback on cells and buttons
- Open the app and click Start
- Choose your mode:
- ๐ฅ๏ธ Play Against Computer โ You are X, Computer is O
- ๐ซ Play with a Friend โ Take turns on the same device
- Click on a cell to place your mark
- The game announces the winner or a draw automatically
Tic-Tac-Toe/
โโโ index.html # Landing page (Welcome + Start button)
โโโ Second.html # Game page (Mode selection + Boards)
โโโ Style.css # Landing page styles (responsive)
โโโ Style2.css # Game page styles (responsive)
โโโ Logic.js # Game logic (navigation, modes, win detection)
โโโ Readme.md # This file
The game checks all 8 possible winning combinations after every move:
let Possibilities = [
[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
]; 0 | 1 | 2
-----------
3 | 4 | 5
-----------
6 | 7 | 8
User clicks "Start"
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Mode Selection โ
โ ๐ฅ๏ธ Computer ๐ซ Friend โ
โโโโโโโโโฌโโโโโโโโโฌโโโโโโโโ
โ โ
โผ โผ
โโโโโโโโโโโ โโโโโโโโโโโ
โ Board1 โ โ Board2 โ
โ (vs AI) โ โ (vs 2P) โ
โโโโโโฌโโโโโ โโโโโโฌโโโโโ
โ โ
โผ โผ
checkWinner() checkWinnerFriend()
โ โ
โผ โผ
Display result in scoreboard
| Breakpoint | Target | Changes |
|---|---|---|
> 768px |
Desktop | Side-by-side board + scoreboard |
โค 768px |
Tablet | Stacked layout, smaller heading |
โค 480px |
Mobile | Vertical mode buttons, compact board (240px) |
| Technology | Purpose |
|---|---|
| HTML5 | Semantic page structure |
| CSS3 | Styling, animations, media queries |
| JavaScript (ES6+) | Game logic, DOM manipulation, events |
| FontAwesome 6.5 | Icons (home, social links) |
| CSS Animations | Typewriter effect, hover transitions |
- DOM Manipulation โ
querySelector,querySelectorAll,innerText - Event Handling โ
addEventListener('click', ...) - State Management โ Board arrays,
gameActiveflags,currentPlayertracking - Conditional Logic โ Win/draw detection with nested loops
- CSS Animations โ
@keyframesfor typewriter and cursor effects - Responsive Design โ Flexbox, Grid, and
@mediaqueries - Multi-page Navigation โ
window.location.hreffor page routing
No build tools needed โ just open in a browser!
# Clone the repository
git clone https://github.com/Madhav-P-2005/Tic-Tac-Toe.git
# Open index.html in your browser
# On Windows:
start index.html
# On Mac:
open index.htmlFeel free to fork this project and customize it. If you find bugs or have suggestions, please open an issue.
This project is open-source and available under the MIT License.
Built with ๐ by Madhav P