import random

def add_to_sequence():
    sequence.append(random.randint(1, 4))

def reset():
    global sequence
    global current

    sequence = []
    add_to_sequence()
    current = 0

reset()

def on_key_down(key):
    global current

    if key in (keys.K_1, keys.K_2, keys.K_3, keys.K_4):
        if key == keys.K_1:
            number = 1
        elif key == keys.K_2:
            number = 2
        elif key == keys.K_3:
            number = 3
        elif key == keys.K_4:
            number = 4

        if number == sequence[current]:
            current += 1
            if current == len(sequence):
                current = 0
                add_to_sequence()
        else:
            reset()

def draw():
    screen.fill((0, 0, 0))

    def draw_square(number, color):
        square_size = 50
        screen.draw.filled_rect(
            Rect(square_size * (number - 1), 0, square_size, square_size),
            color=color
        )
        screen.draw.text(str(number), (square_size * (number - 1) + 21, 18))

    draw_square(1, (50, 0, 0))
    draw_square(2, (0, 50, 0))
    draw_square(3, (0, 0, 50))
    draw_square(4, (50, 50, 0))

    screen.draw.text(str(current + 1) + '/' + str(len(sequence)), (20, 60))
    screen.draw.text('sequence[current]: ' + str(sequence[current]), (20, 100))
    screen.draw.text(', '.join(map(str, sequence)), (20, 140))