-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate.py
More file actions
184 lines (150 loc) · 4.54 KB
/
create.py
File metadata and controls
184 lines (150 loc) · 4.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# make_release_fixed.py
import os
import shutil
print("📦 创建给朋友的超级马里奥发布包")
print("=" * 50)
# 1. 创建文件夹
release_dir = "SuperMario_ForFriend"
if os.path.exists(release_dir):
shutil.rmtree(release_dir)
print(f"🗑️ 清理旧文件夹: {release_dir}")
os.makedirs(release_dir, exist_ok=True)
print(f"📁 创建文件夹: {release_dir}")
# 2. 复制EXE(使用英文名避免编码问题)
exe_source = "dist/SuperMario/SuperMario.exe"
exe_dest = f"{release_dir}/SuperMario.exe"
if os.path.exists(exe_source):
shutil.copy2(exe_source, exe_dest)
print(f"✅ 复制游戏: SuperMario.exe")
else:
print(f"❌ 错误: 找不到 {exe_source}")
print(" 请先运行打包: pyinstaller --windowed --name=SuperMario --add-data='resources;resources' main.py")
input("按回车键退出...")
exit(1)
# 3. 复制资源
resources_source = "resources"
resources_dest = f"{release_dir}/resources"
if os.path.exists(resources_source):
shutil.copytree(resources_source, resources_dest)
# 统计资源文件数量
file_count = 0
for root, dirs, files in os.walk(resources_dest):
file_count += len(files)
print(f"✅ 复制资源: resources ({file_count} 个文件)")
else:
print("⚠️ 警告: 找不到resources文件夹")
# 4. 复制 _internal 文件夹(运行库)
internal_source = "dist/SuperMario/_internal"
internal_dest = f"{release_dir}/_internal"
if os.path.exists(internal_source):
shutil.copytree(internal_source, internal_dest)
print(f"✅ 复制运行库: _internal")
else:
print("ℹ️ 提示: 无运行库文件夹")
# 5. 创建批处理文件(使用ANSI编码)
bat_content = '''@echo off
chcp 65001 >nul
title Super Mario
echo.
echo ========================================
echo Super Mario Game
echo ========================================
echo.
REM Set current directory
cd /d "%~dp0"
REM Check if EXE exists
if not exist "SuperMario.exe" (
echo Error: SuperMario.exe not found!
pause
exit /b 1
)
echo Starting game...
echo.
timeout /t 2 /nobreak >nul
REM Start the game
start "" "SuperMario.exe"
echo.
echo Game started!
echo You can close this window.
timeout /t 5 /nobreak >nul
'''
bat_path = f"{release_dir}/StartGame.bat"
with open(bat_path, "w", encoding="utf-8") as f:
f.write(bat_content)
print(f"✅ 创建启动脚本: StartGame.bat")
# 6. 创建中文启动脚本(GBK编码)
bat_cn_content = '''@echo off
chcp 936 >nul
title 超级马里奥
echo.
echo ========================================
echo 超级马里奥游戏
echo ========================================
echo.
REM 设置当前目录
cd /d "%~dp0"
REM 检查文件
if not exist "SuperMario.exe" (
echo 错误: 找不到游戏文件!
pause
exit /b 1
)
echo 正在启动游戏...
echo.
timeout /t 2 /nobreak >nul
REM 启动游戏
start "" "SuperMario.exe"
echo.
echo 游戏已启动!
echo 可以关闭此窗口.
timeout /t 5 /nobreak >nul
'''
bat_cn_path = f"{release_dir}/启动游戏.bat"
with open(bat_cn_path, "w", encoding="gbk") as f: # 使用GBK编码
f.write(bat_cn_content)
print(f"✅ 创建中文启动脚本: 启动游戏.bat")
# 7. 创建说明文件
readme_content = """Super Mario Game
================
How to play:
1. Double click "StartGame.bat" (English)
2. Or double click "启动游戏.bat" (Chinese)
3. Or double click "SuperMario.exe"
Game Controls:
Arrow Keys: Move Mario
Space: Jump
Z: Run fast / Shoot
X: Pause
ESC: Quit
If game doesn't start:
1. Run as Administrator
2. Install required software:
- Visual C++ Redistributable
- DirectX End-User Runtime
"""
readme_path = f"{release_dir}/README.txt"
with open(readme_path, "w", encoding="utf-8") as f:
f.write(readme_content)
print(f"✅ 创建说明文件: README.txt")
# 8. 计算大小
total_size = 0
for root, dirs, files in os.walk(release_dir):
for file in files:
file_path = os.path.join(root, file)
total_size += os.path.getsize(file_path)
size_mb = total_size / 1024 / 1024
print(f"\n📦 发布包大小: {size_mb:.1f} MB")
# 9. 完成提示
print("\n" + "=" * 50)
print("🎉 发布包创建完成!")
print("=" * 50)
print(f"\n📁 文件夹: {release_dir}")
print("📤 发送给朋友:")
print(" 1. 右键点击文件夹")
print(" 2. 选择 '发送到' -> '压缩(zipped)文件夹'")
print(" 3. 发送生成的ZIP文件")
print("\n🎮 朋友使用方法:")
print(" 1. 解压ZIP文件")
print(" 2. 双击 '启动游戏.bat' 或 'StartGame.bat'")
print(" 3. 如果不行, 双击 'SuperMario.exe'")
input("\n按回车键退出...")