A modern implementation of the classic Tetris game built with React, featuring smooth animations, and sound effects. This project demonstrates React hooks usage, game state management.
- Classic Tetris gameplay mechanics
- Smooth piece movement and rotation
- Next piece preview
- Score tracking
- Background music and sound effects
- Pause/Resume functionality
- Game Over state with restart option
- Responsive design with beautiful UI
- React - Frontend library for building user interfaces
- Vite - Next generation frontend tooling
- Tailwind CSS - Utility-first CSS framework
- ESLint - Code linting and style enforcement
- Node.js (v14 or higher)
- npm or yarn package manager
-
Clone the repository:
git clone https://github.com/yourusername/tetris.git cd tetris
-
Install dependencies:
npm install # or yarn
-
Start the development server:
npm run dev # or yarn dev
-
Open http://localhost:5173 in your browser
- โ โ : Move piece left/right
- โ : Rotate piece
- โ : Move piece down
- P : Pause/Resume game
tetris/
โโโ public/
โ โโโ sound/ # Game sound effects
โโโ src/
โ โโโ components/ # React components
โ โโโ styles/ # CSS styles
โ โโโ assets/ # Static assets
โ โโโ App.jsx # Root component
โโโ package.json # Dependencies and scripts
โโโ vite.config.js # Vite configuration
Main game component that handles:
- Game board state management
- Piece movement and rotation
- Collision detection
- Score tracking
- Game loop
- User input handling
-
Board Management
- 10x20 grid using 2D array
- Null cells for empty spaces
- Color values for filled spaces
-
Piece Movement
- Horizontal movement with collision detection
- Downward movement with floor/piece collision
- Rotation with wall kick system
-
Line Clearing
- Detection of filled rows
- Score calculation
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature
) - Commit your changes (
git commit -m 'Add some AmazingFeature'
) - Push to the branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
-
Code Style
- Follow ESLint configuration
- Use functional components and hooks
- Maintain consistent naming conventions
-
State Management
- Use React hooks for state management
- Keep game logic separate from UI components
- Implement proper cleanup in useEffect
-
Testing
- Write unit tests for game logic
- Test component rendering and interactions
- Ensure game mechanics work as expected
This project is open source and available under the MIT License.
- Original Tetris game by Alexey Pajitnov
- React and Vite communities
- Contributors and maintainers
Made with โค๏ธ by Muhammad Anshar