Skip to content

shailawazeer/Tic-Tac-Toe

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

4 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŽฎ Tic-Tac-Toe Game

A classic Tic-Tac-Toe game built with vanilla JavaScript, HTML, and CSS. Simple, clean, and fun to play!

๐Ÿš€ Features

  • Two-player gameplay - Enter your names and battle it out
  • Smart win detection - Automatically detects wins and ties
  • Clean UI - Responsive design with smooth interactions
  • Modal dialogs - Player name input and winner announcements
  • Game reset - Start fresh anytime

๐ŸŽฏ How to Play

  1. Open tictactoe.html in your browser
  2. Enter both player names in the dialog
  3. Player 1 (X) goes first, then Player 2 (O)
  4. Click any empty cell to place your mark
  5. First to get 3 in a row wins!
  6. Game automatically detects wins, ties, and prevents invalid moves

๐Ÿ› ๏ธ What I Learned

This project helped me practice key JavaScript concepts:

  • Array methods: some() for win detection, forEach() for UI updates
  • Event handling: Click listeners and form submissions
  • DOM manipulation: Dynamic class additions/removals
  • Module pattern: Separating game logic, display, and flow control
  • Data attributes: Using dataset to store cell positions

๐Ÿ“ Project Structure

โ”œโ”€โ”€ tictactoe.html          # Game layout and structure
โ”œโ”€โ”€ style.css           # Styling and responsive design
โ””โ”€โ”€ tictactoe.js           # Game logic and interactions
    โ”œโ”€โ”€ Gameboard()     # Core game state and rules
    โ”œโ”€โ”€ DisplayController() # UI updates and visual feedback
    โ””โ”€โ”€ GameFlow()      # Turn management and game flow

๐ŸŽจ Architecture Highlights

The code follows a modular approach:

  • Gameboard: Handles game state, moves, and win conditions
  • DisplayController: Manages visual updates and CSS classes
  • GameFlow: Controls turns, player management, and game lifecycle

This separation makes the code maintainable and easy to extend!

๐Ÿ”ง Technical Details

  • Win Detection: Uses some() method to efficiently check all 8 winning patterns
  • Turn Management: Boolean flag to alternate between players
  • State Management: Separate game logic from visual representation
  • Event Delegation: Single click listener handles all cell interactions

๐Ÿš€ Quick Start

  1. Clone this repo
  2. Open tictactoe.html in any modern browser
  3. Start playing!

No build process, no dependencies - just pure vanilla JavaScript fun! ๐ŸŽ‰


Built as a learning project to practice JavaScript fundamentals and DOM manipulation.

About

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published