from game import about_button, start_button, play_sound, center_pos
import pygame

WHITE = (255,255,255)
BLACK = (0,0,0)
GREEN = (0, 255, 0)

pygame.init()
pygame.font.init()
pygame.mixer.init()

FONT = pygame.font.Font("assets/font.ttf", 70)
FONT_MIN = pygame.font.Font("assets/font.ttf", 30)

window = pygame.display.set_mode([600,600])

running = True
clock = pygame.time.Clock()

nickname = " "

me = "X"
ia = "O"

while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
            play_sound("minimize_001")
        
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_BACKSPACE and len(nickname) > 2:
                nickname = list(nickname)
                nickname.pop(-2)
                nickname = "".join(nickname)
                play_sound("error_001")
            elif len(nickname.strip()) <= 10:
                play_sound("bong_001")
                if len(nickname) > 1:
                    nickname = list(nickname)
                    nickname.pop(-1)
                    nickname = "".join(nickname)
                nickname += event.unicode
                nickname += " "
            
            if event.key == pygame.K_UP or event.key == pygame.K_DOWN:
                if me == "X":
                    me = "O"
                    ia = "X"
                else:
                    me = "X"
                    ia = "O"

    window.fill(BLACK)

    title = FONT.render("JOGO DA VELHA", True, WHITE)
    title_pos = center_pos(title.get_rect(), 10)
    window.blit(title, title_pos)

    nickname_label = FONT.render("SEU NOME", True, WHITE)
    nickname_label_pos = center_pos(nickname_label.get_rect(), 100)
    window.blit(nickname_label, nickname_label_pos)

    nickname_render = FONT.render(nickname, True, BLACK)
    nickname_rect = nickname_render.get_rect()
    nickname_pos = center_pos(nickname_rect, 180)
    pygame.draw.rect(window, WHITE, (nickname_pos[0], 180, nickname_rect[2], nickname_rect[3]))
    window.blit(nickname_render, nickname_pos)

    choice_render = FONT.render(f"JOGUE COM {me}", True, WHITE)
    window.blit(choice_render, center_pos(choice_render.get_rect(), 280))

    my_name = FONT_MIN.render(f"DESENVOLVIDO POR MARIA EDUARDA DE AZEVEDO", True, WHITE)
    window.blit(my_name, center_pos(my_name.get_rect(), 560))

    start_button(window, "JOGAR", 380, me, ia, nickname.strip(), 10)
    about_button(window, 450, 10)

    pygame.display.flip()
    clock.tick(60)
[((8, 0, 8, 13), 'pygame.init', 'pygame.init', ({}, {}), '()', False, 'import pygame\n'), ((9, 0, 9, 18), 'pygame.font.init', 'pygame.font.init', ({}, {}), '()', False, 'import pygame\n'), ((10, 0, 10, 19), 'pygame.mixer.init', 'pygame.mixer.init', ({}, {}), '()', False, 'import pygame\n'), ((12, 7, 12, 46), 'pygame.font.Font', 'pygame.font.Font', ({(12, 24, 12, 41): '"""assets/font.ttf"""', (12, 43, 12, 45): '70'}, {}), "('assets/font.ttf', 70)", False, 'import pygame\n'), ((13, 11, 13, 50), 'pygame.font.Font', 'pygame.font.Font', ({(13, 28, 13, 45): '"""assets/font.ttf"""', (13, 47, 13, 49): '30'}, {}), "('assets/font.ttf', 30)", False, 'import pygame\n'), ((15, 9, 15, 43), 'pygame.display.set_mode', 'pygame.display.set_mode', ({(15, 33, 15, 42): '[600, 600]'}, {}), '([600, 600])', False, 'import pygame\n'), ((18, 8, 18, 27), 'pygame.time.Clock', 'pygame.time.Clock', ({}, {}), '()', False, 'import pygame\n'), ((26, 17, 26, 35), 'pygame.event.get', 'pygame.event.get', ({}, {}), '()', False, 'import pygame\n'), ((66, 19, 66, 49), 'game.center_pos', 'center_pos', ({(66, 30, 66, 43): 'nickname_rect', (66, 45, 66, 48): '180'}, {}), '(nickname_rect, 180)', False, 'from game import about_button, start_button, play_sound, center_pos\n'), ((67, 4, 67, 95), 'pygame.draw.rect', 'pygame.draw.rect', ({(67, 21, 67, 27): 'window', (67, 29, 67, 34): 'WHITE', (67, 36, 67, 94): '(nickname_pos[0], 180, nickname_rect[2], nickname_rect[3])'}, {}), '(window, WHITE, (nickname_pos[0], 180, nickname_rect[2],\n    nickname_rect[3]))', False, 'import pygame\n'), ((77, 4, 77, 33), 'game.about_button', 'about_button', ({(77, 17, 77, 23): 'window', (77, 25, 77, 28): '(450)', (77, 30, 77, 32): '(10)'}, {}), '(window, 450, 10)', False, 'from game import about_button, start_button, play_sound, center_pos\n'), ((79, 4, 79, 25), 'pygame.display.flip', 'pygame.display.flip', ({}, {}), '()', False, 'import pygame\n'), ((29, 12, 29, 38), 'game.play_sound', 'play_sound', ({(29, 23, 29, 37): '"""minimize_001"""'}, {}), "('minimize_001')", False, 'from game import about_button, start_button, play_sound, center_pos\n'), ((36, 16, 36, 39), 'game.play_sound', 'play_sound', ({(36, 27, 36, 38): '"""error_001"""'}, {}), "('error_001')", False, 'from game import about_button, start_button, play_sound, center_pos\n'), ((38, 16, 38, 38), 'game.play_sound', 'play_sound', ({(38, 27, 38, 37): '"""bong_001"""'}, {}), "('bong_001')", False, 'from game import about_button, start_button, play_sound, center_pos\n')]