Skip to content

sultanofficial717/Python-Tetris-Game-

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

5 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŽฎ Python Tetris Game - Complete Educational Implementation

Python Version Pygame License PRs Welcome

A professional, well-documented Tetris game built with Python and Pygame - Perfect for learning game development, understanding code architecture, and educational purposes.

๐Ÿ“– Table of Contents

๐ŸŽฏ Overview

This is a complete, production-ready Tetris game implementation in Python using the Pygame library. Designed with clean code architecture, comprehensive documentation, and educational purposes in mind, this project serves as an excellent resource for:

  • ๐ŸŽ“ Students learning Python game development
  • ๐Ÿ‘จโ€๐Ÿ’ป Developers studying game architecture patterns
  • ๐Ÿ“š Educators teaching programming concepts
  • ๐ŸŽฎ Game enthusiasts exploring classic game mechanics

Why This Project?

Unlike basic Tetris implementations, this project features:

  • โœจ Modular architecture with separation of concerns
  • ๐Ÿ“ Extensive inline documentation explaining every concept
  • ๐ŸŽจ Professional UI/UX with multiple game screens
  • ๐Ÿ† Complete game features including scoring, levels, and high scores
  • ๐Ÿ”ง Easily extendable codebase for adding new features
  • ๐Ÿ“– Educational documentation explaining game development concepts

โœจ Features

๐ŸŽฎ Core Gameplay

  • 7 Classic Tetromino Shapes (I, O, T, Z, S, L, J blocks)
  • Smooth Piece Rotation with wall-kick implementation
  • Ghost Piece Preview showing landing position
  • Next Piece Display for strategic planning
  • Hard Drop & Soft Drop for advanced gameplay
  • Progressive Difficulty with increasing speed levels

๐Ÿ† Game Systems

  • Scoring System with combo multipliers
    • Single line: 100 points
    • Double lines: 250 points
    • Triple lines: 500 points
    • Tetris (4 lines): 1000 points
  • Level Progression (speed increases every 10 lines)
  • High Score Tracking
  • Lines Cleared Counter
  • Player Name System

๐ŸŽจ User Interface

  • Welcome Screen with game introduction
  • Player Login Screen for personalized experience
  • Game Header displaying score, level, and player info
  • Sidebar with next piece preview and controls guide
  • Pause Menu (press P to pause/unpause)
  • Game Over Screen with restart option
  • Professional Color Scheme optimized for visibility

๐Ÿ› ๏ธ Technical Features

  • Object-Oriented Design with clean class structure
  • Modular Code Architecture for easy maintenance
  • Configuration Management with centralized settings
  • Grid-Based Collision Detection
  • Event-Driven Input Handling
  • FPS-Limited Game Loop for consistent performance
  • Comprehensive Error Handling

๐Ÿ“ธ Screenshots

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ TETRIS GAME โ”‚ โ”‚ Player: YourName Level: 5 โ”‚ โ”‚ Score: 2500 High: 5000 โ”‚ โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค โ”‚ โ”‚ NEXT: โ”‚ โ”‚ โ–“โ–“ โ”‚ โ”Œโ”€โ”€โ” โ”‚ โ”‚ โ–“โ–“โ–“โ–“ โ”‚ โ”‚โ–“โ–“โ”‚ โ”‚ โ”‚ โ–“โ–“ โ”‚ โ””โ”€โ”€โ”˜ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ–“ โ–“โ–“ โ”‚ CONTROLS: โ”‚ โ”‚ โ–“ โ–“ โ”‚ โ†/โ†’ : Move โ”‚ โ”‚ โ–“ โ–“ โ”‚ โ†“ : Soft Drop โ”‚ โ”‚ โ–“โ–“โ–“โ–“โ–“ โ”‚ โ†‘ : Rotate โ”‚ โ”‚ โ”‚ SPACE: Hard Drop โ”‚ โ”‚ โ”‚ P : Pause โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ 

๐Ÿš€ Installation

Prerequisites

  • Python 3.7 or higher
  • pip (Python package installer)

Step-by-Step Installation

  1. Clone the repository

    git clone https://github.com/sultanofficial717/Python-Tetris-Game-.git cd Python-Tetris-Game-
  2. Create a virtual environment (recommended)

    # On Windows python -m venv .venv .venv\Scripts\activate # On macOS/Linux python3 -m venv .venv source .venv/bin/activate
  3. Install dependencies

    pip install -r requirements.txt

    Or install Pygame directly:

    pip install pygame
  4. Run the game

    python main.py

Quick Start (No Installation)

If you just want to try it quickly:

pip install pygame python main.py

๐ŸŽฏ How to Play

Game Objective

Arrange falling tetromino blocks to create complete horizontal lines, which will then disappear. The game ends when blocks stack to the top of the playing field.

Controls

Key Action
โ† Move piece left
โ†’ Move piece right
โ†“ Soft drop (move down faster)
โ†‘ Rotate piece clockwise
SPACE Hard drop (instant drop to bottom)
P Pause/Unpause game
ESC Quit to main menu

Gameplay Tips

  1. Plan Ahead - Use the next piece preview to strategize
  2. Create Tetrises - Clearing 4 lines at once gives maximum points
  3. Use Ghost Piece - The outline shows where your piece will land
  4. Speed Up - Use soft drop for bonus points
  5. Hard Drop - Use space bar for instant placement and 2x points

Scoring

  • 1 Line = 100 points
  • 2 Lines = 250 points (2.5x multiplier)
  • 3 Lines = 500 points (5x multiplier)
  • 4 Lines (Tetris!) = 1000 points (10x multiplier)
  • Soft Drop = 1 point per cell
  • Hard Drop = 2 points per cell

๐Ÿ“ Project Structure

Python-Tetris-Game-/ โ”‚ โ”œโ”€โ”€ main.py # Entry point - simplified launcher โ”œโ”€โ”€ requirements.txt # Python dependencies โ”œโ”€โ”€ setup.py # Package installation script โ”œโ”€โ”€ README.md # This file โ”œโ”€โ”€ LICENSE # MIT License โ”œโ”€โ”€ CONTRIBUTING.md # Contribution guidelines โ”œโ”€โ”€ .gitignore # Git ignore rules โ”‚ โ”œโ”€โ”€ src/ # Source code modules โ”‚ โ”œโ”€โ”€ __init__.py # Package initialization โ”‚ โ”œโ”€โ”€ config.py # Game configuration and constants โ”‚ โ”œโ”€โ”€ tetromino.py # Tetromino class (game pieces) โ”‚ โ”œโ”€โ”€ grid.py # Grid management and collision detection โ”‚ โ”œโ”€โ”€ game.py # Main game logic and loop โ”‚ โ””โ”€โ”€ ui.py # User interface rendering โ”‚ โ”œโ”€โ”€ docs/ # Documentation โ”‚ โ”œโ”€โ”€ GAME_MECHANICS.md # Detailed game mechanics explanation โ”‚ โ”œโ”€โ”€ CODE_STRUCTURE.md # Architecture and design patterns โ”‚ โ”œโ”€โ”€ TUTORIAL.md # Step-by-step development guide โ”‚ โ””โ”€โ”€ API_REFERENCE.md # Code API documentation โ”‚ โ”œโ”€โ”€ assets/ # Game assets (future: sounds, images) โ”‚ โ””โ”€โ”€ README.md # Asset documentation โ”‚ โ””โ”€โ”€ tests/ # Unit tests (future implementation) โ”œโ”€โ”€ __init__.py โ”œโ”€โ”€ test_tetromino.py โ”œโ”€โ”€ test_grid.py โ””โ”€โ”€ test_game.py 

๐ŸŽ“ Educational Value

This project is designed as a comprehensive learning resource for:

1. Python Programming Concepts

  • Object-Oriented Programming (OOP)
  • Class inheritance and composition
  • Module organization
  • List comprehensions
  • Type hints and documentation

2. Game Development Fundamentals

  • Game loop architecture
  • Frame rate control
  • Input handling
  • Collision detection
  • State management
  • Rendering pipeline

3. Pygame Library

  • Display management
  • Event handling
  • Drawing primitives
  • Font rendering
  • Clock and timing
  • Surface manipulation

4. Software Engineering Practices

  • Code organization and modularity
  • Configuration management
  • Documentation standards
  • Version control (Git)
  • Code reusability
  • Design patterns

5. Algorithm Implementation

  • Matrix rotation (for piece rotation)
  • Grid-based collision detection
  • Row clearing algorithm
  • Scoring systems
  • Level progression

๐Ÿ“š Code Documentation

All code is extensively documented with:

  • Module docstrings explaining file purpose
  • Class docstrings describing class responsibilities
  • Method docstrings detailing parameters and return values
  • Inline comments explaining complex logic
  • Educational notes teaching concepts

Example from tetromino.py:

def rotate_clockwise(self): """  Rotate the tetromino 90 degrees clockwise.    Algorithm: Transpose the matrix then reverse each row  Example:  [1, 0] [1, 1]  [1, 1] -> [0, 1]    This is a common matrix rotation technique used in games.  """ transposed = list(zip(*self.shape[::-1])) self.shape = [list(row) for row in transposed]

๐Ÿค Contributing

Contributions are welcome! This is an educational project, so please maintain the documentation standards.

See CONTRIBUTING.md for guidelines on:

  • Code style
  • Documentation requirements
  • Pull request process
  • Feature suggestions

Ideas for Contributions

  • Add sound effects and music
  • Implement hold piece feature
  • Add difficulty modes
  • Create custom themes
  • Add multiplayer support
  • Implement replay system
  • Add unit tests
  • Create additional documentation

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

You are free to:

  • โœ… Use this code for learning
  • โœ… Modify and extend the code
  • โœ… Use in personal or commercial projects
  • โœ… Share and distribute

๐Ÿ” SEO Keywords

Primary Keywords:

  • Python Tetris game
  • Pygame Tetris tutorial
  • Python game development
  • Tetris implementation Python
  • Learn Python with games
  • Python Pygame project
  • Tetris source code Python

Secondary Keywords:

  • Python gaming tutorial
  • Object-oriented game development
  • Python educational project
  • Pygame game example
  • Classic game Python implementation
  • Python coding project
  • Game development for beginners
  • Python Tetris complete code
  • Professional Python game
  • Python game architecture

Educational Keywords:

  • Learn game development Python
  • Python programming tutorial
  • Pygame tutorial complete
  • Python OOP example
  • Game loop Python
  • Collision detection Python
  • Matrix rotation algorithm
  • Python project for students

๐ŸŒŸ Why Learn from This Project?

  1. Complete Implementation - Not a half-finished tutorial
  2. Professional Standards - Real-world code quality
  3. Extensive Documentation - Understand every line
  4. Modular Design - Learn proper code organization
  5. Best Practices - Follow Python conventions
  6. Active Learning - Modify and extend the code
  7. Portfolio Ready - Showcase your skills

๐Ÿ“ž Support & Contact

โญ Show Your Support

If you found this project helpful:

  • โญ Star this repository
  • ๐Ÿด Fork and create your own version
  • ๐Ÿ“ข Share with others learning Python
  • ๐Ÿ› Report bugs or suggest features
  • ๐Ÿ“– Improve documentation

Happy Coding! ๐ŸŽฎ Learn by doing, master by understanding.

Made with โค๏ธ for the Python learning community

Releases

No releases published

Packages

No packages published

Languages