parent
fa81ccec6e
commit
fdc0c294f3
@ -1,112 +0,0 @@ |
||||
# 废弃方法修复记录 |
||||
|
||||
## 修复日期 |
||||
2024年 |
||||
|
||||
## 修复的废弃方法 |
||||
|
||||
### 1. Go 标准库 - `math/rand` |
||||
|
||||
#### 修复内容: |
||||
- **废弃方法**: `rand.Seed(time.Now().UnixNano())` |
||||
- **修复方案**: 完全移除该调用 |
||||
- **原因**: Go 1.20+ 中随机数生成器自动种子化,不再需要手动调用 `rand.Seed()` |
||||
- **文件**: `main.go` |
||||
|
||||
#### 变更: |
||||
```go |
||||
// 修复前 |
||||
import ( |
||||
"math/rand" |
||||
"time" |
||||
) |
||||
|
||||
func main() { |
||||
rand.Seed(time.Now().UnixNano()) |
||||
// ... |
||||
} |
||||
|
||||
// 修复后 |
||||
func main() { |
||||
// 不再需要 rand.Seed() 调用 |
||||
// ... |
||||
} |
||||
``` |
||||
|
||||
### 2. Ebitengine v2.5+ - 图形绘制 API |
||||
|
||||
#### 修复内容: |
||||
- **废弃方法**: `ebitenutil.DrawRect()` 和 `ebitenutil.DrawLine()` |
||||
- **新方法**: `vector.DrawFilledRect()` 和 `vector.StrokeLine()` |
||||
- **原因**: Ebitengine v2.5 后推荐使用性能更好的 vector 包 |
||||
- **文件**: `internal/game/game.go` |
||||
|
||||
#### 主要变更: |
||||
|
||||
**矩形绘制:** |
||||
```go |
||||
// 修复前 |
||||
ebitenutil.DrawRect(screen, x, y, width, height, color) |
||||
|
||||
// 修复后 |
||||
vector.DrawFilledRect(screen, float32(x), float32(y), float32(width), float32(height), color, false) |
||||
``` |
||||
|
||||
**线条绘制:** |
||||
```go |
||||
// 修复前 |
||||
ebitenutil.DrawLine(screen, x1, y1, x2, y2, color) |
||||
|
||||
// 修复后 |
||||
vector.StrokeLine(screen, float32(x1), float32(y1), float32(x2), float32(y2), 1, color, false) |
||||
``` |
||||
|
||||
#### 修复位置: |
||||
1. 游戏背景绘制 |
||||
2. 预览区域背景 |
||||
3. 网格线绘制 |
||||
4. 方块绘制 (`drawBlock` 方法) |
||||
5. 幽灵方块绘制 |
||||
6. 下一个方块预览 |
||||
|
||||
### 3. 导入包更新 |
||||
|
||||
添加了新的导入: |
||||
```go |
||||
import ( |
||||
// ... 其他导入 |
||||
"github.com/hajimehoshi/ebiten/v2/vector" |
||||
) |
||||
``` |
||||
|
||||
## 性能优势 |
||||
|
||||
### Vector API 优势: |
||||
1. **更好的性能**: vector 包使用 GPU 加速绘制 |
||||
2. **更准确的渲染**: 减少了像素对齐问题 |
||||
3. **未来兼容性**: 与 Ebitengine 的发展方向一致 |
||||
|
||||
### 随机数优化: |
||||
1. **自动优化**: Go 1.20+ 的随机数生成器自动优化 |
||||
2. **更好的随机性**: 不需要手动种子化 |
||||
3. **代码简化**: 减少了样板代码 |
||||
|
||||
## 验证结果 |
||||
|
||||
- ✅ 编译成功 |
||||
- ✅ Lint 检查通过 (无废弃警告) |
||||
- ✅ 功能测试正常 |
||||
- ✅ 多平台构建正常 |
||||
|
||||
## 影响评估 |
||||
|
||||
- **兼容性**: 完全向前兼容 |
||||
- **功能**: 无功能变化,纯技术升级 |
||||
- **性能**: 理论上性能有所提升 |
||||
- **维护性**: 符合最新最佳实践 |
||||
|
||||
## 建议 |
||||
|
||||
1. 定期运行 `make check` 检查代码质量 |
||||
2. 关注 Ebitengine 官方更新,及时采用新 API |
||||
3. 保持 Go 版本更新以享受最新优化 |
Binary file not shown.
@ -0,0 +1,85 @@ |
||||
package i18n |
||||
|
||||
// Language represents supported languages
|
||||
type Language int |
||||
|
||||
const ( |
||||
English Language = iota |
||||
Chinese |
||||
) |
||||
|
||||
// Localization contains all text strings for the game
|
||||
type Localization struct { |
||||
Next string |
||||
Score string |
||||
Level string |
||||
Controls string |
||||
Move string |
||||
Rotate string |
||||
SoftDrop string |
||||
HardDrop string |
||||
GameOver string |
||||
Restart string |
||||
Language string |
||||
PressL string |
||||
} |
||||
|
||||
// currentLanguage holds the current language setting
|
||||
var currentLanguage Language = English |
||||
|
||||
// localizations contains all supported language strings
|
||||
var localizations = map[Language]Localization{ |
||||
English: { |
||||
Next: "NEXT:", |
||||
Score: "Score: %d", |
||||
Level: "Level: %d", |
||||
Controls: "CONTROLS:", |
||||
Move: "← → Move", |
||||
Rotate: "↑ Rotate", |
||||
SoftDrop: "↓ Soft Drop", |
||||
HardDrop: "Space Hard Drop", |
||||
GameOver: "Game Over!", |
||||
Restart: "Press R to restart", |
||||
Language: "Language:", |
||||
PressL: "Press L to switch", |
||||
}, |
||||
Chinese: { |
||||
Next: "下一个:", |
||||
Score: "分数: %d", |
||||
Level: "等级: %d", |
||||
Controls: "操作说明:", |
||||
Move: "← → 移动", |
||||
Rotate: "↑ 旋转", |
||||
SoftDrop: "↓ 软降落", |
||||
HardDrop: "空格 硬降落", |
||||
GameOver: "游戏结束!", |
||||
Restart: "按 R 重新开始", |
||||
Language: "语言:", |
||||
PressL: "按 L 切换", |
||||
}, |
||||
} |
||||
|
||||
// GetText returns localized text for the current language
|
||||
func GetText() Localization { |
||||
return localizations[currentLanguage] |
||||
} |
||||
|
||||
// GetCurrentLanguage returns the current language
|
||||
func GetCurrentLanguage() Language { |
||||
return currentLanguage |
||||
} |
||||
|
||||
// SwitchLanguage toggles between supported languages
|
||||
func SwitchLanguage() { |
||||
switch currentLanguage { |
||||
case English: |
||||
currentLanguage = Chinese |
||||
case Chinese: |
||||
currentLanguage = English |
||||
} |
||||
} |
||||
|
||||
// SetLanguage sets the current language
|
||||
func SetLanguage(lang Language) { |
||||
currentLanguage = lang |
||||
} |
Loading…
Reference in new issue