我还有其他方法可以在一段时间内暂停某些功能吗?

问题描述

好的,所以我在pygame中打了个井字游戏,我希望计算机在单击并绘制十字后1秒钟绘制其符号(圆圈)。 这是一些代码

一些列表...

product = 1

# Blank = 0,Cross = 1,Circle = 2,cross_and_circle_pos = [0,0]

position_list = [first,second,third,fourth,fifth,sixth,seventh,eight,ninth]

主要功能

playing_state()检查是否有画圆的权限,然后将其放置在之前什么都没画的位置 我还希望它做的是在绘制圆圈之前等待

def playing_state():
    global state,a

    a += 1

    state = "circle"

    while state == "circle":

        random_number = random.randint(0,8)
        random_position = position_list[random_number]

        if cross_and_circle_pos[random_number] == 0:

            time.sleep(1)
            screen.blit(small_circle,random_position)
            cross_and_circle_pos[random_number] = 2
            state = "cross"

        else:
            continue

因此,简单的函数将检查我是否单击了table1(井字游戏的第一个表),然后在同一表中绘制了一个十字,然后调用绘制圆的func(playing_state)

def easy():
    global mode
    global state,product
    global first,ninth

    easy_mode = True

    mode = font.render("EASY",True,black)

    screen.fill(white)
    in_game()

    while easy_mode:

        for events in pygame.event.get():
            if events.type == pygame.QUIT:
                pygame.quit()
                quit()

            elif events.type == pygame.KEYDOWN:
                if events.key == pygame.K_BACKSPACE:
                    start_screen()

            elif events.type == pygame.MOUSEBUTTONDOWN:
                if state == "cross":
                    if table1.collidepoint(events.pos) and cross_and_circle_pos[0] == 0:

                        screen.blit(small_cross,first)
                        cross_and_circle_pos[0] = 1
                        product = 1
                        for i in cross_and_circle_pos:
                            product = product * i
                        if product == 0:
                            playing_state()
                        print(cross_and_circle_pos)

        pygame.display.update()

我尝试将time.sleep(1)几乎放到任何地方(在绘制十字之后,绘制圆之前,调用绘制圆的函数之前等等)但是该程序确实是,要在我单击(绘制十字)后再绘制两者并在同一时间圈出 我想画我的十字架(点击一下),然后在1秒钟后用计算机画一个

time.sleep()是否有问题,或者我的程序做错了什么? 有什么办法可以将time.sleep()放在某个地方并使其正常工作

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)