我想写一个打字挑战游戏,玩家必须在时间限制内尽可能快地输入一个单词。在game()
函数结束时,它应该在计时器达到0
时执行round1()
函数。然而,没有任何反应,它只停留在号码1
。任何想法是什么导致这种行为?我不明白为什么我的功能不会发生
这是我使用的代码:你做了功能round1
import random
import time
global timer
timer = 20
global counting
counting = 10
global rounds
rounds = 0
def menu():
print ("Main Menu\nType in 'start' to begin the typing challenge")
start = input()
if start == "start":
game()
else:
menu()
def game():
global counting
choices = ["snazzy", "pizzas", "sizzle", "jackal"]
global word
word = (random.choice(choices))
print ("The word you must type is", word)
print ("You will be timed on how long it takes you to type the word.")
print ("Each round you will have a slightly smaller amount of time to type the word")
time.sleep(10)
print ("Starting in...")
for count in range(10):
print (counting)
time.sleep(1)
counting -=1
round1()
def round1():
useless = 100
global rounds
global word
global timer
while useless > 1:
for count in range(20):
time.sleep(1)
timer -=1
print ("Type", word)
attempt = input()
if attempt == word and timer > 0:
rounds = rounds+1
round2()
else:
lose()
这里没有需要并发的简单流程游戏 –
没错,不需要并发。我没有想到只是运行一个计时器。 – arewm