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 3: Tetris
Today’s project was Tetris. The classic game of falling blocks that is both addicting and infuriating. I knew I had made the game well, when my wife complained that she was never getting the piece she wanted (just like the real game!). And no it doesn’t do that intentionally, it’s just a random luck of the draw. I think Tetris is a great game for starting out with programming because it’s recognizable, it’s got simple and straight forward graphics, and it lends itself well to object oriented programming. I have two classes in this one, in addition to the
simplegui framework that I made in earlier projects. I have the block class and the “tetroid” class which has four blocks in a particular configuration. For the tetroid, to draw itself it asks the blocks to draw themselves. When the tetroid needs to move, it checks each block for collisions with the dropped blocks and walls. Once it can’t drop down successfully it drops the blocks into the list of dropped blocks. I really like how simple I was able to make the program to get it working. There’s definitely still cleaning up and polishing that could be done, but for just a few hours of a build it really turned out great. Here’s a screen shot of the game. I went for more muted tones in keeping with the fifteen puzzle I originally posted:
Overall I think this went really well. There were definitely things like the next piece preview that I wish I had a chance to implement, but I think I accomplished quite a bit for a single evening of coding. This was a challenging build due to the time allotted and it makes me confident going ahead that I can get more python projects done.
For those who are interested here’s my github repo for the games project: https://github.com/robb07/python_games