Frame 1
firstGame = 1;
snd1 = new Sound(_root.snd1);
snd1.attachSound("snd1");
stop();
Instance of Symbol 40 MovieClip in Frame 1
onClipEvent (enterFrame) {
text = ((int(_parent.getBytesLoaded() / 1000) + " OF ") + int(_parent.getBytesTotal() / 1000)) + " LOADED ...";
if (_parent.getBytesTotal() == _parent.getBytesLoaded()) {
_root.nextFrame();
}
}
Frame 2
function createRandomArray() {
var _local3 = 16;
n = new Array(_local3);
rnd = new Array(_local3);
var _local1 = 0;
while (_local1 < _local3) {
n[_local1] = _local1 + 1;
_local1++;
}
_local1 = 0;
while (n.length > 0) {
var _local2 = Math.round(Math.random() * (n.length - 1));
rnd[_local1] = n[_local2];
_local1++;
n.splice(_local2, 1);
}
}
function createFirstArray() {
var _local2 = 16;
rnd = new Array(_local2);
var _local1 = 0;
while (_local1 < 16) {
rnd[_local1] = _local1 + 1;
_local1++;
}
}
function buildMap() {
var count = 0;
var _local3 = 0;
while (_local3 < 4) {
var _local1 = 0;
while (_local1 < 4) {
this.attachMovie("tile", (("t_" + _local3) + "_") + _local1, ++d);
var _local2 = this[(("t_" + _local3) + "_") + _local1];
_local2._x = (_local1 * size) + space;
_local2._y = (_local3 * size) + space;
_local2.x = _local1;
_local2.y = _local3;
_local2.gotoAndStop(rnd[count]);
map[_local3][_local1] = rnd[count];
count++;
_local1++;
}
_local3++;
}
}
function moveObject(ob) {
var _local1 = ob;
pos = null;
if (map[_local1.y][_local1.x - 1] == 13) {
pos = "left";
} else if (map[_local1.y][_local1.x + 1] == 13) {
pos = "right";
} else if (map[_local1.y - 1][_local1.x] == 13) {
pos = "up";
} else if (map[_local1.y + 1][_local1.x] == 13) {
pos = "down";
}
if (pos != null) {
obj = _local1;
objCounter = 0;
snd1.start(0, 1);
}
}
function checkWin() {
var _local3 = 1;
var score = 0;
var _local2 = 0;
while (_local2 < 4) {
var _local1 = 0;
while (_local1 < 4) {
if (map[_local2][_local1] == _local3) {
score++;
}
_local3++;
_local1++;
}
_local2++;
}
if (score == 16) {
winLabel = "you win !";
}
}
map = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]];
_root.onMouseDown = function () {
if (!playGame) {
nextFrame();
} else {
var _local3 = int((_xmouse - space) / size);
var _local2 = int((_ymouse - space) / size);
var _local1 = this[(("t_" + _local2) + "_") + _local3];
if (obj != null) {
} else {
_local1.swapDepths(++d);
moveObject(_local1);
}
}
};
_root.onKeyDown = function () {
if (Key.isDown(17)) {
playGame = 0;
nextFrame();
}
if (Key.isDown(32)) {
playGame = 0;
spaceKey = 1;
nextFrame();
}
};
_root.onEnterFrame = function () {
var _local1 = this;
if (obj != null) {
if (pos == "left") {
obj._x = obj._x - 10;
objCounter++;
} else if (pos == "right") {
obj._x = obj._x + 10;
objCounter++;
} else if (pos == "up") {
obj._y = obj._y - 10;
objCounter++;
} else if (pos == "down") {
obj._y = obj._y + 10;
objCounter++;
}
if (objCounter == 8) {
if (pos == "left") {
_local1[(("t_" + obj.y) + "_") + obj.x].gotoAndStop(13);
_local1[(("t_" + obj.y) + "_") + (obj.x - 1)].gotoAndStop(map[obj.y][obj.x]);
_local1[(("t_" + obj.y) + "_") + obj.x]._x = _local1[(("t_" + obj.y) + "_") + obj.x]._x + 80;
map[obj.y][obj.x - 1] = map[obj.y][obj.x];
map[obj.y][obj.x] = 13;
} else if (pos == "right") {
_local1[(("t_" + obj.y) + "_") + obj.x].gotoAndStop(13);
_local1[(("t_" + obj.y) + "_") + (obj.x + 1)].gotoAndStop(map[obj.y][obj.x]);
_local1[(("t_" + obj.y) + "_") + obj.x]._x = _local1[(("t_" + obj.y) + "_") + obj.x]._x - 80;
map[obj.y][obj.x + 1] = map[obj.y][obj.x];
map[obj.y][obj.x] = 13;
} else if (pos == "down") {
_local1[(("t_" + obj.y) + "_") + obj.x].gotoAndStop(13);
_local1[(("t_" + (obj.y + 1)) + "_") + obj.x].gotoAndStop(map[obj.y][obj.x]);
_local1[(("t_" + obj.y) + "_") + obj.x]._y = _local1[(("t_" + obj.y) + "_") + obj.x]._y - 80;
map[obj.y + 1][obj.x] = map[obj.y][obj.x];
map[obj.y][obj.x] = 13;
} else if (pos == "up") {
_local1[(("t_" + obj.y) + "_") + obj.x].gotoAndStop(13);
_local1[(("t_" + (obj.y - 1)) + "_") + obj.x].gotoAndStop(map[obj.y][obj.x]);
_local1[(("t_" + obj.y) + "_") + obj.x]._y = _local1[(("t_" + obj.y) + "_") + obj.x]._y + 80;
map[obj.y - 1][obj.x] = map[obj.y][obj.x];
map[obj.y][obj.x] = 13;
}
pos = null;
obj = null;
moves++;
checkWin();
}
}
};
d = 0;
space = 20;
size = 80;
moves = 0;
spaceKey = 0;
winLabel = "";
obj = null;
if (firstGame) {
createFirstArray();
firstGame = 0;
playGame = 0;
} else {
createRandomArray();
playGame = 1;
}
buildMap();
Key.addListener(_root);
stop();
Frame 3
var i = 0;
while (i < 4) {
var j = 0;
while (j < 4) {
removeMovieClip(this[(("t_" + i) + "_") + j]);
j++;
}
i++;
}
if (!spaceKey) {
prevFrame();
} else {
firstGame = 1;
prevFrame();
}