Готовые 15-ки
Код:
this.lineStyle (0, 0, 0);
this.beginFill (0x666666);
this.moveTo (10, 10);
this.lineTo (140, 10);
this.lineTo (140, 140);
this.lineTo (10, 140);
this.lineTo (10, 10);
this.endFill ();
/*******************************************************************/
f = new TextFormat ("Verdana", 13, 0xFF6600, true);
f.align = "center";
/*******************************************************************/
init = function () {
a = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 0]];
v = [[0,-1],[0,1],[-1,0],[1,0]]
x = 3;
y = 3;
for (p = 1; p < 200;){
r = random (4);
i = x + v[r][0];
j = y + v[r][1];
if (a[i][j] and a[i][j]!= o) {
o = a[i][j];
a[i][j] = a[x][y];
a[x][y] = o;
x = i;
y = j;
p++;
}
}
v = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 0]];
p = [[],[],[],[]];
for (i = 0; i < 4; i++) {
for (j = 0; j < 4; j++) {
p[i][j] = a[i][j];
if (a[i][j] != 0) {
createEmptyMovieClip ("m" + p[i][j], p[i][j]);
this["m" + p[i][j]].lineStyle (0, 0, 0);
this["m" + p[i][j]].beginFill (0x333333);
this["m" + p[i][j]].lineTo (30, 0);
this["m" + p[i][j]].lineTo (30, 30);
this["m" + p[i][j]].lineTo (0, 30);
this["m" + p[i][j]].lineTo (0, 0);
this["m" + p[i][j]].endFill ();
this["m" + p[i][j]].createTextField ("t", 0, 0, 3, 30, 30);
this["m" + p[i][j]].t.setNewTextFormat (f);
this["m" + p[i][j]].t.text = p[i][j];
this["m" + p[i][j]].i = i;
this["m" + p[i][j]].j = j;
this["m" + p[i][j]]._y = i * 32 + 12;
this["m" + p[i][j]]._x = j * 32 + 12;
this["m" + p[i][j]].onRelease = function () {
if (p[this.i][this.j - 1] == 0) {
this._x -= 32;
o = p[this.i][this.j - 1];
p[this.i][this.j - 1] = p[this.i][this.j];
p[this.i][this.j] = o;
this.j--;
} else if (p[this.i][this.j + 1] == 0) {
this._x += 32;
o = p[this.i][this.j + 1];
p[this.i][this.j + 1] = p[this.i][this.j];
p[this.i][this.j] = o;
this.j++;
} else if (p[this.i - 1][this.j] == 0) {
this._y -= 32;
o = p[this.i - 1][this.j];
p[this.i - 1][this.j] = p[this.i][this.j];
p[this.i][this.j] = o;
this.i--;
} else if (p[this.i + 1][this.j] == 0) {
this._y += 32;
o = p[this.i + 1][this.j];
p[this.i + 1][this.j] = p[this.i][this.j];
p[this.i][this.j] = o;
this.i++;
}
if (p.toString () == v.toString ()) {
for (i = 0; i < 16; i++) {
_root["m" + i].removeMovieClip ();
}
_root.createTextField ("t", 100, 0, 60, 150, 25);
_root.t.setNewTextFormat (f);
_root.t.selectable = false;
_root.t.text = "WIN";
_root.onMouseUp = function () {
delete _root.onMouseUp;
_root.init ();
};
}
}
}
}
}
};
init ();
|