Start with a project

photo of child's construction kit

I find it difficult to learn anything of substance if I don’t have a specific use for it. That trait is regularly an obstacle but has reared up particularly in recent months, as I try to study PHP. The best uses are immediately accessible but take time and study to complete and perfect, and I didn’t have one. There is at least one complicated WordPress plugin I’d like to write, but that will require pawing through piles of someone else’s code, which makes it less than immediately accessible.

A few weeks ago it hit me that perhaps I could take one of the several “learn Python by programming games” tutorials and translate it into PHP. That led me to searching for PHP game tutorials, which brought me to Pits of Doom. Pits of Doom is a tutorial series for making a PHP adventure game, where your character travels through a dungeon fighting monsters. Sadly, it is quite incomplete, but it’s a good start, and the game developer who wrote it has a number of standalone tutorials as well: for example, a PHP Hangman game and upgrades to it to use either a database or AJAX.

I also found a series at IBM of PHP game scripts (part 2, part 3). These are primarily small utilities for role-playing, card, and word games, and they don’t use a database, but they are encouraging.

At that point I had a project: a simple adventure game written in PHP. I had in mind some cross between Zork, Tunnels of Doom, and a tabletop role-playing game, though the first edition is not looking like it will have any traces of Zork, and will only allow a one-character “party.” I found Dead Simple RPG online and, after yet more simplification, am using it as the basis for my game.

It is amazing the motivation this has provided. For the sake of players creating characters, I’ve learned about form validation and processing, and written half a dozen jQuery-using JavaScript functions to turn pieces of the form on and off and update others depending on the entries to that point. For smooth gameplay I’m starting to study AJAX, and for visual appeal I’ll be learning how PHP manages images. I have to use superglobal PHP variables for gameplay in the moment and work to and from the database to save and load characters and games between sessions.

There’s a long way to go, but I’ve already learned a great deal, and found it not so difficult now that I have a way to organize my approach. It is true what they say: How do you eat an elephant? One bite at a time.

Toy metal construction kit by stux on Pixabay.

Leave a Reply

Your email address will not be published. Required fields are marked *