0

Allright, so Im making a tic-tac-toe in pygame and I want the computer to draw its symbol(circle) 1 second after i click and draw my cross. Here is some code:

Some lists...

product = 1

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

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

And the main funcs

playing_state() checks if its right to draw a circle and then does it in a position that nothing is drawn before What i also want it to do though is to wait before it draws the circle

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

So the easy func will check if i've clicked the table1(first table of tic tac toe) then draw a cross in the same table and after that call the func(playing_state) that draws the circle

def easy():
    global mode
    global state, product
    global first, second, third, fourth, fifth, sixth, seventh, eight, 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()

I've tried putting time.sleep(1) almost everywhere(right after the cross is drawn, right before the circle is drawn, right before the function that draws the circle is called and so on) BUT WHAT THE PROGRAM DOES IS to wait after i click (to draw the cross) and then draws BOTH cross and circle AT THE SAME TIME while i want to draw my cross (with a click) and after 1 second the computer to draw a circle

Is there a problem with time.sleep() or am i doing something wrong in my program? Is there a way I can put time.sleep() somewhere and make it work properly

Thalis
  • 188
  • 2
  • 12
  • Write some new code in a new file, about 5 lines perhaps which try to achieve the dynamic you want, nothing to do with tic tac toe, or any of the code you've posted. It's a distraction. See how to create a [mcve]. – Peter Wood Oct 19 '20 at 19:58
  • I wrote a new much simpler pygame program. The same thing seems to be happening. The time.sleep() pauses the entire program and and not the actions I want to. Is there anything else I should try? – Thalis Oct 20 '20 at 19:36

0 Answers0