"Be brave enough to be bad at something new." - Jon Acuff
Every program that I have ever written has been a mess of different functions that work well enough, but if something needs to change it can break the whole program. This has worked for me so far but also I want to try something new and see if I like it. It's always good to try new things. Object-oriented programming is that new thing today. After recently getting interested in mathematics and learning about John Conway's game of life, I thought I would try and make it myself.
![]() | ![]() |
I had to think about what sort of classes I would need for this project. You can imagine classes as things that have properties.
I am hungry at the moment, so the example of a class I can give will be a refridgerator, this refridgerator class would have certrain properties like a temperature, different shelves, and a freezer temperature.
You could write different methods (functions) within that class like a method for changing the temperature that would take two arguments:
1) the section of the fridge you want to change the temperature of.
2) the temperature you want to set.
In your code you could then call this method with something like:
kitchen_fridge.change_temp(freezer, -1)
or more generally: <class>.<method>(arguments)
So I thought about what I would need and decided to go with a grid to draw things on and handle the key presses, and a player to move around the screen and place down tiles.
![]() | ![]() |
A class that would follow the rules of life and play them out is also needed. Take a look at the _update_grid method of this class. it makes a copy of the current grid as it is, then it runs through each square of the current grid, applying the rules of the game of life to each one. After it's finished checking the whole grid it then overwrites the current grid with the one it's made after applying the rules of life.
When the game is paused, the player (the little red tile) can go around turning tiles on or off. The shape I have drawn here is well known for generating a lot of action on the screen. The game has been around for a while so people have done a lot of cool things with it.
![]() | ![]() |
Unpausing the game causes a whole lot of things to happen as the game of life plays out. Life goes around, creating new life and destroying it for about 2 minutes until it finally stabilises with the life in the image here on the right hand side. It's really quite nice to watch it all unfold. The screenshots do not really do it justice.
This has been a great learning experience and I can definitely see the value in OOP, keeping track of the state of things is really useful and I am looking forward to trying it again. If you want to see the code you can click here to be taken to a github page where I've put all of it Thanks heaps for reading this and I hope your day or night is a good one.
You can check out a list of all the blog posts by clicking here
You can get back to the homepage by clicking here