Further experimentation in Python and OOP

While there are no notable updates regarding my first game, Chicken vs. Egg, I did write a new Python script today in an effort to hone some of the skills I’ll need to use as I move forward.

It’s called “Dogs,” and it serves no real purpose aside from being a teaching tool for myself. It’s a command line-based demo which works like this:

  1. It prompts you to enter a dog breed and a name
  2. It creates an object instance of the Dog class using the provided parameters and adds it to a list of dogs you’ve created during the program
  3. A menu prompts you to list all created dogs, to create another dog, or quit

You can check it out on Github if you’d like. There’s no real-world application for this program that I can tell, but it was a valuable learning experience that helped me work through a problem I encountered when thinking about the CvE source: how to create an undefined number of objects without explicitly declaring a variable in which to store each one. What I mean is, using the Dogs program as an example, I wanted to find out how to avoid doing something like dog1 = Dog(“collie”, “Sparky”) for each dog I wanted to create.

It turns out that the solution is to create a list and append a new class instance to the list each time it’s created. This will be indispensable as I develop CvE – I have no idea how many different eggs I’ll need to create for any given game, so it would be impossible for me to manually instantiate the various Egg objects. However, if I can populate them into a list as they’re created, I can easily cycle through and update their positions, check for collision, check when they’ve gone offscreen, and remove them once they are no longer needed.

I’ve been missing JavaScript these past few days, but I think it’s best for me to focus on one thing at a time. I’ve made some good progress in JavaScript in the past month or so, and now my goal is to make a game. I do want to continue my journey toward JS mastery, but I think the path of least resistance for my current goal will be Python using Pygame. If I decide to create another game after that, there’s a really cool JavaScript game framework called Phaser which I’m interested in trying out; it would allow me to make a browser-based game using HTML5’s canvas, but I think it would also require a lot more overhead to learn.

Before I wrap up the post, I’d like to add that I’m 10% of the way through my 100 Days of Code challenge (I just posted the log for day 10 here). I’ve still got a long way to go, but I’m encouraged that I’ve made it as far as I have already.

100 Days of Code Progress: Day 5

It’s been a while since I’ve posted here, but I’ve been actively working on code every day all the same. I’ve been pouring most of my thoughts into my 100 Days of Code log in lieu of  posting here (but I’m now seeing that I’ve got a handful of readers, so I wanted to check in and let you know what I’ve been up to).

When I first heard of 100 Days of Code, I thought it was a series of code problems you had to solve 100 days in a row. It’s actually much simpler: you code whatever you want, but you do it for at least an hour each day for 100 days straight. I am in the process of securing a full-time day gig, so I’ll no longer have as much free time as I have had up until now to work on my coding skills, and this sounded like a great way to keep my momentum going.

I forked the official repo on Github and got started about five days ago. Lately, I’ve been going through the coding challenges on CodeWars.com using JavaScript to solve them. Each problem is called a “kata,” and I was making pretty steady progress until the kata I started on around the time I started the 100 Days challenge. (As a side note, you can click here to join my team on that site!)

I worked out all the syntax errors and got the program to run, but the output was totally wrong. I struggled to modify the logic to get it working, but kept hitting a brick wall. So I just decided to erase the meat of the function, work through it in plain English via pseudo code, and start again. And it worked! It’s such a great feeling to finally break through after being stuck on a persistent problem. Part of me wishes I picked everything up without getting stuck in the first place, but another part realizes that perhaps getting stuck is a valuable educational experience in its own right.

I am gearing up to create my very first game in Python using the popular Pygame library. The idea of creating video games is what piqued my interest in computer science/programming in the first place, and even though I know what I crank out will inevitably be rudimentary, I’m still excited to get my first little demo up and running. I’ll be sure to keep you posted as it develops. It won’t be anything innovative or revolutionary, but it’ll be mine, and I’ll be proud of it all the same.

I don’t know if I’ve mentioned this previously, but about a month ago I installed Ubuntu on my laptop alongside Windows 10, and I haven’t logged back into Windows since. The overall environment is so much more amenable to programming. I love it. I have to Google how to use certain features a lot more regularly than I did with Windows, but I’m excited to be learning new skills. I actually wrote my latest log for 100 Days using a very stripped-down editor called Vim; it’s anything but intuitive, but from what I’ve read, it’s very powerful. I’m looking forward to getting further acquainted with it, though I’ll probably still be heavily using Atom for the foreseeable future.

As for now, I should probably try to get some sleep. I’ve got to return to my week-long temporary day job tomorrow. Believe me, I’d much rather be coding, but I’m still not to the point of getting paid to do it.

Not yet, at least.