Функция кнопки Pygame не инициализирует игру - PullRequest
0 голосов
/ 17 января 2020

У нас есть программа pygame, которая запускается, но кнопка Start не активирует запуск игры, но вызывает ее закрытие ... Нет сообщения об ошибке, и отладка не решила проблему. Код, где я считаю, что проблема существует, ниже, и я предположил, что проблема в def game_intro() или def button().

def game_intro():
    intro = True
    while intro:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                quit()
        win.fill(black)
        largeText = pygame.font.Font('freesansbold.ttf',115)
        textSurf, textRect = text_objects("Snake", largeText)
        win.blit(textSurf, textRect)
        button("Start",150,250,100,50,green,bright_green,"play")
        pygame.display.update()
        clock.tick(15)


def button(msg, x,y,w,h,ic,ac,action=None):
    mouse = pygame.mouse.get_pos()
    click = pygame.mouse.get_pressed()
    print(click)
    if x+w > mouse[0] > x and x and y+h > mouse[1] > y:
        pygame.draw.rect(win, ac, (x,y,w,h))
        if click[0] == 1 and action != None:
            if action == "play":
                game_loop()
    if x + w > mouse[0] > x and y + h > mouse[1] > y:
        pygame.draw.rect(win, ac, (x,y,w,h))
    else:
        pygame.draw.rect(win, ic, (x,y,w,h))
    smallText = pygame.font.Font("freesansbold.ttf",20)
    textSurf, textRect = text_objects(msg, smallText)
    textRect.center = ( (x + (w/2)), y+(h/2) )
    win.blit(textSurf, textRect)
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...