0

I am currently on the final stretch of a project that I have put alot of time into.

It is a simon game. Basically I have a list that appends a random number onto it every round (1 number for round one, 2 for round 2 etc). so by round 8, I have 8 colours that flash for half a second, then disappear. This causes the window to not respond. Any Idea why?

#If a click occurs
     if main == True:
            if other == True:
                if mousex >= 500 and mousex <= 600 and mousey >= 0 and mousey <= 50:
#This isnt needed
                    playerchoicelist = []
#Random num
                    randomnum = random.randint(1,4)
#Adds it to simon list
                    addtosimons()

                    for i in range (0, roundnum):
#If its 1, flashes light red square, then normal colour again etc.
                        if simonslist[i] == 1:
                            pygame.display.update()
                            pygame.draw.rect(screen, REDLIGHT, [200, 0, 400, 375])
                            pygame.draw.rect(screen, (50, 50, 50), [550, 0, 100, 50])
                            screen.blit (startroundtext,
                       (600 - startroundtext.get_width() // 2, 25 - startroundtext.get_height()//2))
                            pygame.display.update()
                            time.sleep(1)
                            pygame.draw.rect(screen, RED, [200, 0, 400, 375])
                            pygame.display.update()
                            other = False
                            other = True
                        if simonslist[i] == 2:
                            pygame.display.update()
                            pygame.draw.rect(screen, BLUELIGHT, [600, 0, 400, 375])
                            pygame.draw.rect(screen, (50, 50, 50), [550, 0, 100, 50])
                            screen.blit (startroundtext,
                       (600 - startroundtext.get_width() // 2, 25 - startroundtext.get_height()//2))
                            pygame.display.update()
                            time.sleep(1)
                            pygame.draw.rect(screen, BLUE, [600, 0, 400, 375])
                            pygame.display.update()
                            other = False
                            other = True
                        if simonslist[i] == 3:
                            pygame.display.update()
                            pygame.draw.rect(screen, GREENLIGHT, [200, 375, 400, 375])
                            pygame.draw.rect(screen, (50, 50, 50), [550, 0, 100, 50])
                            screen.blit (startroundtext,
                       (600 - startroundtext.get_width() // 2, 25 - startroundtext.get_height()//2))
                            pygame.display.update()
                            time.sleep(1)
                            pygame.draw.rect(screen, GREEN, [200, 375, 400, 375])
                            pygame.display.update()
                            other = False
                            other = True
                        if simonslist[i] == 4:
                            pygame.display.update()
                            pygame.draw.rect(screen, YELLOWLIGHT, [600, 375, 400, 375])
                            pygame.draw.rect(screen, (50, 50, 50), [550, 0, 100, 50])
                            screen.blit (startroundtext,
                      (600 - startroundtext.get_width() // 2, 25 - startroundtext.get_height()//2))
                            pygame.display.update()
                            time.sleep(1)
                            pygame.draw.rect(screen, YELLOW, [600, 375, 400, 375])
                            pygame.display.update()
                            other = False
                            other = True
                    addroundnum()
  • That is a brutal for loop. Factor it out. Change a variable based on the state of simonslist. Then seperately draw based on the same variable. Then finally pygame.display.update(). Try to remove duplicate lines of code. – shanecandoit Jan 11 '20 at 06:13
  • @shanecandoit I really appreciate that sir. I am meeting up with a friend tonight to finish this. I should have done that before. I'll let u know if that works. I might even put def's after the if statement for organizations sake in the main loop. –  Jan 11 '20 at 21:34

0 Answers0