- UID
- 343
- 帖子
- 987
- 精华
- 13
- 积分
- 7771
- 阅读权限
- 101
- 来自
- 哈尔滨工程大学
- 在线时间
- 124 小时
- 注册时间
- 2004-12-17
- 最后登录
- 2008-7-11
|
2楼
发表于 2007-9-18 21:03
| 只看该作者
-
- //--------------------
- // 版本:0.30
- // 开始日期:2007-09-10
- // 完成日期:2007-09-17
- // 更新历史:
- // 0.01:部分功能实现;
- // 0.10:更改了核心代码和算法,使得基本功能全部实现;
- // 0.20:增加了提示功能;
- // 0.30:增加了自动检测是否存在可消除方块的功能;
- //--------------------
- /*
- 全局变量说明:
- table_w:球阵的宽度;
- table_h:球阵的高度;
- balls:球的种类数;
- prx、pry:前次鼠标选中的球在矩阵中的坐标;
- nwx、nwy:本次鼠标选中的球在矩阵中的坐标;
- count0、count1、count2:过程计数器;
- mc0、mc1:用于存放两个被选中的球的电影剪辑名;
- zt:用于标示当前的可操作状态;
- cache:用于存储要消除的球的电影剪辑名;
- cache0:用于存储消除后下落的球的电影剪辑名;
- table:二维数组,用于标示对应点的球的种类。
- 函数功能及简要算法说明:
- showArray:显示出table的数据,调试程序用;
- update:刷新台面上所有球;
- test0:用于检测是否存在直接相连的同色球,返回布尔值;
- firstRun:初始化游戏,也用于重新开始;
- mb.onMouseDown:鼠标事件处理;
- box0:画出一个标记选中球的方框;
- timer0FC:将两个选中的临近球交换位置,如果不满足消去条件再交换回原位置;
- test1:检测选中球是否在交换后符合消去条件;
- test2:检测参数所定位的球是否满足消去条件;
- scf_check:将交换后能消去的球压入堆栈;
- scf_clean:将能消去的球从屏幕上抹去;
- scf_down:让数组向下塌陷,填补消去的空白;
- scf_fall:让屏幕上的球依次填补空白;
- creat:在空白处产生新的随机球;
- checks:检测下落和产生随机球后时候存在可消去的球;
- restart:重新开始;
- item:自动提示;
- changed:在屏幕上让提示的球闪烁;
- test3:用于检测是否存在可交换消去的球。
- */
- Stage.scaleMode = "noScale";
- var table_w:Number = 10;
- var table_h:Number = 10;
- var balls:Number = 8;
- var prx:Number = -1;
- var pry:Number = -1;
- var nwx:Number = -1;
- var nwy:Number = -1;
- var count0:Number = 0;
- var count1:Number = 0;
- var count2:Number = 0;
- var mc0:MovieClip;
- var mc1:MovieClip;
- var zt:Boolean = true;
- var cache:Array = new Array();
- var cache0:Array = new Array();
- var table:Array = new Array(table_w);
- for (var i = 0; i<table_w; i++) {
- table[i] = new Array(table_h);
- }
- _root.createEmptyMovieClip("box0_mc", 1000);
- showArray = function ():Void {
- for (var i = 0; i<table_w; i++) {
- trace(table[i].toString());
- }
- };
- update = function ():Void {
- for (var i = 0; i<table_w; i++) {
- for (var j = 0; j<table_h; j++) {
- var c = table[i][j];
- var s = table_w*i+j;
- _root.attachMovie("Ball", "ball"+s, s);
- _root["ball"+s]._x = 50*i+50;
- _root["ball"+s]._y = 50*j+50;
- _root["ball"+s].gotoAndStop(c+1);
- }
- }
- };
- test0 = function ():Boolean {
- var w = table_w-2;
- var h = table_h-2;
- for (var i = 0; i<w; i++) {
- for (var j = 0; j<h; j++) {
- if (table[i][j] == table[i][j+1] && table[i][j] == table[i][j+2]) {
- return true;
- }
- if (table[i][j] == table[i+1][j] && table[i][j] == table[i+2][j]) {
- return true;
- }
- }
- }
- for (var i = 0; i<h; i++) {
- if (table[w][i] == table[w][i+1] && table[w][j] == table[w][i+2]) {
- return true;
- }
- if (table[w+1][i] == table[w+1][i+1] && table[w+1][i] == table[w+1][i+2]) {
- return true;
- }
- }
- for (var i = 0; i<w; i++) {
- if (table[i][h] == table[i+1][h] && table[i][h] == table[i+2][h]) {
- return true;
- }
- if (table[i][h+1] == table[i+1][h+1] && table[i][h+1] == table[i+2][h+1]) {
- return true;
- }
- }
- return false;
- };
- firstRun = function ():Void {
- do {
- for (var i = 0; i<table_w; i++) {
- for (var j = 0; j<table_h; j++) {
- table[i][j] = random(balls)+1;
- }
- }
- } while (test0() == true && test3() == true);
- update();
- };
- mb.onMouseDown = function() {
- var x = Math.floor((_root._xmouse-25)/50);
- var y = Math.floor((_root._ymouse-25)/50);
- if (x>=0 && y>=0 && x<10 && y<10 && zt == true) {
- if (prx+pry<0) {
- prx = x;
- pry = y;
- zt = true;
- box0(x, y);
- } else {
- if (Math.abs(prx-x)+Math.abs(pry-y) == 1) {
- zt = false;
- nwx = x;
- nwy = y;
- mc0 = _root["ball"+(nwx*table_w+nwy)];
- mc1 = _root["ball"+(prx*table_w+pry)];
- if (pry>nwy) {
- count0 = 1;
- }
- if (prx<nwx) {
- count0 = 2;
- }
- if (pry<nwy) {
- count0 = 3;
- }
- if (prx>nwx) {
- count0 = 4;
- }
- count1 = 0;
- timer0 = setInterval(timer0FC, 40);
- } else {
- box0_mc.clear();
- prx = x;
- pry = y;
- box0(x, y);
- }
- }
- }
- };
- box0 = function (x:Number, y:Number):Void {
- var ix:Number = x*50+25;
- var iy:Number = y*50+25;
- with (box0_mc) {
- lineStyle(3, 0x00FF00, 100);
- moveTo(ix, iy);
- lineTo(ix+50, iy);
- lineTo(ix+50, iy+50);
- lineTo(ix, iy+50);
- lineTo(ix, iy);
- }
- };
- timer0FC = function ():Void {
- switch (count0) {
- case 1 :
- count1++;
- mc0._y += 5;
- mc1._y -= 5;
- break;
- case 2 :
- count1++;
- mc0._x -= 5;
- mc1._x += 5;
- break;
- case 3 :
- count1++;
- mc0._y -= 5;
- mc1._y += 5;
- break;
- case 4 :
- count1++;
- mc0._x += 5;
- mc1._x -= 5;
- break;
- default :
- trace("Error!");
- }
- if (count1 == 10) {
- test1();
- }
- if (count1 == 20) {
- clearInterval(timer0);
- zt = true;
- }
- };
- test1 = function ():Void {
- var c = table[nwx][nwy];
- table[nwx][nwy] = table[prx][pry];
- table[prx][pry] = c;
- if (test2(nwx, nwy) == false && test2(prx, pry) == false) {
- var c = table[nwx][nwy];
- table[nwx][nwy] = table[prx][pry];
- table[prx][pry] = c;
- switch (count0) {
- case 1 :
- count0 = 3;
- break;
- case 2 :
- count0 = 4;
- break;
- case 3 :
- count0 = 1;
- break;
- case 4 :
- count0 = 2;
- break;
- }
- trace(false);
- } else {
- mc0._x = nwx*50+50;
- mc0._y = nwy*50+50;
- mc0.gotoAndStop(table[nwx][nwy]+1);
- mc1._x = prx*50+50;
- mc1._y = pry*50+50;
- mc1.gotoAndStop(table[prx][pry]+1);
- clearInterval(timer0);
- trace(true);
- box0_mc.clear();
- scf_check();
- }
- };
- test2 = function (ix:Number, iy:Number):Boolean {
- if (iy<9 && table[ix][iy] == table[ix][iy+1] && table[ix][iy] == table[ix][iy+2]) {
- return true;
- }
- if (iy>0 && iy<10 && table[ix][iy] == table[ix][iy-1] && table[ix][iy] == table[ix][iy+1]) {
- return true;
- }
- if (iy>1 && table[ix][iy] == table[ix][iy-2] && table[ix][iy] == table[ix][iy-1]) {
- return true;
- }
- if (ix<9 && table[ix][iy] == table[ix+1][iy] && table[ix][iy] == table[ix+2][iy]) {
- return true;
- }
- if (ix>0 && ix<10 && table[ix-1][iy] == table[ix][iy] && table[ix][iy] == table[ix+1][iy]) {
- return true;
- }
- if (ix>1 && table[ix][iy] == table[ix-2][iy] && table[ix][iy] == table[ix-1][iy]) {
- return true;
- }
- return false;
- };
- scf_check = function ():Void {
- trace("nwx:"+nwx+" nwy:"+nwy+" prx:"+prx+" pry:"+pry);
- var enablenw:Boolean = false;
- var enablepr:Boolean = false;
- if (nwx == prx && nwy<pry) {
- trace("First:nwx == prx && nwy>pry");
- if (nwy>1 && table[nwx][nwy] == table[nwx][nwy-1] && table[nwx][nwy] == table[nwx][nwy-2]) {
- cache.push(_root["ball"+(nwx*table_w+nwy-1)]);
- cache.push(_root["ball"+(nwx*table_w+nwy-2)]);
- enablenw = true;
- }
- if (nwx>1 && nwx<9 && table[nwx][nwy] == table[nwx-2][nwy] && table[nwx][nwy] == table[nwx-1][nwy] && table[nwx][nwy] == table[nwx+1][nwy] && table[nwx][nwy] == table[nwx+2][nwy]) {
- //@@@@@
- cache.push(_root["ball"+((nwx-2)*table_w+nwy)]);
- cache.push(_root["ball"+((nwx-1)*table_w+nwy)]);
- cache.push(_root["ball"+((nwx+1)*table_w+nwy)]);
- cache.push(_root["ball"+((nwx+2)*table_w+nwy)]);
- enablenw = true;
- } else if (nwx>1 && nwx<10 && table[nwx][nwy] == table[nwx-2][nwy] && table[nwx][nwy] == table[nwx-1][nwy] && table[nwx][nwy] == table[nwx+1][nwy]) {
- //@@@@X
- cache.push(_root["ball"+((nwx-2)*table_w+nwy)]);
- cache.push(_root["ball"+((nwx-1)*table_w+nwy)]);
- cache.push(_root["ball"+((nwx+1)*table_w+nwy)]);
- //cache.push(_root["ball"+((nwx+2)*table_w+nwy)]);
- enablenw = true;
- } else if (nwx>0 && nwx<9 && table[nwx][nwy] == table[nwx-1][nwy] && table[nwx][nwy] == table[nwx+1][nwy] && table[nwx][nwy] == table[nwx+2][nwy]) {
- //X@@@@
- //cache.push(_root["ball"+((nwx-2)*table_w+nwy)]);
- cache.push(_root["ball"+((nwx-1)*table_w+nwy)]);
- cache.push(_root["ball"+((nwx+1)*table_w+nwy)]);
- cache.push(_root["ball"+((nwx+2)*table_w+nwy)]);
- enablenw = true;
- } else if (nwx>1 && table[nwx][nwy] == table[nwx-2][nwy] && table[nwx][nwy] == table[nwx-1][nwy]) {
- //@@@XX
- cache.push(_root["ball"+((nwx-2)*table_w+nwy)]);
- cache.push(_root["ball"+((nwx-1)*table_w+nwy)]);
- //cache.push(_root["ball"+((nwx+1)*table_w+nwy)]);
- //cache.push(_root["ball"+((nwx+2)*table_w+nwy)]);
- enablenw = true;
- } else if (nwx>0 && nwx<10 && table[nwx][nwy] == table[nwx-1][nwy] && table[nwx][nwy] == table[nwx+1][nwy]) {
- //X@@@X
- //cache.push(_root["ball"+((nwx-2)*table_w+nwy)]);
- cache.push(_root["ball"+((nwx-1)*table_w+nwy)]);
- cache.push(_root["ball"+((nwx+1)*table_w+nwy)]);
- //cache.push(_root["ball"+((nwx+2)*table_w+nwy)]);
- enablenw = true;
- } else if (nwx<9 && table[nwx][nwy] == table[nwx+1][nwy] && table[nwx][nwy] == table[nwx+2][nwy]) {
- //XX@@@
- //cache.push(_root["ball"+((nwx-2)*table_w+nwy)]);
- //cache.push(_root["ball"+((nwx-1)*table_w+nwy)]);
- cache.push(_root["ball"+((nwx+1)*table_w+nwy)]);
- cache.push(_root["ball"+((nwx+2)*table_w+nwy)]);
- enablenw = true;
- }
- if (enablenw == true) {
- cache.push(_root["ball"+(nwx*table_w+nwy)]);
- }
- if (pry<9 && table[prx][pry] == table[prx][pry+1] && table[prx][pry] == table[prx][pry+2]) {
- cache.push(_root["ball"+(prx*table_w+pry+1)]);
- cache.push(_root["ball"+(prx*table_w+pry+2)]);
- enablepr = true;
- }
- if (prx>1 && prx<9 && table[prx][pry] == table[prx-2][pry] && table[prx][pry] == table[prx-1][pry] && table[prx][pry] == table[prx+1][pry] && table[prx][pry] == table[prx+2][pry]) {
- //@@@@@
- cache.push(_root["ball"+((prx-2)*table_w+pry)]);
- cache.push(_root["ball"+((prx-1)*table_w+pry)]);
- cache.push(_root["ball"+((prx+1)*table_w+pry)]);
- cache.push(_root["ball"+((prx+2)*table_w+pry)]);
- enablepr = true;
- } else if (prx>1 && prx<10 && table[prx][pry] == table[prx-2][pry] && table[prx][pry] == table[prx-1][pry] && table[prx][pry] == table[prx+1][pry]) {
- //@@@@X
- cache.push(_root["ball"+((prx-2)*table_w+pry)]);
- cache.push(_root["ball"+((prx-1)*table_w+pry)]);
- cache.push(_root["ball"+((prx+1)*table_w+pry)]);
- //cache.push(_root["ball"+((prx+2)*table_w+pry)]);
- enablepr = true;
- } else if (prx>0 && prx<9 && table[prx][pry] == table[prx-1][pry] && table[prx][pry] == table[prx+1][pry] && table[prx][pry] == table[prx+2][pry]) {
- //X@@@@
- //cache.push(_root["ball"+((prx-2)*table_w+pry)]);
- cache.push(_root["ball"+((prx-1)*table_w+pry)]);
- cache.push(_root["ball"+((prx+1)*table_w+pry)]);
- cache.push(_root["ball"+((prx+2)*table_w+pry)]);
- enablepr = true;
- } else if (prx>1 && table[prx][pry] == table[prx-2][pry] && table[prx][pry] == table[prx-1][pry]) {
- //@@@XX
- cache.push(_root["ball"+((prx-2)*table_w+pry)]);
- cache.push(_root["ball"+((prx-1)*table_w+pry)]);
- //cache.push(_root["ball"+((prx+1)*table_w+pry)]);
- //cache.push(_root["ball"+((prx+2)*table_w+pry)]);
- enablepr = true;
- } else if (prx>0 && prx<10 && table[prx][pry] == table[prx-1][pry] && table[prx][pry] == table[prx+1][pry]) {
- //X@@@X
- //cache.push(_root["ball"+((prx-2)*table_w+pry)]);
- cache.push(_root["ball"+((prx-1)*table_w+pry)]);
- cache.push(_root["ball"+((prx+1)*table_w+pry)]);
- //cache.push(_root["ball"+((prx+2)*table_w+pry)]);
- enablepr = true;
- } else if (prx<9 && table[prx][pry] == table[prx+1][pry] && table[prx][pry] == table[prx+2][pry]) {
- //XX@@@
- //cache.push(_root["ball"+((prx-2)*table_w+pry)]);
- //cache.push(_root["ball"+((prx-1)*table_w+pry)]);
- cache.push(_root["ball"+((prx+1)*table_w+pry)]);
- cache.push(_root["ball"+((prx+2)*table_w+pry)]);
- enablepr = true;
- }
- if (enablepr == true) {
- cache.push(_root["ball"+(prx*table_w+pry)]);
- }
- }
- if (nwx == prx && nwy>pry) {
- trace("Second:nwx == prx && nwy<pry");
- if (nwy<9 && table[nwx][nwy] == table[nwx][nwy+1] && table[nwx][nwy] == table[nwx][nwy+2]) {
- cache.push(_root["ball"+(nwx*table_w+nwy+1)]);
- cache.push(_root["ball"+(nwx*table_w+nwy+2)]);
- enablenw = true;
- }
- if (nwx>1 && nwx<9 && table[nwx][nwy] == table[nwx-2][nwy] && table[nwx][nwy] == table[nwx-1][nwy] && table[nwx][nwy] == table[nwx+1][nwy] && table[nwx][nwy] == table[nwx+2][nwy]) {
- //@@@@@
- cache.push(_root["ball"+((nwx-2)*table_w+nwy)]);
- cache.push(_root["ball"+((nwx-1)*table_w+nwy)]);
- cache.push(_root["ball"+((nwx+1)*table_w+nwy)]);
- cache.push(_root["ball"+((nwx+2)*table_w+nwy)]);
- enablenw = true;
- } else if (nwx>1 && nwx<10 && table[nwx][nwy] == table[nwx-2][nwy] && table[nwx][nwy] == table[nwx-1][nwy] && table[nwx][nwy] == table[nwx+1][nwy]) {
- //@@@@X
- cache.push(_root["ball"+((nwx-2)*table_w+nwy)]);
- cache.push(_root["ball"+((nwx-1)*table_w+nwy)]);
- cache.push(_root["ball"+((nwx+1)*table_w+nwy)]);
- //cache.push(_root["ball"+((nwx+2)*table_w+nwy)]);
- enablenw = true;
- } else if (nwx>0 && nwx<9 && table[nwx][nwy] == table[nwx-1][nwy] && table[nwx][nwy] == table[nwx+1][nwy] && table[nwx][nwy] == table[nwx+2][nwy]) {
- //X@@@@
- //cache.push(_root["ball"+((nwx-2)*table_w+nwy)]);
- cache.push(_root["ball"+((nwx-1)*table_w+nwy)]);
- cache.push(_root["ball"+((nwx+1)*table_w+nwy)]);
- cache.push(_root["ball"+((nwx+2)*table_w+nwy)]);
- enablenw = true;
- } else if (nwx>1 && table[nwx][nwy] == table[nwx-2][nwy] && table[nwx][nwy] == table[nwx-1][nwy]) {
- //@@@XX
- cache.push(_root["ball"+((nwx-2)*table_w+nwy)]);
- cache.push(_root["ball"+((nwx-1)*table_w+nwy)]);
- //cache.push(_root["ball"+((nwx+1)*table_w+nwy)]);
- //cache.push(_root["ball"+((nwx+2)*table_w+nwy)]);
- enablenw = true;
- } else if (nwx>0 && nwx<10 && table[nwx][nwy] == table[nwx-1][nwy] && table[nwx][nwy] == table[nwx+1][nwy]) {
- //X@@@X
- //cache.push(_root["ball"+((nwx-2)*table_w+nwy)]);
- cache.push(_root["ball"+((nwx-1)*table_w+nwy)]);
- cache.push(_root["ball"+((nwx+1)*table_w+nwy)]);
- //cache.push(_root["ball"+((nwx+2)*table_w+nwy)]);
- enablenw = true;
- } else if (nwx<9 && table[nwx][nwy] == table[nwx+1][nwy] && table[nwx][nwy] == table[nwx+2][nwy]) {
- //XX@@@
- //cache.push(_root["ball"+((nwx-2)*table_w+nwy)]);
- //cache.push(_root["ball"+((nwx-1)*table_w+nwy)]);
- cache.push(_root["ball"+((nwx+1)*table_w+nwy)]);
- cache.push(_root["ball"+((nwx+2)*table_w+nwy)]);
- enablenw = true;
- }
- if (enablenw == true) {
- cache.push(_root["ball"+(nwx*table_w+nwy)]);
- }
- if (pry>1 && table[prx][pry] == table[prx][pry-1] && table[prx][pry] == table[prx][pry-2]) {
- cache.push(_root["ball"+(prx*table_w+pry-1)]);
- cache.push(_root["ball"+(prx*table_w+pry-2)]);
- enablepr = true;
- }
- if (prx>1 && prx<9 && table[prx][pry] == table[prx-2][pry] && table[prx][pry] == table[prx-1][pry] && table[prx][pry] == table[prx+1][pry] && table[prx][pry] == table[prx+2][pry]) {
- //@@@@@
- cache.push(_root["ball"+((prx-2)*table_w+pry)]);
- cache.push(_root["ball"+((prx-1)*table_w+pry)]);
- cache.push(_root["ball"+((prx+1)*table_w+pry)]);
- cache.push(_root["ball"+((prx+2)*table_w+pry)]);
- enablepr = true;
- } else if (prx>1 && prx<10 && table[prx][pry] == table[prx-2][pry] && table[prx][pry] == table[prx-1][pry] && table[prx][pry] == table[prx+1][pry]) {
- //@@@@X
- cache.push(_root["ball"+((prx-2)*table_w+pry)]);
- cache.push(_root["ball"+((prx-1)*table_w+pry)]);
- cache.push(_root["ball"+((prx+1)*table_w+pry)]);
- //cache.push(_root["ball"+((prx+2)*table_w+pry)]);
- enablepr = true;
- } else if (prx>0 && prx<9 && table[prx][pry] == table[prx-1][pry] && table[prx][pry] == table[prx+1][pry] && table[prx][pry] == table[prx+2][pry]) {
- //X@@@@
- //cache.push(_root["ball"+((prx-2)*table_w+pry)]);
- cache.push(_root["ball"+((prx-1)*table_w+pry)]);
- cache.push(_root["ball"+((prx+1)*table_w+pry)]);
- cache.push(_root["ball"+((prx+2)*table_w+pry)]);
- enablepr = true;
- } else if (prx>1 && table[prx][pry] == table[prx-2][pry] && table[prx][pry] == table[prx-1][pry]) {
- //@@@XX
- cache.push(_root["ball"+((prx-2)*table_w+pry)]);
- cache.push(_root["ball"+((prx-1)*table_w+pry)]);
- //cache.push(_root["ball"+((prx+1)*table_w+pry)]);
- //cache.push(_root["ball"+((prx+2)*table_w+pry)]);
- enablepr = true;
- } else if (prx>0 && prx<10 && table[prx][pry] == table[prx-1][pry] && table[prx][pry] == table[prx+1][pry]) {
- //X@@@X
- //cache.push(_root["ball"+((prx-2)*table_w+pry)]);
- cache.push(_root["ball"+((prx-1)*table_w+pry)]);
- cache.push(_root["ball"+((prx+1)*table_w+pry)]);
- //cache.push(_root["ball"+((prx+2)*table_w+pry)]);
- enablepr = true;
- } else if (prx<9 && table[prx][pry] == table[prx+1][pry] && table[prx][pry] == table[prx+2][pry]) {
- //XX@@@
- //cache.push(_root["ball"+((prx-2)*table_w+pry)]);
- //cache.push(_root["ball"+((prx-1)*table_w+pry)]);
- cache.push(_root["ball"+((prx+1)*table_w+pry)]);
- cache.push(_root["ball"+((prx+2)*table_w+pry)]);
- enablepr = true;
- }
- if (enablepr == true) {
- cache.push(_root["ball"+(prx*table_w+pry)]);
- }
- }
- if (nwy == pry && nwx>prx) {
- trace("Third:nwy == pry && nwx>prx");
- if (nwx<9 && table[nwx][nwy] == table[nwx+1][nwy] && table[nwx][nwy] == table[nwx+2][nwy]) {
- cache.push(_root["ball"+((nwx+1)*table_w+nwy)]);
- cache.push(_root["ball"+((nwx+2)*table_w+nwy)]);
- enablenw = true;
- }
- if (nwy>1 && nwy<9 && table[nwx][nwy] == table[nwx][nwy-2] && table[nwx][nwy] == table[nwx][nwy-1] && table[nwx][nwy] == table[nwx][nwy+1] && table[nwx][nwy] == table[nwx][nwy+2]) {
- //@@@@@
- cache.push(_root["ball"+(nwx*table_w+nwy-2)]);
- cache.push(_root["ball"+(nwx*table_w+nwy-1)]);
- cache.push(_root["ball"+(nwx*table_w+nwy+1)]);
- cache.push(_root["ball"+(nwx*table_w+nwy+2)]);
- enablenw = true;
- } else if (nwy>1 && nwy<10 && table[nwx][nwy] == table[nwx][nwy-2] && table[nwx][nwy] == table[nwx][nwy-1] && table[nwx][nwy] == table[nwx][nwy+1]) {
- //@@@@X
- cache.push(_root["ball"+(nwx*table_w+nwy-2)]);
- cache.push(_root["ball"+(nwx*table_w+nwy-1)]);
- cache.push(_root["ball"+(nwx*table_w+nwy+1)]);
- //cache.push(_root["ball"+(nwx*table_w+nwy+2)]);
- enablenw = true;
- } else if (nwy>0 && nwy<9 && table[nwx][nwy] == table[nwx][nwy-1] && table[nwx][nwy] == table[nwx][nwy+1] && table[nwx][nwy] == table[nwx][nwy+2]) {
- //X@@@@
- //cache.push(_root["ball"+(nwx*table_w+nwy-2)]);
- cache.push(_root["ball"+(nwx*table_w+nwy-1)]);
- cache.push(_root["ball"+(nwx*table_w+nwy+1)]);
- cache.push(_root["ball"+(nwx*table_w+nwy+2)]);
- enablenw = true;
- } else if (nwy>1 && table[nwx][nwy] == table[nwx][nwy-2] && table[nwx][nwy] == table[nwx][nwy-1]) {
- //@@@XX
- cache.push(_root["ball"+(nwx*table_w+nwy-2)]);
- cache.push(_root["ball"+(nwx*table_w+nwy-1)]);
- //cache.push(_root["ball"+(nwx*table_w+nwy+1)]);
- //cache.push(_root["ball"+(nwx*table_w+nwy+2)]);
- enablenw = true;
- } else if (nwy>0 && nwy<10 && table[nwx][nwy] == table[nwx][nwy-1] && table[nwx][nwy] == table[nwx][nwy+1]) {
- //X@@@X
- //cache.push(_root["ball"+(nwx*table_w+nwy-2)]);
- cache.push(_root["ball"+(nwx*table_w+nwy-1)]);
- cache.push(_root["ball"+(nwx*table_w+nwy+1)]);
- //cache.push(_root["ball"+(nwx*table_w+nwy+2)]);
- enablenw = true;
- } else if (nwy<9 && table[nwx][nwy] == table[nwx][nwy+1] && table[nwx][nwy] == table[nwx][nwy+2]) {
- //XX@@@
- //cache.push(_root["ball"+(nwx*table_w+nwy-2)]);
- //cache.push(_root["ball"+(nwx*table_w+nwy-1)]);
- cache.push(_root["ball"+(nwx*table_w+nwy+1)]);
- cache.push(_root["ball"+(nwx*table_w+nwy+2)]);
- enablenw = true;
- }
- if (enablenw == true) {
- cache.push(_root["ball"+(nwx*table_w+nwy)]);
- }
- if (prx>1 && table[prx][pry] == table[prx-1][pry] && table[prx][pry] == table[prx-2][pry]) {
- cache.push(_root["ball"+((prx-1)*table_w+pry)]);
- cache.push(_root["ball"+((prx-2)*table_w+pry)]);
- enablepr = true;
- }
- if (pry>1 && pry<9 && table[prx][pry] == table[prx][pry-2] && table[prx][pry] == table[prx][pry-1] && table[prx][pry] == table[prx][pry+1] && table[prx][pry] == table[prx][pry+2]) {
- //@@@@@
- cache.push(_root["ball"+(prx*table_w+pry-2)]);
- cache.push(_root["ball"+(prx*table_w+pry-1)]);
- cache.push(_root["ball"+(prx*table_w+pry+1)]);
- cache.push(_root["ball"+(prx*table_w+pry+2)]);
- enablepr = true;
- } else if (pry>1 && pry<10 && table[prx][pry] == table[prx][pry-2] && table[prx][pry] == table[prx][pry-1] && table[prx][pry] == table[prx][pry+1]) {
- //@@@@X
- cache.push(_root["ball"+(prx*table_w+pry-2)]);
- cache.push(_root["ball"+(prx*table_w+pry-1)]);
- cache.push(_root["ball"+(prx*table_w+pry+1)]);
- //cache.push(_root["ball"+(prx*table_w+pry+2)]);
- enablepr = true;
- } else if (pry>0 && pry<9 && table[prx][pry] == table[prx][pry-1] && table[prx][pry] == table[prx][pry+1] && table[prx][pry] == table[prx][pry+2]) {
- //X@@@@
- //cache.push(_root["ball"+(prx*table_w+pry-2)]);
- cache.push(_root["ball"+(prx*table_w+pry-1)]);
- cache.push(_root["ball"+(prx*table_w+pry+1)]);
- cache.push(_root["ball"+(prx*table_w+pry+2)]);
- enablepr = true;
- } else if (pry>1 && table[prx][pry] == table[prx][pry-2] && table[prx][pry] == table[prx][pry-1]) {
- //@@@XX
- cache.push(_root["ball"+(prx*table_w+pry-2)]);
- cache.push(_root["ball"+(prx*table_w+pry-1)]);
- //cache.push(_root["ball"+(prx*table_w+pry+1)]);
- //cache.push(_root["ball"+(prx*table_w+pry+2)]);
- enablepr = true;
- } else if (pry>0 && pry<10 && table[prx][pry] == table[prx][pry-1] && table[prx][pry] == table[prx][pry+1]) {
- //X@@@X
- //cache.push(_root["ball"+(prx*table_w+pry-2)]);
- cache.push(_root["ball"+(prx*table_w+pry-1)]);
- cache.push(_root["ball"+(prx*table_w+pry+1)]);
- //cache.push(_root["ball"+(prx*table_w+pry+2)]);
- enablepr = true;
- } else if (pry<9 && table[prx][pry] == table[prx][pry+1] && table[prx][pry] == table[prx][pry+2]) {
- //XX@@@
- //cache.push(_root["ball"+(prx*table_w+pry-2)]);
- //cache.push(_root["ball"+(prx*table_w+pry-1)]);
- cache.push(_root["ball"+(prx*table_w+pry+1)]);
- cache.push(_root["ball"+(prx*table_w+pry+2)]);
- enablepr = true;
- }
- if (enablepr == true) {
- cache.push(_root["ball"+(prx*table_w+pry)]);
- }
- }
- if (nwy == pry && nwx<prx) {
- trace("Forth:nwy == pry && nwx<prx");
- if (nwx>1 && table[nwx][nwy] == table[nwx-1][nwy] && table[nwx][nwy] == table[nwx-2][nwy]) {
- cache.push(_root["ball"+((nwx-1)*table_w+nwy)]);
- cache.push(_root["ball"+((nwx-2)*table_w+nwy)]);
- enablenw = true;
- }
- if (nwy>1 && nwy<9 && table[nwx][nwy] == table[nwx][nwy-2] && table[nwx][nwy] == table[nwx][nwy-1] && table[nwx][nwy] == table[nwx][nwy+1] && table[nwx][nwy] == table[nwx][nwy+2]) {
- //@@@@@
- cache.push(_root["ball"+(nwx*table_w+nwy-2)]);
- cache.push(_root["ball"+(nwx*table_w+nwy-1)]);
- cache.push(_root["ball"+(nwx*table_w+nwy+1)]);
- cache.push(_root["ball"+(nwx*table_w+nwy+2)]);
- enablenw = true;
- } else if (nwy>1 && nwy<10 && table[nwx][nwy] == table[nwx][nwy-2] && table[nwx][nwy] == table[nwx][nwy-1] && table[nwx][nwy] == table[nwx][nwy+1]) {
- //@@@@X
- cache.push(_root["ball"+(nwx*table_w+nwy-2)]);
- cache.push(_root["ball"+(nwx*table_w+nwy-1)]);
- cache.push(_root["ball"+(nwx*table_w+nwy+1)]);
- //cache.push(_root["ball"+(nwx*table_w+nwy+2)]);
- enablenw = true;
- } else if (nwy>0 && nwy<9 && table[nwx][nwy] == table[nwx][nwy-1] && table[nwx][nwy] == table[nwx][nwy+1] && table[nwx][nwy] == table[nwx][nwy+2]) {
- //X@@@@
- //cache.push(_root["ball"+(nwx*table_w+nwy-2)]);
- cache.push(_root["ball"+(nwx*table_w+nwy-1)]);
- cache.push(_root["ball"+(nwx*table_w+nwy+1)]);
- cache.push(_root["ball"+(nwx*table_w+nwy+2)]);
- enablenw = true;
- } else if (nwy>1 && table[nwx][nwy] == table[nwx][nwy-2] && table[nwx][nwy] == table[nwx][nwy-1]) {
- //@@@XX
- cache.push(_root["ball"+(nwx*table_w+nwy-2)]);
- cache.push(_root["ball"+(nwx*table_w+nwy-1)]);
- //cache.push(_root["ball"+(nwx*table_w+nwy+1)]);
- //cache.push(_root["ball"+(nwx*table_w+nwy+2)]);
- enablenw = true;
- } else if (nwy>0 && nwy<10 && table[nwx][nwy] == table[nwx][nwy-1] && table[nwx][nwy] == table[nwx][nwy+1]) {
- //X@@@X
- //cache.push(_root["ball"+(nwx*table_w+nwy-2)]);
- cache.push(_root["ball"+(nwx*table_w+nwy-1)]);
- cache.push(_root["ball"+(nwx*table_w+nwy+1)]);
- //cache.push(_root["ball"+(nwx*table_w+nwy+2)]);
- enablenw = true;
- } else if (nwy<9 && table[nwx][nwy] == table[nwx][nwy+1] && table[nwx][nwy] == table[nwx][nwy+2]) {
- //XX@@@
- //cache.push(_root["ball"+(nwx*table_w+nwy-2)]);
- //cache.push(_root["ball"+(nwx*table_w+nwy-1)]);
- cache.push(_root["ball"+(nwx*table_w+nwy+1)]);
- cache.push(_root["ball"+(nwx*table_w+nwy+2)]);
- enablenw = true;
- }
- if (enablenw == true) {
- cache.push(_root["ball"+(nwx*table_w+nwy)]);
- }
- if (prx<9 && table[prx][pry] == table[prx+1][pry] && table[prx][pry] == table[prx+2][pry]) {
- cache.push(_root["ball"+((prx+1)*table_w+pry)]);
- cache.push(_root["ball"+((prx+2)*table_w+pry)]);
- enablepr = true;
- }
- if (pry>1 && pry<9 && table[prx][pry] == table[prx][pry-2] && table[prx][pry] == table[prx][pry-1] && table[prx][pry] == table[prx][pry+1] && table[prx][pry] == table[prx][pry+2]) {
- //@@@@@
- cache.push(_root["ball"+(prx*table_w+pry-2)]);
- cache.push(_root["ball"+(prx*table_w+pry-1)]);
- cache.push(_root["ball"+(prx*table_w+pry+1)]);
- cache.push(_root["ball"+(prx*table_w+pry+2)]);
- enablepr = true;
- } else if (pry>1 && pry<10 && table[prx][pry] == table[prx][pry-2] && table[prx][pry] == table[prx][pry-1] && table[prx][pry] == table[prx][pry+1]) {
- //@@@@X
- cache.push(_root["ball"+(prx*table_w+pry-2)]);
- cache.push(_root["ball"+(prx*table_w+pry-1)]);
- cache.push(_root["ball"+(prx*table_w+pry+1)]);
- //cache.push(_root["ball"+(prx*table_w+pry+2)]);
- enablepr = true;
- } else if (pry>0 && pry<9 && table[prx][pry] == table[prx][pry-1] && table[prx][pry] == table[prx][pry+1] && table[prx][pry] == table[prx][pry+2]) {
- //X@@@@
- //cache.push(_root["ball"+(prx*table_w+pry-2)]);
- cache.push(_root["ball"+(prx*table_w+pry-1)]);
- cache.push(_root["ball"+(prx*table_w+pry+1)]);
- cache.push(_root["ball"+(prx*table_w+pry+2)]);
- enablepr = true;
- } else if (pry>1 && table[prx][pry] == table[prx][pry-2] && table[prx][pry] == table[prx][pry-1]) {
- //@@@XX
- cache.push(_root["ball"+(prx*table_w+pry-2)]);
- cache.push(_root["ball"+(prx*table_w+pry-1)]);
- //cache.push(_root["ball"+(prx*table_w+pry+1)]);
- //cache.push(_root["ball"+(prx*table_w+pry+2)]);
- enablepr = true;
- } else if (pry>0 && pry<10 && table[prx][pry] == table[prx][pry-1] && table[prx][pry] == table[prx][pry+1]) {
- //X@@@X
- //cache.push(_root["ball"+(prx*table_w+pry-2)]);
- cache.push(_root["ball"+(prx*table_w+pry-1)]);
- cache.push(_root["ball"+(prx*table_w+pry+1)]);
- //cache.push(_root["ball"+(prx*table_w+pry+2)]);
- enablepr = true;
- } else if (pry<9 && table[prx][pry] == table[prx][pry+1] && table[prx][pry] == table[prx][pry+2]) {
- //XX@@@
- //cache.push(_root["ball"+(prx*table_w+pry-2)]);
- //cache.push(_root["ball"+(prx*table_w+pry-1)]);
- cache.push(_root["ball"+(prx*table_w+pry+1)]);
- cache.push(_root["ball"+(prx*table_w+pry+2)]);
- enablepr = true;
- }
- if (enablepr == true) {
- cache.push(_root["ball"+(prx*table_w+pry)]);
- }
- }
- count2 = 0;
- timer1 = setInterval(scf_clean, 100);
- };
- scf_clean = function ():Void {
- if (cache[0]._alpha<=0) {
- for (var i = 0; i<cache.length; i++) {
- cache[i]._alpha = 100;
- cache[i]._xscale = 100;
- cache[i]._yscale = 100;
- cache[i].gotoAndStop(1);
- }
- clearInterval(timer1);
- scf_down();
- } else {
- for (var i = 0; i<cache.length; i++) {
- cache[i]._alpha -= 10;
- cache[i]._xscale -= 10;
- cache[i]._yscale -= 10;
- }
- }
- };
- scf_down = function ():Void {
- for (var i = 0; i<cache.length; i++) {
- var ix = (cache[i]._x-50)/50;
- var iy = (cache[i]._y-50)/50;
- table[ix][iy] = -1;
- }
- for (var i = 0; i<table_w; i++) {
- for (var j = table_h; j>=0; j--) {
- if (table[i][j]<0) {
- var s:Number = 0;
- do {
- s++;
- } while (s<=j && table[i][j-s]<0);
- if (table[i][j-s] == undefined) {
- table[i][j] = -1;
- } else {
- table[i][j] = table[i][j-s];
- table[i][j-s] = -1;
- }
- cache0.push(_root["ball"+(i*table_w+j)]);
- }
- }
- }
- for (var i = 0; i<cache.length; i++) {
- for (var j = 0; j<cache0.length; j++) {
- if (cache[i] == cache0[j]) {
- cache0.splice(j, 1);
- break;
- }
- }
- }
- count1 = 0;
- timer2 = setInterval(scf_fall, 50);
- };
- scf_fall = function () {
- var ix = cache0[count1]._x/50-1;
- var iy = cache0[count1]._y/50-1;
- var s = ix*table_w+iy;
- var c = 0;
- do {
- c++;
- } while (_root["ball"+(s+c)]._currentframe == 1);
- _root["ball"+(s+c-1)].gotoAndStop(_root["ball"+s]._currentframe);
- _root["ball"+s].gotoAndStop(1);
- count1++;
- if (count1>cache0.length) {
- clearInterval(timer2);
- creat();
- }
- };
- creat = function () {
- for (var i = 0; i<table_w; i++) {
- for (var j = 0; j<table_h; j++) {
- if (table[i][j]<0) {
- table[i][j] = random(balls)+1;
- }
- }
- }
- update();
- //showArray();
- checks();
- };
- checks = function () {
- cache = new Array();
- cache0 = new Array();
- for (var i = 0; i<table_w; i++) {
- for (var j = 0; j<table_h; j++) {
- if (test2(i, j) == true) {
- cache.push(_root["ball"+(i*table_w+j)]);
- }
- }
- }
- if (cache.length>0) {
- count2 = 0;
- timer1 = setInterval(scf_clean, 100);
- } else {
- prx = -1;
- pry = -1;
- cache = new Array();
- cache0 = new Array();
- zt = true;
- if (test3() == false) {
- restart();
- }
- }
- };
- restart = function ():Void {
- my_cmi.enabled = false;
- box0_mc.clear();
- prx = -1;
- pry = -1;
- nwx = -1;
- nwy = -1;
- cache = new Array();
- cache0 = new Array();
- firstRun();
- zt = true;
- my_cmi.enabled = true;
- };
- item = function () {
- if (test3() == true) {
- zt = false;
- for (var i = 1; i<table_w; i++) {
- for (var j = 1; j<table_h; j++) {
- var c = table[i-1][j];
- table[i-1][j] = table[i][j];
- table[i][j] = c;
- if (test2(i, j) == true || test2(i-1, j) == true) {
- var c = table[i-1][j];
- table[i-1][j] = table[i][j];
- table[i][j] = c;
- count0 = 0;
- timer3 = setInterval(changed, 200, _root["ball"+(i*table_w+j)], _root["ball"+((i-1)*table_w+j)]);
- i = table_w;
- j = table_h;
- } else {
- var c = table[i-1][j];
- table[i-1][j] = table[i][j];
- table[i][j] = c;
- c = table[i][j-1];
- table[i][j-1] = table[i][j];
- table[i][j] = c;
- if (test2(i, j) == true || test2(i, j-1) == true) {
- var c = table[i][j-1];
- table[i][j-1] = table[i][j];
- table[i][j] = c;
- count0 = 0;
- timer3 = setInterval(changed, 200, _root["ball"+(i*table_w+j)], _root["ball"+(i*table_w+j-1)]);
- i = table_w;
- j = table_h;
- } else {
- var c = table[i][j-1];
- table[i][j-1] = table[i][j];
- table[i][j] = c;
- }
- }
- }
- }
- } else {
- restart();
- }
- };
- changed = function (mc0_mc:MovieClip, mc1_mc:MovieClip) {
- if (mc0_mc._currentframe == 10 && mc1_mc._currentframe == 10) {
- update();
- } else {
- mc0_mc.gotoAndStop(10);
- mc0_mc._xscale = 150;
- mc0_mc._yscale = 150;
- mc1_mc.gotoAndStop(10);
- mc1_mc._xscale = 150;
- mc1_mc._yscale = 150;
- }
- if (++count0>6) {
- update();
- clearInterval(timer3);
- zt = true;
- }
- };
- test3 = function ():Boolean {
- for (var i = 1; i<table_w; i++) {
- for (var j = 1; j<table_h; j++) {
- var c = table[i-1][j];
- table[i-1][j] = table[i][j];
- table[i][j] = c;
- if (test2(i, j) == true || test2(i-1, j) == true) {
- var c = table[i-1][j];
- table[i-1][j] = table[i][j];
- table[i][j] = c;
- return true;
- } else {
- var c = table[i-1][j];
- table[i-1][j] = table[i][j];
- table[i][j] = c;
- c = table[i][j-1];
- table[i][j-1] = table[i][j];
- table[i][j] = c;
- if (test2(i, j) == true || test2(i, j-1) == true) {
- var c = table[i][j-1];
- table[i][j-1] = table[i][j];
- table[i][j] = c;
- return true;
- } else {
- var c = table[i][j-1];
- table[i][j-1] = table[i][j];
- table[i][j] = c;
- }
- }
- }
- }
- return false;
- };
- firstRun();
- var my_cm:ContextMenu = new ContextMenu();
- var my0_cmi:ContextMenuItem = new ContextMenuItem("提示", item);
- var my1_cmi:ContextMenuItem = new ContextMenuItem("重新开始", restart, true);
- my_cm.customItems.push(my0_cmi, my1_cmi);
- //my_cm.customItems.push(my1_cmi);
- my_cm.hideBuiltInItems();
- _root.menu = my_cm;
复制代码 |
|