Skip to content

A modern Tetris game implementation built with React and Vite

Notifications You must be signed in to change notification settings

ansharmuhammad/tetris

Repository files navigation

React Tetris Game

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

๐ŸŽฎ Features

  • 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

๐Ÿ› ๏ธ Tech Stack

  • React - Frontend library for building user interfaces
  • Vite - Next generation frontend tooling
  • Tailwind CSS - Utility-first CSS framework
  • ESLint - Code linting and style enforcement

๐Ÿš€ Getting Started

Prerequisites

  • Node.js (v14 or higher)
  • npm or yarn package manager

Installation

  1. Clone the repository:

    git clone https://github.com/yourusername/tetris.git
    cd tetris
  2. Install dependencies:

    npm install
    # or
    yarn
  3. Start the development server:

    npm run dev
    # or
    yarn dev
  4. Open http://localhost:5173 in your browser

๐ŸŽฏ Game Controls

  • โ† โ†’ : Move piece left/right
  • โ†‘ : Rotate piece
  • โ†“ : Move piece down
  • P : Pause/Resume game

๐Ÿ—๏ธ Project Structure

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

๐ŸŽฒ Game Components

TetrisGame.jsx

Main game component that handles:

  • Game board state management
  • Piece movement and rotation
  • Collision detection
  • Score tracking
  • Game loop
  • User input handling

Key Game Mechanics

  1. Board Management

    • 10x20 grid using 2D array
    • Null cells for empty spaces
    • Color values for filled spaces
  2. Piece Movement

    • Horizontal movement with collision detection
    • Downward movement with floor/piece collision
    • Rotation with wall kick system
  3. Line Clearing

    • Detection of filled rows
    • Score calculation

๐Ÿค Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

๐Ÿ“ Development Guidelines

  1. Code Style

    • Follow ESLint configuration
    • Use functional components and hooks
    • Maintain consistent naming conventions
  2. State Management

    • Use React hooks for state management
    • Keep game logic separate from UI components
    • Implement proper cleanup in useEffect
  3. Testing

    • Write unit tests for game logic
    • Test component rendering and interactions
    • Ensure game mechanics work as expected

๐Ÿ“„ License

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

๐Ÿ™ Acknowledgments

  • Original Tetris game by Alexey Pajitnov
  • React and Vite communities
  • Contributors and maintainers

Made with โค๏ธ by Muhammad Anshar

About

A modern Tetris game implementation built with React and Vite

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published