Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# IDE settings
.idea/
.vscode/
*.swp
*.swo
*~

# OS files
.DS_Store
Thumbs.db
46 changes: 36 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@

这是一个2D农场模拟游戏,玩家可以控制角色在农场中移动,开垦土地、种植作物、等待作物生长并收获产品。

## 🆕 v1.1 更新内容

- **新增作物种类**:番茄和玉米,共三种作物可供种植
- **金币系统**:收获作物可获得金币,不同作物价值不同
- **商店系统**:可以使用金币购买各种种子
- **改进的UI**:显示金币数量、当前选中的种子类型
- **作物颜色区分**:不同作物显示不同颜色(小麦-金黄、番茄-红色、玉米-金色)
- **物品堆叠显示**:背包中相同物品会合并显示数量

## 🛠️ 技术栈

- **Python 3** - 主要开发语言
Expand All @@ -17,7 +26,7 @@
planting-game/
├── main.py # 游戏主入口,包含游戏循环和主要逻辑
├── block.py # 土地块类定义(Block、Soil)
├── character.py # 角色类定义,包含背包管理
├── character.py # 角色类定义,包含背包和金币管理
├── item.py # 物品类定义(Item、ItemType、Plant)
└── import pygame.py # 早期版本/备份文件
```
Expand All @@ -26,9 +35,10 @@ planting-game/

#### `main.py` - 游戏主程序
- 初始化 Pygame 和游戏窗口(800x600)
- 创建玩家角色和初始物品(锄头、小麦种子
- 创建玩家角色和初始物品(锄头、种子
- 生成土地块网格
- 处理游戏主循环:事件监听、渲染更新、植物生长逻辑
- 商店系统逻辑

#### `block.py` - 土地系统
- **Block 类**:基础土地块,包含位置和状态属性
Expand All @@ -37,16 +47,26 @@ planting-game/
- 支持种植(plant_crop)
- 支持生长(grow)- 基于时间的生长系统
- 支持收获(harvest)
- 不同作物显示不同颜色

#### `character.py` - 角色系统
- 角色位置管理
- 背包系统:添加、移除、获取物品
- 金币系统:添加、消费金币

#### `item.py` - 物品系统
- **ItemType 类**:物品类型枚举(工具、种子、植物、产品)
- **ItemType 类**:物品类型枚举(工具、种子、植物、产品、货币
- **Item 类**:基础物品定义
- **Plant 类**(继承Item):植物定义,包含生长时间、产出物品、种子掉落等属性

## 🌱 作物信息

| 作物 | 种子价格 | 生长阶段 | 产品售价 |
|------|----------|----------|----------|
| 小麦 | 10 金币 | 5 阶段 | 15 金币 |
| 番茄 | 20 金币 | 6 阶段 | 25 金币 |
| 玉米 | 30 金币 | 7 阶段 | 35 金币 |

## 🎮 游戏操作

| 按键 | 功能 |
Expand All @@ -57,13 +77,19 @@ planting-game/
| D | 向右移动 |
| 空格 | 交互(开垦土地/种植/收获)|
| E | 打开/关闭背包 |
| B | 打开/关闭商店 |
| 1 | 选择小麦种子 |
| 2 | 选择番茄种子 |
| 3 | 选择玉米种子 |

## 🌱 游戏玩法

1. **开垦土地**:站在未开垦的土地上,背包中有锄头时按空格键开垦
2. **种植作物**:站在已开垦的土地上,背包中有种子时按空格键种植
3. **等待生长**:作物会随时间自动生长,生长阶段以数字显示
4. **收获产品**:作物成熟后(达到最大生长阶段),按空格键收获产品和种子
2. **购买种子**:按 B 打开商店,点击想要购买的种子
3. **选择种子**:按 1-3 键选择要种植的种子类型
4. **种植作物**:站在已开垦的土地上,背包中有种子时按空格键种植
5. **等待生长**:作物会随时间自动生长,生长阶段以数字显示
6. **收获产品**:作物成熟后(达到最大生长阶段),按空格键收获产品和种子,同时获得金币

## 🚀 如何运行

Expand All @@ -78,16 +104,16 @@ python main.py
## 📋 未来更新计划

### 近期计划 (v1.x)
- [ ] 添加更多作物种类(番茄、玉米、南瓜等)
- [x] 添加更多作物种类(番茄、玉米)
- [x] 实现金币系统
- [x] 添加商店系统
- [ ] 实现浇水系统,影响作物生长速度
- [ ] 添加季节系统,不同季节可种植不同作物
- [ ] 优化玩家角色动画

### 中期计划 (v2.x)
- [ ] 添加商店系统,可以买卖种子和产品
- [ ] 实现金币系统
- [ ] 添加更多工具(水壶、斧头等)
- [ ] 添加背包容量限制和堆叠功能
- [ ] 添加背包容量限制
- [ ] 保存/读取游戏进度

### 长期计划 (v3.x)
Expand Down
Binary file removed __pycache__/block.cpython-312.pyc
Binary file not shown.
Binary file removed __pycache__/character.cpython-312.pyc
Binary file not shown.
Binary file removed __pycache__/item.cpython-312.pyc
Binary file not shown.
13 changes: 11 additions & 2 deletions block.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import pygame

# 定义常量
PLANT_COLOR = (0, 128, 0)
TILE_SIZE = 32

# 植物颜色字典
PLANT_COLORS = {
"Wheat Plant": (218, 165, 32), # 金黄色 - 小麦
"Tomato Plant": (255, 99, 71), # 番茄红
"Corn Plant": (255, 215, 0), # 玉米金色
}
DEFAULT_PLANT_COLOR = (0, 128, 0) # 默认绿色

# 初始化字体
pygame.font.init()
FONT = pygame.font.Font(None, 24) # 可以根据需要调整字体大小
Expand Down Expand Up @@ -90,8 +97,10 @@ def draw(self, screen):
x, y = self.position
# 计算植物的大小,根据生长阶段动态变化
plant_size = TILE_SIZE * (self.growth_stage / self.plant.max_stages)
# 获取植物颜色
plant_color = PLANT_COLORS.get(self.plant.name, DEFAULT_PLANT_COLOR)
# 绘制植物矩形,使其居中显示在土地块上
pygame.draw.rect(screen, PLANT_COLOR, (x + (TILE_SIZE - plant_size) // 2,
pygame.draw.rect(screen, plant_color, (x + (TILE_SIZE - plant_size) // 2,
y + (TILE_SIZE - plant_size) // 2,
plant_size, plant_size))
# 绘制生长阶段数字标注
Expand Down
19 changes: 19 additions & 0 deletions character.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def __init__(self, name, x, y):
self.x = x
self.y = y
self.inventory = [] # Item list
self.coins = 100 # Starting coins

def add_item(self, item):
"""
Expand All @@ -36,3 +37,21 @@ def get_inventory(self):
:return: The character's inventory list
"""
return self.inventory

def add_coins(self, amount):
"""
Add coins to the character
:param amount: The amount of coins to add
"""
self.coins += amount

def spend_coins(self, amount):
"""
Spend coins from the character
:param amount: The amount of coins to spend
:return: True if successful, False if not enough coins
"""
if self.coins >= amount:
self.coins -= amount
return True
return False
1 change: 1 addition & 0 deletions item.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class ItemType:
SEED = 2
PLANT = 3
PRODUCT = 4
CURRENCY = 5

# 定义物品类
class Item:
Expand Down
Loading