def choosePath():
path = ""
while path != "e" and path !="n":
print('\nWhich way do you go (n, s, e, w):\n')
t = Timer(1 * 1, timeout)
t.start()
answer = input(path)
path = path.lower()
if path =="e":
station()
elif path =="n":
estate()
elif path =="s":
building()
else:
print("\nYou return the way you came are but are soon caught by Mansons and assimilated.\n")
return path
我已经收到了这个代码,并希望添加一个计时器,如果答案没有在一定的时间内完成,它说gameover。你知道吗
你需要在while循环外启动计时器。还有几种方法可以实现计时器,但这应该是可行的(我简化了它,您需要根据业务逻辑调整它)
您需要线程模块中的Timer类。你知道吗
如果用户在time中选择了一个选项,则调用
t.cancel()
尝试创建另一个线程来跟踪时间,然后更新全局布尔值:
现在您可以让主代码在
while
循环中有一个附加语句:相关问题 更多 >
编程相关推荐