code:
function gameOver() {
attachMovie("gameOver", "gameOverr", _root.getNextHighestDepth(), {_x:180, _y:155});
for (i=0; i<hang; i++) {
for (j=0; j<lie; j++) {
delete block[i][j].onRelease;
}
}
}
hang = 5;
lie = 5;
ranLei = 4;
var block:Array = new Array();
var blocka:Array = new Array();
//set lei array
var dir = new Array();
dir[0] = new Array(1, 0);
dir[1] = new Array(1, 1);
dir[2] = new Array(0, 1);
dir[3] = new Array(-1, 1);
dir[4] = new Array(-1, 0);
dir[5] = new Array(-1, -1);
dir[6] = new Array(0, -1);
dir[7] = new Array(1, -1);
for (i=0; i<hang; i++) {
block[i] = new Array();
for (j=0; j<lie; j++) {
k = i*hang+j;
a = attachMovie("lei", k, k);
a._x = 20*j+21;
a._y = 20*i+21;
a.txt = 0;
a.go = 2;
a.x = i;
a.y = j;
a.f = 0;
block[i].push(a);
}
}
for (i=0; i<hang*lie; i++) {
blocka[i] = _root[i];
}
trace(blocka.length);
for (i=0; i<ranLei; i++) {
rand = random(blocka.length);
blocka[rand].go = 3;
blocka[rand].f = 1;
temp = blocka[rand];
blocka[rand] = blocka[blocka.length-1];
blocka[blocka.length-1] = temp;
blocka.pop();
}
for (i=0; i<hang; i++) {
for (j=0; j<lie; j++) {
if (block[i][j].go == 2) {
var t = 0;
for (k=0; k<dir.length; k++) {
if (block[i+dir[k][0]][j+dir[k][1]].go == 3) {
t++;
}
}
block[i][j].txt = t;
}
}
}
for (i=0; i<hang; i++) {
for (j=0; j<lie; j++) {
block[i][j].onRelease = function() {
if (this.go == 3) {
//trace(this.x);
//trace(this.y);
gameOver();
this.gotoAndStop(this.go);
delete this.onRelease;
} else {
//if (win() == 1) {
//attachMovie("win", "winn", _root.getNextHighestDepth(), {_x:160, _y:155});
//}
//win();
this.gotoAndStop(this.go);
delete this.onRelease;
}
};
}
}
stop();
this.f = 1;
if (this.txt != 0) {
wz = this.txt;
} else {
wz = "";
for (kk=0; kk<_root.dir.length; kk++) {
_root.block[this.x+_root.dir[kk][0]][this.y+_root.dir[kk][1]].gotoAndStop(_root.block[this.x+_root.dir[kk][0]][this.y+_root.dir[kk][1]].go);
delete this.onRelease;
delete _root.block[this.x+_root.dir[kk][0]][this.y+_root.dir[kk][1]].onRelease;
}
}
function win() {
youWin = 1;
for (i=0; i<_root.hang*_root.lie; i++) {
if (_root[i].f == 0) {
youWin = 0;
break;
}
}
return youWin;
}
if (win() == 1) {
trace("win");
_root.attachMovie("win", "winn", _root.getNextHighestDepth(), {_x:160, _y:155});
for (i=0; i<_root.hang*_root.lie; i++) {
delete _root[i].onRelease;
}
}