在pygame中为图片设置变量时,如何使其从列表中出现并使其消失?

我想知道如何将图像从列表中显示出来,然后使其在单击后消失。一旦单击,将分配一个变量。

当我在pygame中运行此程序时,我得到了一堆所有这些图片,它们很快就过了。

def game():
    screen = pygame.display.set_mode((1400, 750))
    pygame.display.set_caption("Goofspiel")
    screenExit = False
    while not screenExit:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                screenExit = True

        keys = pygame.key.get_pressed()
        mouse = pygame.mouse.get_pos()
        click = pygame.mouse.get_pressed()

        screen.fill(lightgray)

        fontname = pygame.font.SysFont("Denmark", 150)
        font = pygame.font.SysFont("Denmark", 40)
        font1 = pygame.font.SysFont("Denmark", 75)

        name = fontname.render("Goofspeil", True, (black))
        score = font.render("Player 1", True, (blue))
        score1 = font.render("Player 2", True, (red))
        player = font1.render("Player 1", True, (black))
        que = font.render("Who's turn is it?", True, (black))


        screen.blit(name, (490, 0))

        #Score board
        pygame.draw.rect(screen, sun, [0,20,375,80])
        pygame.draw.rect(screen, black, [0,20,375,5])
        pygame.draw.rect(screen, black, [0, 100.5, 375, 5])
        pygame.draw.rect(screen, black, [375, 20, 5, 85])
        pygame.draw.rect(screen, black, [305, 20, 5, 85])
        pygame.draw.rect(screen, black, [180, 20, 5, 85])
        pygame.draw.rect(screen, black, [110, 20, 5, 85])

        screen.blit(score, (0, 50))
        screen.blit(score1, (190, 50))
        screen.blit(que, (1100, 20))
        screen.blit(player, (1120, 70))

        #Displaying the cards
        screen.blit(DK, (5, 450))
        screen.blit(DQ, (100, 450))
        screen.blit(DJ, (200, 450))
        screen.blit(D10, (300, 450))
        screen.blit(D9, (400, 450))
        screen.blit(D8, (500, 450))
        screen.blit(D7, (600, 450))
        screen.blit(D6, (700, 450))
        screen.blit(D5, (800, 450))
        screen.blit(D4, (900, 450))
        screen.blit(D3, (1000, 450))
        screen.blit(D2, (1100, 450))
        screen.blit(D1, (1200, 450))

        #Add a random picture
        list = []
        list.append(HK)
        list.append(HQ)
        list.append(HJ)
        list.append(H10)
        list.append(H9)
        list.append(H8)
        list.append(H7)
        list.append(H6)
        list.append(H5)
        list.append(H4)
        list.append(H3)
        list.append(H2)
        list.append(H1)

        #rand = random.randrange(0, len(list))
        random.shuffle(list)
        screen.blit(list[0], (700,150))

        if 200 > mouse[0] > 100 and 700 > mouse[1] > 450:
            pygame.draw.rect(screen, lightblue2, [80, 705, 200, -60])
            if click[0] == 1:

                x = 12
                score2 = font.render(str(x), True, (black))
                screen.blit(score2, (135, 50))


        pygame.display.update()

game()

What I want to do, is that I want a picture randomly out of this list to show up, then get "removed" from the list and then make the picture disappear from the screen. Because these pictures are cards, I want that if a person clicks on the king, the x value = 13 and so on.

Can someone please help, I'm stuck on this question. I'm trying to make the game Goofspiel and I can't!

评论