|
|
|
# Tetris Game
|
|
|
|
|
|
|
|
A classic Tetris game implemented in Go using the Ebitengine game engine.
|
|
|
|
|
|
|
|
## Features
|
|
|
|
|
|
|
|
- Classic Tetris gameplay
|
|
|
|
- Ghost piece preview
|
|
|
|
- Next piece preview
|
|
|
|
- Line clearing with scoring
|
|
|
|
- Progressive difficulty levels
|
|
|
|
- Smooth controls with wall kicks
|
|
|
|
|
|
|
|
## Project Structure
|
|
|
|
|
|
|
|
```
|
|
|
|
tetris/
|
|
|
|
├── main.go # Application entry point
|
|
|
|
├── go.mod # Go module definition
|
|
|
|
├── go.sum # Go module checksums
|
|
|
|
├── assets/ # Game assets (future use)
|
|
|
|
├── internal/ # Internal packages
|
|
|
|
│ ├── game/ # Core game logic
|
|
|
|
│ │ └── game.go # Game state and rendering
|
|
|
|
│ ├── tetromino/ # Tetromino (falling pieces) logic
|
|
|
|
│ │ └── tetromino.go # Piece shapes, rotation, movement
|
|
|
|
│ └── types/ # Shared type definitions
|
|
|
|
│ └── types.go # Block types and colors
|
|
|
|
└── pkg/ # Public packages
|
|
|
|
└── config/ # Configuration constants
|
|
|
|
└── config.go # Game configuration and constants
|
|
|
|
```
|
|
|
|
|
|
|
|
## Architecture
|
|
|
|
|
|
|
|
The project follows Go best practices with a clean package structure:
|
|
|
|
|
|
|
|
- **`main.go`**: Entry point that initializes the game
|
|
|
|
- **`pkg/config`**: Contains all game configuration constants
|
|
|
|
- **`internal/types`**: Defines core data types and enums
|
|
|
|
- **`internal/tetromino`**: Handles tetromino piece logic (shapes, rotation, movement)
|
|
|
|
- **`internal/game`**: Core game mechanics (board state, input handling, rendering)
|
|
|
|
|
|
|
|
## Controls
|
|
|
|
|
|
|
|
- **Left/Right Arrow**: Move piece horizontally
|
|
|
|
- **Up Arrow**: Rotate piece clockwise
|
|
|
|
- **Down Arrow**: Soft drop (faster falling)
|
|
|
|
- **Space**: Hard drop (instant drop)
|
|
|
|
- **L**: Switch language (English ⇄ 中文)
|
|
|
|
- **R** (when game over): Restart game
|
|
|
|
|
|
|
|
## 中文支持 / Chinese Support
|
|
|
|
|
|
|
|
游戏支持中文界面!启动游戏后按 **L 键** 切换到中文模式。
|
|
|
|
|
|
|
|
The game supports Chinese interface! Press **L key** after starting the game to switch to Chinese mode.
|
|
|
|
|
|
|
|
参见 [中文使用指南](HOW_TO_USE_CHINESE.md) 了解详细说明。
|
|
|
|
|
|
|
|
See [Chinese Usage Guide](HOW_TO_USE_CHINESE.md) for detailed instructions.
|
|
|
|
|
|
|
|
## Building and Running
|
|
|
|
|
|
|
|
```bash
|
|
|
|
# Run the game
|
|
|
|
go run .
|
|
|
|
|
|
|
|
# Build executable
|
|
|
|
go build -o tetris
|
|
|
|
./tetris
|
|
|
|
```
|
|
|
|
|
|
|
|
## Dependencies
|
|
|
|
|
|
|
|
- [Ebitengine](https://ebitengine.org/) v2.8.8 - 2D game engine for Go
|
|
|
|
|
|
|
|
## License
|
|
|
|
|
|
|
|
This project is open source and available under the MIT License.
|