Jay-sixer
04-20-2005, 03:33 PM
MoveUp = function (standClip) {
_global.ring = standClip.stack.pop();
_global.activeRing = _root["r"+ring];
endCount = 6;
dy = (100-activeRing._y)/endCount;
data = {dy:dy, endCount:endCount};
activeRing.dataQuerry.push(data);
activeRing.active = true;
};
dropDown = function (standClip) {
endCount = 5;
dx = (standClip._x-activeRing._x)/endCount;
data = {dx:dx, endCount:endCount};
activeRing.dataQuerry.push(data);
len = standClip.stack.length;
targetY = standClip._y-len*activeRing._height;
endCount = 6;
dy = (targetY-activeRing._y)/endCount;
data = {dy:dy, endCount:endCount};
activeRing.dataQuerry.push(data);
standClip.stack.push(_global.ring);
activeRing.active = true;
_global.activeRing = null;
};
checkPopable = function () {
// trace("check popable");
for (var p = 0; p<3; p++) {
var stand = _root["a"+p];
// trace(stand);
// trace(stand.stack);
if (stand.stack.length>0) {
stand.btn.enabled = true;
} else {
stand.btn.enabled = false;
}
}
};
checkPushable = function () {
for (var p = 0; p<3; p++) {
var stand = _root["a"+p];
len = stand.stack.length;
if (len<1 || _global.ring<stand.stack[len-1]) {
stand.btn.enabled = true;
} else {
stand.btn.enabled = false;
}
}
};
Frame 2:
stop();
init = function () {
a0.stack = [5, 4, 3, 2, 1];
a1.stack = [];
a2.stack = [];
for (var k = 1; k<=5; k++) {
clip = _root["r"+k];
clip._y = a0._y-(5-k)*clip._height;
clip._x = a0._x;
}
};
init();
on (release) {
ringPos = [];
for (var k = 0; k<3; k++) {
var stack2 = _root["a"+k].stack;
for (var j in stack2) {
ringPos[stack2[j]] = k;
}
}
solve2 = function (n, targetPos) {
if (n == 0) {
return;
}
var pos = ringPos[n];
if (pos == targetPos) {
return solve2(n-1, targetPos);
} else {
var spare = 3-targetPos-pos;
var s1 = solve2(n-1, spare)+"M"+pos+targetPos;
for (var k = 1; k<n; k++) {
ringPos[k] = spare;
}
ringPos[n] = targetPos;
var s2 = solve2(n-1, targetPos);
return s1+s2;
}
};
ans = solve2(5, 1);
//------------------------------------
a0.btn.enabled = a1.btn.enabled=a2.btn.enabled=false;
//---------------------------------------
index = -1;
this.createEmptyMovieClip("solver", 2);
solver.onEnterFrame = function() {
if (!_global.activeRing) {
//pick a move
if (upRing.active) {
return;
}
if (index>=ans.length) {
a0.btn.enabled = a1.btn.enabled=a2.btn.enabled=true;
this.removeMovieClip();
return;
}
index++;
moveUp(_root["a"+ans.substr(index, 1)]);
upRing = _global.activeRing;
return;
}
if (!_global.activeRing.active) {
index++;
dropDown(_root["a"+ans.substr(index, 1)]);
return;
}
};
}
This is from a program called Tower of Hanoi, and I simply only understand minor of it, I hope some professionel user of Flash 2004 MX user can help, cause I am using flash 5, so I just don't understand it...Well in the start yes its to functions for Move up for the brick then drop down for the brick else i don't understand, plz help?
_global.ring = standClip.stack.pop();
_global.activeRing = _root["r"+ring];
endCount = 6;
dy = (100-activeRing._y)/endCount;
data = {dy:dy, endCount:endCount};
activeRing.dataQuerry.push(data);
activeRing.active = true;
};
dropDown = function (standClip) {
endCount = 5;
dx = (standClip._x-activeRing._x)/endCount;
data = {dx:dx, endCount:endCount};
activeRing.dataQuerry.push(data);
len = standClip.stack.length;
targetY = standClip._y-len*activeRing._height;
endCount = 6;
dy = (targetY-activeRing._y)/endCount;
data = {dy:dy, endCount:endCount};
activeRing.dataQuerry.push(data);
standClip.stack.push(_global.ring);
activeRing.active = true;
_global.activeRing = null;
};
checkPopable = function () {
// trace("check popable");
for (var p = 0; p<3; p++) {
var stand = _root["a"+p];
// trace(stand);
// trace(stand.stack);
if (stand.stack.length>0) {
stand.btn.enabled = true;
} else {
stand.btn.enabled = false;
}
}
};
checkPushable = function () {
for (var p = 0; p<3; p++) {
var stand = _root["a"+p];
len = stand.stack.length;
if (len<1 || _global.ring<stand.stack[len-1]) {
stand.btn.enabled = true;
} else {
stand.btn.enabled = false;
}
}
};
Frame 2:
stop();
init = function () {
a0.stack = [5, 4, 3, 2, 1];
a1.stack = [];
a2.stack = [];
for (var k = 1; k<=5; k++) {
clip = _root["r"+k];
clip._y = a0._y-(5-k)*clip._height;
clip._x = a0._x;
}
};
init();
on (release) {
ringPos = [];
for (var k = 0; k<3; k++) {
var stack2 = _root["a"+k].stack;
for (var j in stack2) {
ringPos[stack2[j]] = k;
}
}
solve2 = function (n, targetPos) {
if (n == 0) {
return;
}
var pos = ringPos[n];
if (pos == targetPos) {
return solve2(n-1, targetPos);
} else {
var spare = 3-targetPos-pos;
var s1 = solve2(n-1, spare)+"M"+pos+targetPos;
for (var k = 1; k<n; k++) {
ringPos[k] = spare;
}
ringPos[n] = targetPos;
var s2 = solve2(n-1, targetPos);
return s1+s2;
}
};
ans = solve2(5, 1);
//------------------------------------
a0.btn.enabled = a1.btn.enabled=a2.btn.enabled=false;
//---------------------------------------
index = -1;
this.createEmptyMovieClip("solver", 2);
solver.onEnterFrame = function() {
if (!_global.activeRing) {
//pick a move
if (upRing.active) {
return;
}
if (index>=ans.length) {
a0.btn.enabled = a1.btn.enabled=a2.btn.enabled=true;
this.removeMovieClip();
return;
}
index++;
moveUp(_root["a"+ans.substr(index, 1)]);
upRing = _global.activeRing;
return;
}
if (!_global.activeRing.active) {
index++;
dropDown(_root["a"+ans.substr(index, 1)]);
return;
}
};
}
This is from a program called Tower of Hanoi, and I simply only understand minor of it, I hope some professionel user of Flash 2004 MX user can help, cause I am using flash 5, so I just don't understand it...Well in the start yes its to functions for Move up for the brick then drop down for the brick else i don't understand, plz help?