db.net/blog

2009.06.30

The cow game.

This was a great little toy to remind myself how to use PHP, MySQL, and teach myself some more uses for JQuery. The basic rules are fairly simple - if there's a group of cows on your side - add one to your total. If there's a cemetary, your cows die (your total becomes zero. Obviously, it requires honesty - the drive is at a huge disadvantage, and there's a gray area as to what constitutes a cow siting - one cow? A large herd? What if there are multiple groups? Do you only count right along the road, or off into the scenery? A little human intuition is neccesary, but the basic logic is pretty simple.

The great thing about JQuery (and other AJAX scripting libraries) is that it really simplifies building lightweight sites that still have rich interactions. This was doubly important, because I wanted it to work on my iPhone on a drive from New Jersey to North Carolina, then to Tennessee, and back. AT&T's 3G data connection is OK, but there's no need to push your luck if you're stuck on EDGE in the middle of nowhere (I believe that's an actual town you pass on I-81 in Virginia. If it's not, it should be. If saved a ton of time reload the entire page, and instead just making calls to and from a database.

I have one major bug fix - and it's the first user interaction you should check for - "Idiot Clicking." Essentially, you need to know what's going to happen when someone clicks a button 20 times in a row when the site freezes, or your data connection hangs because you went into a dead spot between some mountains. And, of course, this is the first thing my wife discovers. It's not a big deal - I simply need to disable the buttons and show a "working/please wait" message of some sort.

We also got creative with the rules (we were in the car for over 24 hours this weekend). You constantly pass rather large crosses on hills when you get out past the Mason-Dixon line. Should they count as something? Maybe, if you have no cows, you get some back from the dead. It would've helped me - every time I'd get close, I'd hit a graveyard. The closest my wife got was a monument of some sort. Do Chick-Fil-A billboards count? The cows aren't live, but they are pretty funny.

Once I fix it up, and secure it, maybe I'll put it live somewhere.

Link