[Python] Delay button appearance, random start of levels when it is pressed [duplicate]

Discussão em 'Python' iniciado por Stack, Abril 13, 2025.

  1. Stack

    Stack Membro Participativo

    There are several levels in the game, how to make it so that when you press the "ButtonB" button, one of the levels is launched randomly (beginning (beginning2) randomly (later they will be filled with questions (quiz) and there will be at least 10 of them). I tried to do it with random numbers, transferred the levels to a separate file.py, and also tried to specify just def-s (levels) or classes, but nothing worked.

    That's the problem. Following the documentation and the Internet, I did it the same way as with numbers, only I placed the level either in a separate scene or class. But unfortunately, nothing worked.

    import pygame
    import sys
    import pygame.time
    import pygame.locals
    from Button import ImageButton

    pygame.init()

    screen = pygame.display.set_mode((1280, 780))
    bg = pygame.image.load("image/result_Фон11.png")
    bg2 = pygame.image.load("image/result_Фон2.png")
    bg3 = pygame.image.load("image/Презентация.png")
    bg4 = pygame.image.load("image/result_Фон2 (размытый).png")
    pygame.display.set_caption("Соучастие в преступлении")
    icon = pygame.image.load("image/Icon/crowd-80.png")
    pygame.display.set_icon(icon)
    clock = pygame.time.Clock()

    def main_menu():

    def start():

    image = pygame.image.load("image/Airbrush-ARDUWgv8Nwg-Photoroom.png")
    imageD = pygame.image.load("image/Dio.png")
    myfond = pygame.font.Font('Font/Lilita One Regular.ttf', 20)
    text_surfaceS = myfond.render('Нужна твоя помощь!', True, 'Black')

    myfond = pygame.font.Font('Font/Lilita One Regular.ttf', 20)
    text_surfaceSo = myfond.render('Поступило сообщение', True, 'Black')
    ButtonB = ImageButton(1180, 360, 100, 100, "", "image/Button/стрелка-вправо.png",
    "image/Button/стрелка-вправо цвет.png")

    running = True
    while running:
    screen.fill((0, 0, 0))
    screen.blit(bg4, (0, -90))
    screen.blit(image, (40, 270))
    screen.blit(imageD, (450, 50))
    screen.blit(text_surfaceS, (590, 80))
    screen.blit(text_surfaceSo, (590, 100))

    ButtonB.check_hover(pygame.mouse.get_pos())
    ButtonB.draw(screen)

    for event in pygame.event.get():
    if event.type == pygame.QUIT:
    run = False
    pygame.quit()
    sys.exit()

    ButtonB.handle_event(event)
    if event.type == pygame.USEREVENT and event.button == ButtonB:
    beginning()

    pygame.display.flip()

    def pr():

    myfond = pygame.font.Font('Font/PassionsConflictRUS-Regular.otf', 50)
    text_surfacePr = myfond.render('Проект направлен на формирование ...', True, 'Black')

    running = True
    while running:
    screen.fill((0, 0, 0))
    screen.blit(bg3, (0, -90))
    screen.blit(text_surfacePr, (60, 60))

    for event in pygame.event.get():
    if event.type == pygame.QUIT:
    running = False
    pygame.quit()
    sys.exit()

    pygame.display.update()

    def beginning():

    running = True
    while running:

    screen.fill((0, 0, 0))
    screen.blit(bg2, (0, -90))

    for event in pygame.event.get():
    if event.type == pygame.QUIT:
    running = False
    pygame.quit()
    sys.exit()

    pygame.display.flip()

    def beginning2():

    running = True
    while running:

    screen.fill((0, 0, 0))
    screen.blit(bg2, (0, -90))

    for event in pygame.event.get():
    if event.type == pygame.QUIT:
    running = False
    pygame.quit()
    sys.exit()

    pygame.display.flip()

    if __name__ == "__main__":
    main_menu()

    Continue reading...

Compartilhe esta Página