Files

3.7 KiB
Raw Permalink Blame History

-=:dAs:=- Tetris

Classic Tetris on Python + pygame with configurable blocks, colors and controls

Python pygame PyInstaller

🇺🇦 Українська версія

💡 Purpose

A desktop Tetris game where the set of pieces, their colors, the unlock score for each piece, the field width, block size, colors and keys are described in JSON files – so the game can be extended with new shapes without touching the code.

📃 Features

  • Gameplay – falling pieces, rotation, line clearing, score and lines counter, next-piece preview
  • Progressive pieces – 23 shapes, new ones unlock as the score grows
  • Configuration – keys, colors, field width, block size and speed mode in JSON
  • Pause, restart and exit confirmation dialog (mouse or Y/N keys)

⭐ Advantages

  • Data-driven shapes – any new piece is a few lines of JSON: name, color, minimal score and a list of rotations.
  • Safe defaults – committed *_000.json defaults are used automatically when local configs are absent.
  • Runs from anywhere – configs are resolved next to the script or the built executable, not the current directory.
  • Clear config errors – broken JSON or a missing key stops the game with a message naming the file and key.

📱 Screenshots

Game Logo
Game field Logo

📌 Using

Gameplay

Standard Tetris rules on a 20-row field

  • ← / → – move, ↑ – rotate, ↓ – drop one row
  • P – pause, R – restart, Esc – exit (with confirmation)
  • Score for cleared lines at once: 1 – 100, 2 – 300, 3 – 500, 4 – 800
  • The next piece is always different from the current one

Progressive pieces

The higher the score, the more varied the pieces

  • 8 base shapes (configs/blocks.json): Square, Line, Line3 and L from the start; J from 900, S from 1000, Z and T from 2500 points
  • 15 additional shapes (configs/blocks_ADD.json, optional): Dot, U, Corner, X, P, F and others, unlocked from 3500 up to 30000 points
  • Above 5000, 10000 and 15000 points the falling speed changes

Configuration

All settings live in configs/

  • config.json – keys (pygame key names, e.g. K_LEFT), controls help text, colors, store_width (field width in blocks), block_size (pixels), high_score_inc_speed
  • high_score_inc_speed: false – the game speeds up as the score grows, true – it slows down
  • blocks.json / blocks_ADD.json – pieces: name, color [r, g, b], min_score, shapes (list of clockwise rotations, 0/1 matrices); at least one piece must have min_score 0
  • If a local file is missing, its *_000.json default is used

🚀 Running

Requirements: Python 3.12, pygame 2.6.

python3 -m venv .venv
.venv/bin/pip install -r requirements.txt
.venv/bin/python das_tetris_gui.py                  # start the game
.venv/bin/python -m unittest discover -s tests -v   # run tests
.venv/bin/pip install pyinstaller
.venv/bin/pyinstaller --onefile das_tetris_gui.py   # build a single executable into dist/

The executable reads configs from a configs/ folder located next to it.

Made by -=:dAs:=-