Chain Factor JS

Download Chain Factor JS (10 KB)
Download jQuery 1.2.3 (94 KB)
Download all code in zip file (97 KB)

Chain Factor JS

Chain Factor is a great little puzzle game that I like to play once in a while to clear my head if I’m working on a tough problem, or just when I’m bored. It’s pretty simple: click on a column in the board to drop the next ball into that column. When the number on a ball matches the number of consecutive balls in the row or column that ball is in, the ball will clear. The FAQ on the Chain Factor site probably explains it better than I can.

I was bored one afternoon and wanted to play Chain Factor, but I only had my iPhone, which doesn’t handle Flash. So I did what any reasonable web developer would do and cloned it in Javascript. This is NOT a full game; I started with the goal of playing it on my iPhone, but soon decided that I just wanted to see how simple I could make the basic game play.

Chain Factor JS was written with jQuery, and almost the entire game relies on the DOM. Aside from a couple configuration variables (how big should the board be, etc), only two variables about the game are stored: what will the next ball be, and whether or not the previous move is still being processed. When you drop a ball, the DOM is polled to determine which balls need to be cleared, and which ones then need to be shifted down. Is this the most efficient way to do it? Almost definitely not, but I wanted to get more comfortable with jQuery and see how simple I could keep my Javascript. The code could be shorter, but I’ve always been of the opinion that readability is preferable to brevity.

This version doesn’t keep score, and it doesn’t add the gray balls that make Chain Factor interesting, but I think it’s still fun to play with. Even as I’m typing this description, I keep stopping to play with it for a bit.