It dawned on me a week or two ago that I hadn’t written any new games in a long time. A bunch of years ago I started periodically to sit down and write a game, usually a recreation of something I had seen before; all of them get written in Visual Basic .NET (which is my favorite language). I’ve written card games (Four Corners, Nickles), board games (Othello, Sorry), puzzle games (Traffic, Sokoban, MasterMind, 3D Maze), and arcade games (Stacker, Klax, Bejeweled); some are one player, some two or more. Some even got ported to my PocketPC. I do it to keep my programming skills sharp, or to learn new skills (like PocketPC programming), but I guess mostly so I can have my own copy of the game. (I once saw a student playing the same game every day in homeroom, and wrote an equivalent on a dare.)
Anyway, as I said I realized recently that it’s been a while (a few years!) since I’ve done this, so I started looking around for a challenge. Going through my list of favorites from various gaming sites, I found that one particular favorite seems to be gone. If you search for a game called Candy Train, you’ll see lots of hits, but it’s been taken off PopCap.com where I originally found it. This tells me I found my target!
Candy Train (or my version, Crazy Train) has a 7×7 grid of tiles, and each tile has a random train track segments: straights, curves, etc. Clicking on any tile rotates it 90 degrees right or left (based on the mouse button used). A train engine starts in the center tile, and your mission is to keep switching the track tiles to keep the train on the tracks. Periodically a new train car will appear somewhere on the grid, and you have to manuver the train to that tile to pick up the car. The new car will be added to the end of the train, which of course makes it harder to keep a clear path open for the train. After the train reaches a predetermined number of cars, a train station tile appears, and you have to bring the train to the station to go to the next level. Failing to get a tile aligned before the train reaches it will naturally cause the train to crash. Here’s what it used to look like:
So a week ago I started writing the game (actually, modifying my Bejewled equivalent, since it already works with an array of picture box tiles). After a little bit I had the grid of tiles, and got them to rotate right or left. (I even got a few of my FIRST students interested, as they would occasionally walk into the lab and see me working on the game. But alas, none of them are in my programming classes right now.) So it got to the point where I rearrange the tiles to make the track any way I wanted … and then it hit me: I needed to get the tiles to know about the track beyond just the image! Each tile needed to know its track’s shape, so that the train (however that would be programmed) could tell if it was entering from the North, South, East or West, and what side it would exit from.
After pondering this a bit, I came to the conclusion that I needed to rethink my approach. I needed to NOT use an array of PictureBoxes, but an array of TrackSegment objects that were based on PictureBoxes. Each TrackSegment would know internally what its track looked like (straight, curved, etc.), and would also be able to tell the train object (again, however it would be programmed) where it was on the tile as the train moved along.
Tonight, after a few days of start and stop programming (anywhere from five minutes to an hour at a time), I got it working. My train right now is a small red box (just something easily seen), but it will run around the track designed with mouse clicks. (Can’t wait to show the students!) Hopefully there will be more entries in the future to describe my progress.