When I was in highschool I wanted to be a newspaper journalist. When I graduated from college I wanted to be a school teacher. But at this point programming has clearly won out as my lifelong career.
And now I have a job programming games. ;o) They may not be the most complicated games, but they are nonetheless outrageously fun.
My first project is to port gemdrop from java to flash.
Here's gemdrop in java.
Here's what I've got so far in flash.
Obviously one issue to this game is determining where continuities of 3 or more same-colored gems exist in the grid. Here's what I've got...seems to work perfectly:
private function search(gemName:String, curGem:Gem, thusFar:Array):int {
if (curGem == null) return 0;
if (curGem.gemName != gemName) return 0;
for (var i:int = 0; i < thusFar.length; i++)
if (curGem == thusFar[i]) return 0;
thusFar.push(curGem);
var ourTotal:int = 1 + search(gemName, grid[curGem.column][curGem.row+1], thusFar);
if (curGem.column < grid.length-1)
ourTotal += search(gemName, grid[curGem.column+1][curGem.row], thusFar);
if (curGem.row > 0)
ourTotal += search(gemName, grid[curGem.column][curGem.row-1], thusFar);
if (curGem.column > 0)
ourTotal += search(gemName, grid[curGem.column-1][curGem.row], thusFar);
return ourTotal;
}
}
This searches for any continuities from one given gem...and I only calculate from gems once their done falling (from the top, or due to a clear below them)...it saves a lot of search cycles to localize my search-domain to just the gems that have landed. The array "thusFar" is primed with []. So if I want to search off of gem "myGem", I would call
var thusFar:Array = [];
var totalContiguity:int = search(myGem.gemName, myGem, thusFar);
and thusFar would be full of the objects found once done. ;o)