Could anyone help me fix my score system?
I am coding a game where the user is shown a clock face and needs to choose the correct time from three options (answer1, answer2 and answer3). Once they have chosen their answer, if they are correct, the variable user_score should increment by one, and if they are incorrect the variable wolf_score should increment by one.
The variables are defined outside of the while loop initially as zero, there is a for loop in which the event for mouse button down is checked and the variables increase, and the text displayed on screen is defined after the loop.
The score should update once the user choses their answer, but it does not change when the code is run, it stays at 0.
This is my first post, so sorry if I have not given enough details, of if the code is hard to follow!
I have tried moving the code around, defining the variables in different ways and using global variables with no success…. I don’t know if I’ve been staring at the code for too long but I just can’t seem to work out where I’ve gone wrong, so any help is greatly appreciated.
I have attached below my code to analyse as you need:
def clocks():
#define variables
running= True
answer= None
user_score = 0
wolf_score = 0
while running : #game loop
#get mouse pos
CLOCKS_MOUSE_POS = pygame.mouse.get_pos()
#drawing
GAME_TEXT= font.render("Let's play!", True, "white")
GAME_RECT= GAME_TEXT.get_rect(center= (500,100))
screen.blit(GAME_TEXT, GAME_RECT)
#generate correct answer
answer1= Answer(None, (500, 590), question.getAnswer(), font, "Red", "Dark Red" , "")
answer1.changeColor(CLOCKS_MOUSE_POS)
answer1.update(screen)
#pygame.display.flip()
pygame.display.update()
#gameloop events
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
exit()
if event.type == pygame.MOUSEBUTTONDOWN:
if answer1.checkForInput(CLOCKS_MOUSE_POS):
buttonclick_sound.play()
user_score += 1
correct()
pygame.display.update()
if answer2.checkForInput(CLOCKS_MOUSE_POS):
buttonclick_sound.play()
wolf_score += 1
incorrect()
pygame.display.update()
if answer3.checkForInput(CLOCKS_MOUSE_POS):
buttonclick_sound.play()
wolf_score += 1
incorrect()
pygame.display.update()
if pausebutton.checkForInput(CLOCKS_MOUSE_POS):
buttonclick_sound.play()
pause()
if backbutton.checkForInput(CLOCKS_MOUSE_POS):
buttonclick_sound.play()
play()
#pygame.display.flip()
user_score_text = font.render(f"{user_score}", True, "Yellow")
screen.blit(user_score_text, (20, 100))
wolf_score_text = font.render(f"{wolf_score}", True, "Yellow")
screen.blit(wolf_score_text, (920, 100))
pygame.display.update()
Jemima Hilton is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.