30 Days of Python: Day 2 Pong Revisited

I’ve been learning a lot about Python over the last year but I realized a few weeks back that I needed some more intensive time with it to get really fluent. That’s when I came up with 30 days of python. I’m going to make a small project every day in python for the next 30 days (probably a few days longer since there are some vacation days in there). I’m hoping to learn a bunch of different python packages and make a wide variety of projects  from games, to computer tools, to machine learning, and maybe some science. It should be a good variety and I think it will be a lot of fun.

Day 2: Pong Revisited

A while back I posted my version of pong from the interactive python course at coursera. Today’s project was to port that web based game to pygame using my implementation of simplegui from yesterday’s project. To get it working I had to improve the buttons, add labels, and make the button panel a much more robust control panel in simplegui. I skipped the sound effects and just put a placeholder in for now but that might be a project to revisit further down the road. Overall I was quite pleased with how quickly I was able to get pong up and running with the new backend. Here’s what the new version looks like:


After I got it running again, I spent a lot of time refactoring the code. My version from back in the fall worked, but it relied heavily on global variables and disconnected information. I reworked the program to have two classes: paddle and ball. The resulting program is about the same length as the original, but I think it is a lot more understandable. It’s easier to follow the interactions between the objects than trying to track what happens to individual global variables. Refactoring the computer player proved to be the trickiest because it had a convoluted logic structure that depended on whether it was the left or right paddle but I did eventually find a solution.

For those who are interested here’s my github repo for the games project: https://github.com/robb07/python_games



2 thoughts on “30 Days of Python: Day 2 Pong Revisited

  1. […] He’s also come up with a version of Pong: […]

  2. […] He’s also come up with a version of Pong: […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s