A modern, interactive tic-tac-toe game built with HTML, CSS, and JavaScript featuring both Player vs Player and Player vs AI modes.
๐ Live site: https://rohanraaj2.github.io/Tic-Tac-Toe/
- Player vs Player Mode: Two players can play against each other
- Player vs AI Mode: Play against an intelligent AI opponent
- Interactive Game Board: Click on cells to place your markers
- Win Detection: Automatically detects winning conditions and highlights winning cells
- Draw Detection: Recognizes when the game ends in a draw
- Modern Design: Beautiful gradient background with glassmorphism effects
- Responsive Layout: Works perfectly on desktop, tablet, and mobile devices
- Smooth Animations: Engaging hover effects, transitions, and winner animations
- Game Modal: Displays game results with options to play again
- Score Tracking: Keeps track of wins and draws with persistent storage
- Keyboard Support: Use number keys 1-9 to place markers, ESC to close modals
- Sound Effects: Audio feedback for moves and game events (optional)
- Game Analytics: Track game statistics and history
- Local Storage: Scores persist between browser sessions
- A modern web browser (Chrome, Firefox, Safari, Edge)
- No additional installations required!
- Clone this repository or download the files
- Open
index.html
in your web browser - Start playing immediately!
PRODIGY_WD_03/
โโโ index.html # Main HTML structure
โโโ style.css # CSS styling and animations
โโโ script.js # JavaScript game logic
โโโ README.md # Project documentation
- The game is played on a 3ร3 grid
- Players take turns placing their markers (X or O)
- The first player to get 3 markers in a row (horizontally, vertically, or diagonally) wins
- If all 9 cells are filled without a winner, the game is a draw
- Mouse: Click on any empty cell to place your marker
- Keyboard: Press number keys 1-9 to place markers in corresponding positions
- Game Modes: Switch between Player vs Player and Player vs AI
- Reset: Use "Reset Game" to start a new game or "Reset Score" to clear statistics
The AI opponent uses an intelligent strategy:
- Win: Attempts to complete three in a row
- Block: Prevents the player from winning
- Center: Takes the center position when available
- Corners: Prioritizes corner positions
- Edges: Falls back to edge positions
Edit style.css
to customize:
- Color schemes and gradients
- Animation speeds and effects
- Layout and spacing
- Responsive breakpoints
The modular JavaScript structure allows easy extension:
- Add new game modes
- Implement different AI difficulties
- Add multiplayer networking
- Create tournament modes
- HTML5: Semantic structure and accessibility
- CSS3: Modern styling with flexbox, grid, and animations
- JavaScript ES6+: Object-oriented game logic and DOM manipulation
- Chrome 60+
- Firefox 55+
- Safari 12+
- Edge 79+
- Efficient DOM manipulation
- CSS hardware acceleration
- Optimized animations
- Minimal memory footprint
The game is fully optimized for mobile devices:
- Touch-friendly interface
- Responsive design adapts to all screen sizes
- Optimized button sizes for touch interaction
- Portrait and landscape orientation support
- Clone the repository
- Open
index.html
in your browser - Make changes to the files
- Refresh the browser to see updates
- TicTacToe Class: Main game logic and state management
- GameAnalytics Class: Statistics tracking and history
- SoundManager Class: Audio effects management
- Utility Functions: Helper functions for UI enhancements
1-9
: Place marker in corresponding cellESC
: Close modal dialogsR
: Reset current game (when implemented)
- Keyboard navigation support
- Screen reader friendly
- High contrast mode compatible
- Focus indicators for all interactive elements
Feel free to fork this project and submit pull requests for:
- Bug fixes
- Feature enhancements
- Performance improvements
- Documentation updates
This project is open source and available under the MIT License.
This site includes Google Analytics for traffic tracking. No personal data is collected.
Created as part of the PRODIGY Web Development internship program.
Enjoy playing Tic-Tac-Toe! ๐ฎ