【发布时间】:2021-02-22 22:05:16
【问题描述】:
这是通过 python shell 运行它时发生的图像:
所以基本上在 50 到 100+ 回合后,我的游戏就会崩溃。看起来os.system() 在清除屏幕时未正确关闭。使用 python shell,我可以轻松地手动关闭cmd 页面并继续游戏而没有问题,但是当您将游戏作为 exe 文件或通过控制台运行时,这不是一个选项,因此会导致系统崩溃。
我曾尝试在os.system() 清除指令之前延迟并使用try/except,但未能解决问题。
def clear_screen():
playerMap[y][x] = "@"
time.sleep(.1)
os.system('cls' if os.name == 'nt' else 'clear')
displayMap(playerMap)
例如,如果您单击 W 进行移动并最终到达“。”的位置。然后clear_screen 将激活。
if movement == "W":
y = y-1
position = mapChoice[y][x]
playerMap[y][x] = "@"
if position == ".":
clear_screen()
intro1=random.choice(intro)
print (intro1)
print("which direction will you go ?")
每次移动都会激活清屏功能,但每移动 100 次,os.system() 功能就会无缘无故“卡住”。
【问题讨论】:
-
进行大量
os.system('cls)` 调用可能不是 IMO 的问题,所以我强烈怀疑该问题有其他原因。 -
如果我没有得到解决方案,我会重新编写整个游戏,但要小心可能导致此错误的任何事情。感谢您的编辑。
标签: python python-3.x windows crash