Frame 1
function startGame() {
_root.gameOverMC._visible = false;
score = 0;
level = 0;
var _local3 = 0;
while (_local3 < 20) {
var _local2 = 0;
while (_local2 < 12) {
mc = _root.attachMovie("block", (("block " + _local3) + " ") + _local2, level);
mc._x = (30 * _local3) + 25;
mc._y = (30 * _local2) + 20;
mc.x = _local3;
mc.y = _local2;
mc.gotoAndStop(Math.ceil(Math.random() * 4));
level++;
_local2++;
}
_local3++;
}
trace(_root.gameOverMC._visible);
}
function clickBlock(x, y) {
var _local3 = _root[(("block " + x) + " ") + y]._currentframe;
_root[(("block " + x) + " ") + y].gotoAndStop(5);
var _local2 = 1;
_local2 = _local2 + testNeighbor(x - 1, y, _local3);
_local2 = _local2 + testNeighbor(x + 1, y, _local3);
_local2 = _local2 + testNeighbor(x, y - 1, _local3);
_local2 = _local2 + testNeighbor(x, y + 1, _local3);
if (_local2 > 1) {
collapseDown();
collapseAcross();
score = score + (_local2 * _local2);
} else {
_root[(("block " + x) + " ") + y].gotoAndStop(_local3);
}
}
function testNeighbor(x, y, c) {
if (_root[(("block " + x) + " ") + y]._currentframe == c) {
_root[(("block " + x) + " ") + y].gotoAndStop(5);
var _local2 = 1;
_local2 = _local2 + testNeighbor(x - 1, y, c);
_local2 = _local2 + testNeighbor(x + 1, y, c);
_local2 = _local2 + testNeighbor(x, y - 1, c);
_local2 = _local2 + testNeighbor(x, y + 1, c);
return(_local2);
}
return(0);
}
function collapseDown() {
var _local4 = 0;
while (_local4 < 20) {
var _local3 = 11;
while (_local3 > 0) {
thisColor = _root[(("block " + _local4) + " ") + _local3]._currentframe;
if (thisColor == 5) {
var _local2 = _local3 - 1;
while (_local2 >= 0) {
aboveColor = _root[(("block " + _local4) + " ") + _local2]._currentframe;
if (aboveColor != 5) {
_root[(("block " + _local4) + " ") + _local3].gotoAndStop(aboveColor);
_root[(("block " + _local4) + " ") + _local2].gotoAndStop(5);
break;
}
_local2--;
}
}
_local3--;
}
_local4++;
}
}
function collapseAcross() {
do {
n = 0;
var _local3 = 0;
while (_local3 < 19) {
if (_root[("block " + _local3) + " 11"]._currentframe == 5) {
if (_root[("block " + (_local3 + 1)) + " 11"]._currentframe != 5) {
n++;
var _local2 = 0;
while (_local2 < 12) {
c = _root[(("block " + (_local3 + 1)) + " ") + _local2]._currentframe;
_root[(("block " + _local3) + " ") + _local2].gotoAndStop(c);
_root[(("block " + (_local3 + 1)) + " ") + _local2].gotoAndStop(5);
_local2++;
}
}
}
_local3++;
}
} while (n > 0);
}
function checkGameOver() {
gameOver = true;
do {
var _local3 = 0;
while (_local3 < 20) {
var _local2 = 11;
while (_local2 >= 0) {
block = _root[(("block " + _local3) + " ") + _local2];
if (block._currentframe != 5) {
if (block._currentframe == _root[(("block " + (_local3 + 1)) + " ") + _local2]._currentframe) {
gameOver = false;
break;
}
if (block._currentframe == _root[(("block " + (_local3 - 1)) + " ") + _local2]._currentframe) {
gameOver = false;
break;
}
if (block._currentframe == _root[(("block " + _local3) + " ") + (_local2 + 1)]._currentframe) {
gameOver = false;
break;
}
if (block._currentframe == _root[(("block " + _local3) + " ") + (_local2 - 1)]._currentframe) {
gameOver = false;
break;
}
}
_local2--;
}
_local3++;
}
if (gameOver) {
gotoAndStop ("game over");
_root.gameOverMC._visible = true;
trace(_root.gameOverMC._visible);
break;
}
} while (gameOver == true);
}
stop();
Instance of Symbol 14 MovieClip "gameOverMC" in Frame 1
onClipEvent (load) {
_root.gameOverMC._level = 5000;
trace(this._level);
}
Instance of Symbol 17 MovieClip in Frame 1
onClipEvent (load) {
_root.startGame();
}
Frame 10
stop();
Symbol 3 Button
on (release) {
if (_root._currentframe != "game over") {
_root.clickBlock(x, y);
_root.checkGameOver();
}
}
Symbol 7 MovieClip [block] Frame 1
stop();
Symbol 13 Button
on (release) {
_root.gameOverMC._visible = false;
_root.startGame();
_root.gotoAndStop("play");
}