Skip to main content

A tetris game runs in the terminal

Project description

gameplay
English | ไธญๆ–‡

Tetris Terminal๐ŸŽฎ

A terminal-based Tetris game written in Python using the curses library.

License: MIT Python 3.9+

Features

  • Modern Tetris design following the Tetris Design Guideline
    • Extended Placement
    • Next Piece Preview
    • SRS System
    • Piece Holding
    • Shadow Piece
    • Modern Scoring System
    • Modern Level System

Platform Support

Based on Python's curses module:

  • โœ… Linux/macOS: Works out of the box
  • โœ…๏ธ Windows: With windows-curses
  • Can run on basically any terminal setup, even a linux tty.

Installation & Usage

pip install tetris-terminal
tetris

Controls

Key Action
a, โ† Move left
d, โ†’ Move right
w, โ†‘,x Rotate cw
z Rotate ccw
s, โ†“ Soft drop
space Hard drop
c Hold
p Pause
q Quit game

CLI Options

Option Description
--generate-config Generate a default config file and exit
--disable-config Ignore config file and run with built-in defaults
--version Show version and exit

Multiplayer (Versus Mode)

Compete in real-time 1v1 battles over WebSocket. Clear lines to send garbage to your opponent โ€” the last player standing wins.

โ”Œโ”€ Server โ”€โ”      โ”Œโ”€ Client A โ”€โ”      โ”Œโ”€ Client B โ”€โ”
โ”‚           โ”‚ โ†โ”€โ”€โ†’ โ”‚  game loop โ”‚      โ”‚  game loop  โ”‚
โ”‚   Room    โ”‚      โ”‚            โ”‚ โ†โ”€โ”€โ†’ โ”‚             โ”‚
โ”‚           โ”‚ โ†โ”€โ”€โ†’ โ”‚  network   โ”‚      โ”‚  network    โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜      โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜      โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Quick Start

# Terminal 1 โ€” start the server
tetris-server

# Terminal 2 โ€” connect client A
tetris --server localhost:8765

# Terminal 3 โ€” connect client B
tetris --server localhost:8765

Once both clients connect, the server matches them and the battle begins.

CLI

Command Description
tetris-server Start the WebSocket matchmaking server
tetris Launch the game in single-player modes
tetris --server HOST:PORT Launch the game in multiplayer mode

tetris-server Options

Option Default Description
--host 0.0.0.0 Host address to bind
--port 8765 Port to listen on
--version Show version and exit

tetris --server Options

Option Description
--server HOST:PORT Connect to a multiplayer server (default: localhost:8765)
--disable-config Ignore config file and run with built-in defaults
--version Show version and exit

Gameplay

  • Garbage system: Each cleared line generates garbage based on the standard Tetris scoring โ€” more lines at once send more garbage.
  • Incoming garbage is shown as a Garbage counter on the side panel.
  • Garbage cancellation: Clearing lines while you have pending garbage cancels an equal number of incoming lines.
  • No pause: Versus mode disables pause to keep both players in sync.
  • Opponent disconnect: If the opponent disconnects, the match ends immediately.

Configuration

multi_play

Connection settings for multiplayer mode.

Key Default Description
host "localhost" Server hostname or IP
port 8765 Server port

Configuration

On first run, or via tetris --generate-config, a configuration file is created at:

Platform Path
Linux ~/.config/tetris-terminal/config.json
macOS ~/Library/Application Support/tetris-terminal/config.json
Windows %APPDATA%/tetris-terminal/config.json

The config file references a JSON Schema for editor autocompletion and validation. All fields are optional โ€” missing keys fall back to their defaults.

display

Visual appearance of the game board.

Key Default Description
empty_cell " " Empty cell character
solid_cell "โ–ˆโ–ˆ" Filled cell character
shadow_cell "โ–‘โ–‘" Shadow piece character
bd_v "โ”‚" Border vertical
bd_h "โ”€" Border horizontal
bd_tl "โ•ญ" Border top-left
bd_tr "โ•ฎ" Border top-right
bd_bl "โ•ฐ" Border bottom-left
bd_br "โ•ฏ" Border bottom-right
bd_vr "โ”œ" Border T-right
bd_vl "โ”ค" Border T-left
bd_hb "โ”ฌ" Border T-bottom
bd_ht "โ”ด" Border T-top

timing

Frame rate and animation settings.

Key Default Description
fps 30 Frames per second
clear_anim_flash_interval 0.05 Line clear flash interval (seconds)
clear_anim_duration 0.3 Line clear animation duration (seconds)

game_rules

Gameplay parameters.

Key Default Description
max_lock_down_move_count 15 Max moves before piece locks down
time_attack_duration 120 Time Attack mode duration (seconds)

License

MIT License - see LICENSE for details.

Acknowledgements

Idea from tinytetris (a C implementation).

Going to be implemented(Maybe)

  1. sound
  2. ...

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tetris_terminal-0.3.0.tar.gz (26.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tetris_terminal-0.3.0-py3-none-any.whl (27.9 kB view details)

Uploaded Python 3

File details

Details for the file tetris_terminal-0.3.0.tar.gz.

File metadata

  • Download URL: tetris_terminal-0.3.0.tar.gz
  • Upload date:
  • Size: 26.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for tetris_terminal-0.3.0.tar.gz
Algorithm Hash digest
SHA256 3cccd92c4a544ceaaa268b1c6df3dbd665f5083b3ef249234d1e26275a3141a2
MD5 7e199ed2b5f912b8cf2fea8d1604c755
BLAKE2b-256 dbf2af28fa0441b348b6f4b8d18c7b3f3ec70ea46e79b64fc13fd7077ee93372

See more details on using hashes here.

File details

Details for the file tetris_terminal-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for tetris_terminal-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 93335f4883810a5ac38f6122c7f082147ede564df540ea843df59432671a6895
MD5 5a10d0677fa4afa074193347e66d91d9
BLAKE2b-256 600a1861a63dadc2a3b873637219e4c0a243553afe1fed6d5d54546c11aace40

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page