Memory Graphics – Programming 1 Final

When I decided to add to the base of the Programming Final I searched for possible platforms that would help me make the program better using graphics. This post will explain the massive key that I had to learn, Pygame. I had to spend time than writing my source code for the program using trial and error. After I was able to learn how to use Pygame I had to make sure that everything ran correctly with no errors in the finale.

In order to start on the idea of graphics, I had to figure out where I wanted to do them. Out in python, there are many different possible packages that I could have used. In class, we used turtle which is built into python but I needed something that would work better and was overall easy to use. For this, I went back to our Question of the Week we did where we gave ideas for possible programs I wanted to do. One of my good programming buddies, Janna had mentioned something about Pygame. I looked into it and found that it was a package within python that you had to download. Mr. Sommerer was also able to help me and showed me a tutorial that he made for Pygame.


            elif (clickedButton and clickedButton != computerPattern[currentButton]) or (currentButton!= 0 and time.time() - TIMEOUT > lastClickTime):
                gameOver()
                #newRound = new_game('Would you like to play again?', basicFont)
                computerPattern = []
                currentButton = 0
                inputWait = False
                score = 0
                pygame.time.wait(1000)

This is a part of my code that runs when the user has failed in entering the correct sequence. I am proud about this because within the else if statement the board will display game-over before resetting for the next round so that the user doesn’t haven’t have to rerun the program

    for start, end, step in((0, 255, 1), (255, 0, -1)):
        for alpha in range(start, end, animationSpeed*step):
            userQuit()
            DISPLAYSURF.blit(originalSurf, (0, 0))
            flashSurf.fill((r, g, b, alpha))
            DISPLAYSURF.blit(flashSurf, rectangle.topleft)
            pygame.display.update()
            FPSCLOCK.tick(FPS)

This code was also something that I was happy about when it finally worked out. This is a for loop which is coming from my buttonFlash() procedure. What happens here is that the animation runs through 2 times, once increase and the other then decreasing the color of the chosen rectangle which makes it flash.


Along with things that I was proud of there are somethings that I do not like about this program.

          elif event.type == pygame.KEYDOWN:

            if event.key == pygame.K_q:
                clickedButton = YELLOW
            elif event.key == pygame.K_w:
                clickedButton = BLUE
            elif event.key == pygame.K_a:
                clickedButton = RED
            elif event.key == pygame.K_s:
                clickedButton = GREEN

This is apart of an if statement in my event_handler() procedure. This part of the code doesn’t work and no matter what I tried It wouldn’t run properly. Adding this into my program allows the user to not only use the mouse but to also use the keys: “Q, W, A, S” as the 4 color squares. This part of my program makes me mad and I am not proud that this is something I can’t work out. If I had time I would like to go back in a try and test some things working only with the keyboard and see if I could change it so that it could run either way.

Leave a Reply