if not waitingForInput: # play the pattern pygame.display.update() pygame.time.wait(1000) pattern.append(random.choice((YELLOW, BLUE, RED, GREEN))) for button in pattern: flashButtonAnimation(button) pygame.time.wait(FLASHDELAY) waitingForInput = True
There are two different "modes" or "states" that the program can be in. When
False, the program will be displaying the animation for the pattern. When
True, the program will be waiting for the user to select buttons.
Lines 1  to 9  will cover the case where the program displays the pattern animation. Since this is done at the start of the game or when the player finishes a pattern, line 5  will add a random color to the pattern list to make the pattern one step longer. Then lines 6  to 8  loops through each of the values in the pattern list and calls
flashButtonAnimation() which makes that button light up. After it is done lighting up all the buttons in the pattern list, the program sets the
waitingForInput variable to