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)) square_size = 50 screen.draw.filled_rect( Rect(0, 0, square_size, square_size), color=(50, 0, 0) ) screen.draw.text('1', (19, 18)) screen.draw.filled_rect( Rect(square_size, 0, square_size, square_size), color=(0, 50, 0) ) screen.draw.text('2', (square_size + 21, 18)) screen.draw.filled_rect( Rect(square_size * 2, 0, square_size, square_size), color=(0, 0, 50) ) screen.draw.text('3', (square_size * 2 + 21, 18)) screen.draw.filled_rect( Rect(square_size * 3, 0, square_size, square_size), color=(50, 50, 0) ) screen.draw.text('4', (square_size * 3 + 21, 18)) 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))