Skip to main content

tetris

PyPI - Python Version License: MIT

俄罗斯方块命令行游戏,基于 Python curses 和 Typer 实现,支持多种参数自定义,支持预告方块、影子方块、难度调节等特性。

tetris-demo

特性

  • 纯命令行界面,跨平台(Linux/macOS,Windows 需支持 curses)
  • 支持自定义棋盘大小、下落速度、难度、帧率等
  • 支持影子方块(落点预览)
  • 支持多预告方块
  • 支持暂停、加速、硬降
  • 支持 Hold/切换方块
  • 支持 T-Spin、Back-to-Back、Combo、Perfect Clear 高级玩法

安装

推荐使用 Python 3.7 及以上版本。

git clone https://github.com/lonsty/tetris.git
cd tetris
pip install .

或直接通过 pip 安装:

pip install tetris

快速开始

在终端输入:

tetris

即可开始游戏。

操作说明

  • ←:左移
  • →:右移
  • ↓:加速下落(只加速,不会固定方块)
  • ↑/x:顺时针旋转
  • z:逆时针旋转
  • 空格:硬降(直接落到底并固定)
  • C:Hold/切换方块(每个方块只可 Hold 一次)
  • ESC:暂停并显示帮助
  • q:退出游戏

命令行参数

所有参数均有默认值,可通过命令行自定义。例如:

tetris --game-fps 120 --board-height 24 --board-width 12 --next-count 2

支持的参数

参数名 默认值 说明
--game-fps -f 60 游戏帧率
--board-height -h 20 棋盘高度
--board-width -w 10 棋盘宽度
--drop-time-base 0.8 初始下落间隔(秒)
--drop-time-min 0.03 最快下落间隔(秒)
--level-max -m 15 最高难度等级
--level -l 1 初始等级
--next-count -n 4 预告方块数量

查看所有参数及帮助:

tetris --help

开发与测试

  1. 克隆仓库并安装依赖:

    git clone https://github.com/lonsty/tetris.git
    cd tetris
    pip install -e .
    
  2. 运行测试:

    pytest tests/
    
  3. 代码结构:

    tetris/
      ├── __init__.py
      ├── cli.py         # Typer 命令行入口
      ├── tetris.py      # 游戏主逻辑
      ├── const.py       # 常量配置
    tests/               # 单元测试
    

贡献

欢迎提交 issue 和 PR!

  • 发现 bug 或有新建议,请在 Issues 区留言。
  • 代码贡献请遵循 PEP8 风格。

许可证

MIT License © 2025 Allen Shaw

详见 LICENSE


项目主页:https://github.com/lonsty/tetris

Metadata

Release files for cli-tetris 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cli-tetris 0.1.0
File Size Uploaded Provenance Actions
cli_tetris-0.1.0.tar.gz 14.9 kB Without provenance Details for cli_tetris-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cli-tetris 0.1.0
File Interpreter ABI Platform Actions
cli_tetris-0.1.0-py3-none-any.whl Python 3 none any Details for cli_tetris-0.1.0-py3-none-any.whl

Total release size: 28.2 kB

Release files / cli_tetris-0.1.0.tar.gz

Download URL cli_tetris-0.1.0.tar.gz
Size 14.9 kB
Tags Source
SHA-256 checksum
How to use checksums
233590de41110a3220c8c5a6c05b6d01ba750b256726e2b38596c9fd6d14484c
BLAKE2b-256 checksum
How to use checksums
5a09979b1ac99c0a2eed68aa1b4fa802aea02ce5156cecec9bcf8fdd62170f57
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.11

Release files / cli_tetris-0.1.0-py3-none-any.whl

Download URL cli_tetris-0.1.0-py3-none-any.whl
Size 13.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cebf7af416a382f4dde964dbe2101be60d390d3344d1d609161200a50d8fcb92
BLAKE2b-256 checksum
How to use checksums
068663565b25e6d23ba0e6c72c0d269fc9d3d22d3b96e035bc61fa3f16254d1c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.11

Security for cli-tetris 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page