我试着在每次用户得到正确答案时加一分,如果在我的“连接4”数学游戏中答错了,我就拿走一分。在游戏中,用户把一个计数器放在想要的地方,问题就会弹出,等待答案,以便继续。这段代码中的所有内容都能正常工作,但我只是想建立一个积分制。这只是在每次回答问题时重置分数值。谢谢你的帮助!在N = random.randint(0, 14)
SCORE = 0
with open("QUESTIONS.txt") as QUESTIONS, open("ANSWERS.txt") as ANSWERS:
QUESTIONdata = QUESTIONS.readlines()
ANSWERdata = ANSWERS.readlines()
x = QUESTIONdata[N]
y = ANSWERdata[N]
txtbx = inputbox.Input(maxlength=45, color=(169,37,44), prompt = x[:-1])
while True:
events = pygame.event.get()
txtanswer = txtbx.update(events)
txtbx.draw(DISPLAYWINDOW)
pygame.display.flip()
drawBoard(mainBoard)
B = pygame.Surface((630, 540), pygame.SRCALPHA)
B.fill((0,0,0,128))
DISPLAYWINDOW.blit(B, (XMARGIN, YMARGIN))
for event in events:
if event.type == KEYDOWN:
if event.key == K_RETURN:
user_answer = str(txtbx.value)
try:
if (user_answer) == str(y[:-1]):
print("correct")
SCORE += 1
print(SCORE)
return
else:
turn = AI
print("incorrect")
print(SCORE)
SCORE += -1
print(SCORE)
return
except ValueError:
turn = AI
print("value errr")
SCORE += -1
return
elif event.type == QUIT:
pygame.quit()
return