Skip to main content

俄罗斯方块命令行游戏

Project description

tetris

PyPI - Python Version License: MIT

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

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

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

cli_tetris-0.1.0.tar.gz (14.9 kB view details)

Uploaded Source

Built Distribution

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

cli_tetris-0.1.0-py3-none-any.whl (13.3 kB view details)

Uploaded Python 3

File details

Details for the file cli_tetris-0.1.0.tar.gz.

File metadata

  • Download URL: cli_tetris-0.1.0.tar.gz
  • Upload date:
  • Size: 14.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.11

File hashes

Hashes for cli_tetris-0.1.0.tar.gz
Algorithm Hash digest
SHA256 233590de41110a3220c8c5a6c05b6d01ba750b256726e2b38596c9fd6d14484c
MD5 b3dbb71897b26247736a514895f3718b
BLAKE2b-256 5a09979b1ac99c0a2eed68aa1b4fa802aea02ce5156cecec9bcf8fdd62170f57

See more details on using hashes here.

File details

Details for the file cli_tetris-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: cli_tetris-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 13.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.11

File hashes

Hashes for cli_tetris-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cebf7af416a382f4dde964dbe2101be60d390d3344d1d609161200a50d8fcb92
MD5 98ee462e994b98d2f6c6eed0e51e4cab
BLAKE2b-256 068663565b25e6d23ba0e6c72c0d269fc9d3d22d3b96e035bc61fa3f16254d1c

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