home *** CD-ROM | disk | FTP | other *** search
/ 600 Games / 600games.iso / Puzzle / collapse.swf / scripts / frame_11 / DoAction_2.as next >
Encoding:
Text File  |  2006-06-13  |  3.3 KB  |  150 lines

  1. function startGame()
  2. {
  3.    gotoAndStop(12);
  4.    score = 0;
  5.    level = 0;
  6.    balls = 240;
  7.    var x = 0;
  8.    while(x < 20)
  9.    {
  10.       var y = 0;
  11.       while(y < 12)
  12.       {
  13.          mc = _root.attachMovie("block","block " + x + " " + y,level);
  14.          mc._x = 25 * x + 85;
  15.          mc._y = 25 * y + 60;
  16.          mc.x = x;
  17.          mc.y = y;
  18.          mc.gotoAndStop(Math.ceil(Math.random() * 4));
  19.          level++;
  20.          y++;
  21.       }
  22.       x++;
  23.    }
  24. }
  25. function clickBlock(x, y)
  26. {
  27.    var c = _root["block " + x + " " + y]._currentframe;
  28.    _root["block " + x + " " + y].gotoAndStop(5);
  29.    var n = 1;
  30.    n += testNeighbor(x - 1,y,c);
  31.    n += testNeighbor(x + 1,y,c);
  32.    n += testNeighbor(x,y - 1,c);
  33.    n += testNeighbor(x,y + 1,c);
  34.    if(n > 1)
  35.    {
  36.       collapseDown();
  37.       collapseAcross();
  38.       if(isGameOver())
  39.       {
  40.          _root.gotoAndStop("over");
  41.       }
  42.       _root.balls -= n;
  43.       score += n * n;
  44.       now.nowscore += n * n;
  45.       now.gotoAndPlay(2);
  46.       fx.start();
  47.    }
  48.    else
  49.    {
  50.       _root["block " + x + " " + y].gotoAndStop(c);
  51.       fx2.start();
  52.       _root.nomatch.gotoAndPlay(2);
  53.    }
  54. }
  55. function testNeighbor(x, y, c)
  56. {
  57.    if(_root["block " + x + " " + y]._currentframe == c)
  58.    {
  59.       _root["block " + x + " " + y].gotoAndStop(5);
  60.       var n = 1;
  61.       n += testNeighbor(x - 1,y,c);
  62.       n += testNeighbor(x + 1,y,c);
  63.       n += testNeighbor(x,y - 1,c);
  64.       n += testNeighbor(x,y + 1,c);
  65.       return n;
  66.    }
  67.    return 0;
  68. }
  69. function collapseDown()
  70. {
  71.    var x = 0;
  72.    while(x < 20)
  73.    {
  74.       var y = 11;
  75.       while(y > 0)
  76.       {
  77.          thisColor = _root["block " + x + " " + y]._currentFrame;
  78.          if(thisColor == 5)
  79.          {
  80.             var i = y - 1;
  81.             while(i >= 0)
  82.             {
  83.                aboveColor = _root["block " + x + " " + i]._currentframe;
  84.                if(aboveColor != 5)
  85.                {
  86.                   _root["block " + x + " " + y].gotoAndStop(aboveColor);
  87.                   _root["block " + x + " " + i].gotoAndStop(5);
  88.                   break;
  89.                }
  90.                i--;
  91.             }
  92.          }
  93.          y--;
  94.       }
  95.       x++;
  96.    }
  97. }
  98. function collapseAcross()
  99. {
  100.    do
  101.    {
  102.       n = 0;
  103.       var x = 0;
  104.       while(x < 19)
  105.       {
  106.          if(_root["block " + x + " 11"]._currentframe == 5)
  107.          {
  108.             if(_root["block " + (x + 1) + " 11"]._currentframe != 5)
  109.             {
  110.                n++;
  111.                var y = 0;
  112.                while(y < 12)
  113.                {
  114.                   c = _root["block " + (x + 1) + " " + y]._currentframe;
  115.                   _root["block " + x + " " + y].gotoAndStop(c);
  116.                   _root["block " + (x + 1) + " " + y].gotoAndStop(5);
  117.                   y++;
  118.                }
  119.             }
  120.          }
  121.          x++;
  122.       }
  123.    }
  124.    while(n > 0);
  125.    
  126. }
  127. function isGameOver()
  128. {
  129.    var i = 0;
  130.    while(i < 20)
  131.    {
  132.       var j = 0;
  133.       while(j < 12)
  134.       {
  135.          var c = _root["block " + i + " " + j]._currentframe;
  136.          if(c != 5)
  137.          {
  138.             if(_root["block " + (i + 1) + " " + j]._currentframe == c || _root["block " + i + " " + (j + 1)]._currentframe == c)
  139.             {
  140.                return false;
  141.             }
  142.          }
  143.          j++;
  144.       }
  145.       i++;
  146.    }
  147.    return true;
  148. }
  149. stop();
  150.