Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/sarahshahab12345/react-tic-tac-toe-game

🎉 **Tic Tac Toe Game** 🕹ī¸ Play the classic Tic Tac Toe in React! This interactive game features scoring, confetti explosions 🎊 for winners, and a fun shake animation đŸ’Ĩ. Enjoy a vibrant design with color-coded X and Y boxes. 🎨 Start a new game or restart with a single click! 🆕🔄 Perfect for quick, casual gaming sessions. 🕰ī¸đŸ‘ž
https://github.com/sarahshahab12345/react-tic-tac-toe-game

animation confetti confetti-animation css fornt-end game gaming html interactive javascript react shake-animation tic-tac-toe uiux web-development

Last synced: 14 days ago
JSON representation

🎉 **Tic Tac Toe Game** 🕹ī¸ Play the classic Tic Tac Toe in React! This interactive game features scoring, confetti explosions 🎊 for winners, and a fun shake animation đŸ’Ĩ. Enjoy a vibrant design with color-coded X and Y boxes. 🎨 Start a new game or restart with a single click! 🆕🔄 Perfect for quick, casual gaming sessions. 🕰ī¸đŸ‘ž

Awesome Lists containing this project

README

        

# React + Vite

This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.

Currently, two official plugins are available:

- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh

## Tic Tac Toe Game - Functionality

### Overview
This React-based Tic Tac Toe game allows two players to play against each other, tracks scores, and provides visual feedback with animations when someone wins.

### How It Works

#### State Management
- **BoxValues**: An array representing the 3x3 grid, initially filled with empty strings.
- **XTurn**: A boolean indicating whether it is player X's turn.
- **XScore & YScore**: Track the scores for players X and Y.
- **status**: Displays the current game status (whose turn it is, or who won).
- **isGameOn**: Boolean indicating if the game is active.
- **winner**: Stores the winner ("X" or "Y") if there is one.

#### Gameplay
- **handleOnBoxClick(index)**:
- Updates the grid cell to "X" or "Y" depending on the current turn if the cell is empty.
- Toggles the turn between X and Y.
- The click is only registered if `isGameOn` is true.

#### Winner Checking
- **checkWinner()**:
- Defines winning patterns for Tic Tac Toe.
- Checks if any of the winning patterns match the current state of the grid.
- If a player wins, updates the score, status message, and stops the game.
- If the grid is full and no winner is found, it declares a draw.

#### Game Control
- **startPlay()**:
- Resets the game and sets it to active.
- **clear()**:
- Clears the grid and updates the status to indicate which player starts.

#### Visual Effects
- **Confetti**: Appears when there is a winner, adding a celebratory effect.
- **Shake Animation**: Adds a shake effect to the game container when a player wins.

#### User Interface
- **Grid**: Clickable 3x3 grid where players make their moves.
- **Score Display**: Shows the current scores of X and Y.
- **Status**: Displays messages like whose turn it is or who won.
- **Start/Restart Button**: Allows starting a new game or restarting the current game.