【发布时间】:2019-09-21 18:37:29
【问题描述】:
我正在为学校编码“挑战”编写一个不太好的小游戏,我需要为某个动作设置时间限制,同时引入一个按键进入系统。我有一个完整的游戏计时器,但我的游戏是以射击外星人为基础的,我希望在外星人回击之前为每一波设置一个时间限制。另外,我怎样才能为用户输入自动输入? (例如,要射击,您必须按 P,但在游戏中您必须输入 P 然后输入)。
#Main Code
print("An Alien has appeared! They are shooting in 5 seconds!")
#MAIN TIMER START
start = time.time()
decision = input("Will you shoot (P) or deflect (O)?")
if input == "P":
decision = shoot
elif input == "p":
decision = shoot
elif input == "O":
decision = deflect
elif input == "o":
decision = deflect
重启()
【问题讨论】:
-
您的代码将无法工作,因为您测试的变量
input不存在。为避免大小写问题,您可以在变量上使用.upper(),这样您只需测试“P”和“O”。
标签: python