我想寫一個打字挑戰遊戲,玩家必須在時間限制內儘可能快地輸入一個單詞。在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