🐍 贪吃蛇小游戏
一个使用纯HTML、CSS和JavaScript实现的经典贪吃蛇游戏,具有现代化的UI设计和流畅的游戏体验。
✨ 功能特点
- 🎮 经典贪吃蛇游戏玩法
- 🎨 现代化的渐变UI设计
- 📱 支持移动端触摸控制
- 🎯 得分系统和最高分记录(本地存储)
- ⌨️ 支持键盘和按钮控制
- 🎪 流畅的游戏动画效果
🚀 安装和运行
方式一:通过 PyPI 安装(推荐)
pip install snake-game-zh
安装后,在命令行运行:
snake-game
游戏会自动在浏览器中打开。
方式二:直接运行
- 直接在浏览器中打开
index.html文件即可开始游戏 - 无需安装任何依赖或服务器
方式三:Python 模块方式
from snake_game import start_game
start_game(port=8000, open_browser=True)
🎮 操作说明
键盘控制
- 方向键 ↑ ↓ ← → 或 WASD 键控制蛇的移动方向
- 使用方向键或WASD键控制蛇的移动
移动端控制
- 点击屏幕上的方向按钮
- 或在游戏画布上滑动手指(上下左右)
🎯 游戏规则
- 控制蛇移动,吃到红色食物
- 每吃到一个食物,蛇会变长,得分+10
- 撞到墙壁或自己的身体,游戏结束
- 尽量获得更高的分数!
📁 文件结构
小游戏/
├── snake_game/ # Python 包目录
│ ├── __init__.py # 包初始化文件
│ ├── server.py # 服务器启动脚本
│ └── static/ # 静态文件目录
│ ├── index.html # 主页面
│ ├── style.css # 样式文件
│ └── game.js # 游戏逻辑
├── setup.py # PyPI 打包配置
├── MANIFEST.in # 文件清单
├── LICENSE # 许可证
└── README.md # 说明文档
🛠️ 技术栈
- HTML5 Canvas - 游戏渲染
- CSS3 - 现代化UI样式
- JavaScript (ES6+) - 游戏逻辑
- LocalStorage - 最高分存储
📝 游戏特性
- 网格系统:20x20的网格布局
- 碰撞检测:墙壁和自身碰撞检测
- 食物生成:随机生成,避免与蛇身重叠
- 动画效果:流畅的移动和绘制
- 响应式设计:适配不同屏幕尺寸
🎨 UI设计
- 渐变背景和卡片式设计
- 清晰的得分显示
- 游戏开始/结束界面
- 移动端友好的控制按钮
享受游戏吧!🎉
Metadata
Release files for snake-game-zh 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| snake_game_zh-1.0.0.tar.gz | 10.7 kB | Without provenance | Details for snake_game_zh-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| snake_game_zh-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for snake_game_zh-1.0.0-py3-none-any.whl |
Total release size: 21.0 kB
Release files / snake_game_zh-1.0.0.tar.gz
| Download URL | snake_game_zh-1.0.0.tar.gz |
|---|---|
| Size | 10.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
008c8b3166e68ed63503273a1b38ee71e84619937db560980c8fd0d94d1f5ea5
|
|
BLAKE2b-256 checksum How to use checksums |
9365a6dc01f24de76f2ff51deff5d315e0d601196d57a0bad2a4b96acc31ecdd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|
Release files / snake_game_zh-1.0.0-py3-none-any.whl
| Download URL | snake_game_zh-1.0.0-py3-none-any.whl |
|---|---|
| Size | 10.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
91fdca8b3d97030e179d447a31ac1abd9a06f3b3398522110ad6786e1c19afa4
|
|
BLAKE2b-256 checksum How to use checksums |
8b75e288663d64a9cf1a959e91c2f2d00a7e9a3befb4227fb730cca940283db7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|
Security for snake-game-zh 1.0.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.