下面是通过python shell运行时发生的情况的图像:
所以基本上在50到100+个回合后,我的游戏就会崩溃。看起来os.system()
在清除屏幕时没有正确关闭。使用pythonshell,我可以轻松地手动关闭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()
功能将无故“堵塞”
用print(“\033c”,end=”“)替换操作系统('cls')来解决此问题。在感到无聊之前已经转了500多圈了。我不认为os.system(“cls”)是为在每次转弯、每次攻击、每次激活的动作中重复使用而设计的
相关问题 更多 >
编程相关推荐