Metadata-Version: 2.4
Name: cli-tetris
Version: 0.1.0
Summary: 俄罗斯方块命令行游戏
Author-email: Allen Shaw <lonsty@sina.com>
License: MIT License
        
        Copyright (c) 2025 Allen Shaw
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
Project-URL: Homepage, https://github.com/lonsty/tetris
Keywords: tetris,game,cli
Requires-Python: >=3.7
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: typer
Requires-Dist: colorama
Dynamic: license-file

# tetris

[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/tetris.svg)](https://python.org)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)

俄罗斯方块命令行游戏，基于 Python [curses](https://docs.python.org/3/library/curses.html) 和 [Typer](https://typer.tiangolo.com/) 实现，支持多种参数自定义，支持预告方块、影子方块、难度调节等特性。

![tetris-demo](https://raw.githubusercontent.com/lonsty/tetris/refs/heads/master/tetris.png)

## 特性

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

## 安装

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

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

或直接通过 pip 安装：

```bash
pip install tetris
```

## 快速开始

在终端输入：

```bash
tetris
```

即可开始游戏。

## 操作说明

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

## 命令行参数

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

```bash
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    | 预告方块数量 |

查看所有参数及帮助：

```bash
tetris --help
```

## 开发与测试

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

    ```bash
    git clone https://github.com/lonsty/tetris.git
    cd tetris
    pip install -e .
    ```

2. 运行测试：

    ```bash
    pytest tests/
    ```

3. 代码结构：

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

## 贡献

欢迎提交 issue 和 PR！

- 发现 bug 或有新建议，请在 [Issues](https://github.com/lonsty/tetris/issues) 区留言。
- 代码贡献请遵循 [PEP8](https://www.python.org/dev/peps/pep-0008/) 风格。

## 许可证

MIT License © 2025 [Allen Shaw](mailto:lonsty@sina.com)

详见 [LICENSE](LICENSE)

---

**项目主页**：[https://github.com/lonsty/tetris](https://github.com/lonsty/tetris)
