下面是一个不需要并行处理(在python中很复杂)的示例:while True: # you don't need to write True==True
for horse in horseList:
if horse.leg.getX() > -187:
horse.move( -1, 20 )
else:
horse.move( 5, 28 )
for civilian in civiliansList:
if civilian.getX() < 800:
civilian.move( 20, 0 )
else:
civilian.move( -100, 0 )
mouse = win.getMouse()
princess.move( mouse, civilianCounter)
civilianCounter = princess.move( mouse, civilianCounter)
if civiliansSaved >= 10: # check to see if 10 or more have been saved
break
print( "Game over" )
win.getMouse()
win.close()
你要做的是保持游戏运行直到civilianSaved计数器至少为10。但是你不能在一个与主游戏循环分开的循环中这样做,所以在计数至少为10之前,不要停止游戏是更有意义的。这个if语句可以包含在主游戏循环中。在