Я проверил другие ответы на эту проблему, но мой немного отличается.
В моем коде ниже счет обновляется, когда я нажимаю на неправильный ответ, но затем он возвращается к своему первоначальному значению, что меня смущает, я проверил код и чувствую, что он в порядке, но я знаю, что что-то упустил или делать что-то не так. Пожалуйста, дайте мне знать, где я делаю неправильно. Ниже мой код.
#GAME SCREEN
def game_screen():
player_score = 25
timer = pygame.time.get_ticks()
start = True
while start :
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
seconds = (pygame.time.get_ticks()- timer)/1000
main_font = pygame.font.Font("ArialRounded.TTF", 22)
sub_font = pygame.font.Font("ArialRounded.TTF", 22)
timer_font = sub_font.render(str(seconds), True, SEABLUE)
question_font = main_font.render("Question:", True, SEABLUE)
star_img = pygame.image.load("starscore.png")
menu_screen_img = pygame.image.load("quizzappbackgroundscreen.png")
blureffect_img = pygame.image.load("blureffect.png")
onoff_button_img = pygame.image.load("onoffbutton.png")
knobone_img = pygame.image.load("knob_a.png")
knobtwo_img = pygame.image.load("knob_a.png")
knobrect_a = knobone_img.get_rect(center=(97.5,647.5))
knobrect_b = knobtwo_img.get_rect(center=(514.5,647.5))
mpos = pygame.mouse.get_pos()
click = pygame.mouse.get_pressed()
if knobrect_a.collidepoint(mpos):
knobone_img = pygame.image.load("knob_b.png")
if click[0] == 1:
knobone_img = pygame.image.load("rotatedknob_a.png")
click_sound.set_volume(0.3)
click_sound.play()
if knobrect_b.collidepoint(mpos):
knobtwo_img = pygame.image.load("knob_b.png")
if click[0] == 1:
knobtwo_img = pygame.image.load("rotatedknob_a.png")
click_sound.set_volume(0.3)
click_sound.play()
screen.blit(menu_screen_img, [0,0])
screen.blit(star_img, [50,47])
screen.blit(timer_font, [485,55])
screen.blit(question_font, [50,95])
question1(player_score)
screen.blit(blureffect_img, [0,0])
screen.blit(onoff_button_img, [25,726])
screen.blit(knobone_img, [50,599])
screen.blit(knobtwo_img, [465,599])
pygame.display.update()
#QUESTIONS FUNCTIONS
def question1(player_score):
main_font = pygame.font.Font("ArialRounded.TTF", 20)
question_font = main_font.render("Are the points G, C, A, and Y coplanar?", True, SEABLUE)
option1_font = main_font.render("- Yes", True, SEABLUE)
option2_font = main_font.render("- No", True, SEABLUE)
question_img1 = pygame.image.load("question1img.png")
option1rect = option1_font.get_rect(center=(93.5,402))
option2rect = option2_font.get_rect(center=(89.5,452))
mpos = pygame.mouse.get_pos()
click = pygame.mouse.get_pressed()
if option1rect.collidepoint(mpos):
option1_font = main_font.render("- Yes", True, DSEABLUE)
if click[0] == 1:
print("Right Answer")
#right_answers += 1
print(right_answers)
if option2rect.collidepoint(mpos):
option2_font = main_font.render("- No", True, DSEABLUE)
if click[0] == 1:
print("Wrong Answer")
player_score -=1
screen.blit(question_font,[60,130])
screen.blit(question_img1,[150,170])
screen.blit(option1_font, [70, 390])
screen.blit(option2_font, [70, 430])
draw_score(player_score)
#DRAW SCORE TEXT
def draw_score(player_score):
font = pygame.font.Font("ArialRounded.TTF", 22)
text = font.render("x" + str(player_score), True, SEABLUE)
screen.blit(text, [85,55])