home *** CD-ROM | disk | FTP | other *** search
- function startGame()
- {
- gotoAndStop(12);
- score = 0;
- level = 0;
- balls = 240;
- var x = 0;
- while(x < 20)
- {
- var y = 0;
- while(y < 12)
- {
- mc = _root.attachMovie("block","block " + x + " " + y,level);
- mc._x = 25 * x + 85;
- mc._y = 25 * y + 60;
- mc.x = x;
- mc.y = y;
- mc.gotoAndStop(Math.ceil(Math.random() * 4));
- level++;
- y++;
- }
- x++;
- }
- }
- function clickBlock(x, y)
- {
- var c = _root["block " + x + " " + y]._currentframe;
- _root["block " + x + " " + y].gotoAndStop(5);
- var n = 1;
- n += testNeighbor(x - 1,y,c);
- n += testNeighbor(x + 1,y,c);
- n += testNeighbor(x,y - 1,c);
- n += testNeighbor(x,y + 1,c);
- if(n > 1)
- {
- collapseDown();
- collapseAcross();
- if(isGameOver())
- {
- _root.gotoAndStop("over");
- }
- _root.balls -= n;
- score += n * n;
- now.nowscore += n * n;
- now.gotoAndPlay(2);
- fx.start();
- }
- else
- {
- _root["block " + x + " " + y].gotoAndStop(c);
- fx2.start();
- _root.nomatch.gotoAndPlay(2);
- }
- }
- function testNeighbor(x, y, c)
- {
- if(_root["block " + x + " " + y]._currentframe == c)
- {
- _root["block " + x + " " + y].gotoAndStop(5);
- var n = 1;
- n += testNeighbor(x - 1,y,c);
- n += testNeighbor(x + 1,y,c);
- n += testNeighbor(x,y - 1,c);
- n += testNeighbor(x,y + 1,c);
- return n;
- }
- return 0;
- }
- function collapseDown()
- {
- var x = 0;
- while(x < 20)
- {
- var y = 11;
- while(y > 0)
- {
- thisColor = _root["block " + x + " " + y]._currentFrame;
- if(thisColor == 5)
- {
- var i = y - 1;
- while(i >= 0)
- {
- aboveColor = _root["block " + x + " " + i]._currentframe;
- if(aboveColor != 5)
- {
- _root["block " + x + " " + y].gotoAndStop(aboveColor);
- _root["block " + x + " " + i].gotoAndStop(5);
- break;
- }
- i--;
- }
- }
- y--;
- }
- x++;
- }
- }
- function collapseAcross()
- {
- do
- {
- n = 0;
- var x = 0;
- while(x < 19)
- {
- if(_root["block " + x + " 11"]._currentframe == 5)
- {
- if(_root["block " + (x + 1) + " 11"]._currentframe != 5)
- {
- n++;
- var y = 0;
- while(y < 12)
- {
- c = _root["block " + (x + 1) + " " + y]._currentframe;
- _root["block " + x + " " + y].gotoAndStop(c);
- _root["block " + (x + 1) + " " + y].gotoAndStop(5);
- y++;
- }
- }
- }
- x++;
- }
- }
- while(n > 0);
-
- }
- function isGameOver()
- {
- var i = 0;
- while(i < 20)
- {
- var j = 0;
- while(j < 12)
- {
- var c = _root["block " + i + " " + j]._currentframe;
- if(c != 5)
- {
- if(_root["block " + (i + 1) + " " + j]._currentframe == c || _root["block " + i + " " + (j + 1)]._currentframe == c)
- {
- return false;
- }
- }
- j++;
- }
- i++;
- }
- return true;
- }
- stop();
-