Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

6 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŽฎ Tic-Tac-Toe | Interactive JavaScript Web Game

HTML5 CSS3 JavaScript FontAwesome GitHub Pages

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.


๐Ÿš€ Live Demo

Play Now


โœจ Features

  • ๐Ÿ–ฅ๏ธ 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

๐Ÿ•น๏ธ How to Play

  1. Open the app and click Start
  2. Choose your mode:
    • ๐Ÿ–ฅ๏ธ Play Against Computer โ€” You are X, Computer is O
    • ๐Ÿซ‚ Play with a Friend โ€” Take turns on the same device
  3. Click on a cell to place your mark
  4. The game announces the winner or a draw automatically

๐Ÿ—‚๏ธ Project Structure

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

๐Ÿง  Game Logic โ€” How It Works

Win Detection Algorithm

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
];

Board Layout (cell IDs)

 0 | 1 | 2
-----------
 3 | 4 | 5
-----------
 6 | 7 | 8

Architecture

User clicks "Start"
     โ”‚
     โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Mode Selection        โ”‚
โ”‚  ๐Ÿ–ฅ๏ธ Computer  ๐Ÿซ‚ Friend โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
        โ”‚        โ”‚
        โ–ผ        โ–ผ
   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
   โ”‚ Board1  โ”‚ โ”‚ Board2  โ”‚
   โ”‚ (vs AI) โ”‚ โ”‚ (vs 2P) โ”‚
   โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”˜
        โ”‚            โ”‚
        โ–ผ            โ–ผ
   checkWinner()  checkWinnerFriend()
        โ”‚            โ”‚
        โ–ผ            โ–ผ
   Display result in scoreboard

๐Ÿ“ฑ Responsive Breakpoints

Breakpoint Target Changes
> 768px Desktop Side-by-side board + scoreboard
โ‰ค 768px Tablet Stacked layout, smaller heading
โ‰ค 480px Mobile Vertical mode buttons, compact board (240px)

๐Ÿ› ๏ธ Tech Stack

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

๐Ÿ“š Concepts Demonstrated

  • DOM Manipulation โ€” querySelector, querySelectorAll, innerText
  • Event Handling โ€” addEventListener('click', ...)
  • State Management โ€” Board arrays, gameActive flags, currentPlayer tracking
  • Conditional Logic โ€” Win/draw detection with nested loops
  • CSS Animations โ€” @keyframes for typewriter and cursor effects
  • Responsive Design โ€” Flexbox, Grid, and @media queries
  • Multi-page Navigation โ€” window.location.href for page routing

๐Ÿš€ Run Locally

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.html

๐Ÿค Contributing

Feel free to fork this project and customize it. If you find bugs or have suggestions, please open an issue.

๐Ÿชช License

This project is open-source and available under the MIT License.


Built with ๐Ÿ’– by Madhav P

About

๐Ÿ•น๏ธ A simple and interactive Tic-Tac-Toe game developed using HTML, CSS, and JavaScript. Features responsive design, multiplayer mode, and computer opponent gameplay. ๐ŸŽฎ

Topics

Resources

Stars

Watchers

Forks

Contributors

Languages