hjælp til Puzzle (MX)
Hej E'sLillebror er gået på flash og fidler med de samples som ligger med i goodies pakken til MX, jeg troede jeg kunne fixe det, man ak det går helt galt :-/
Anyway vi vil fjerne funktionen som roterer brikkerne, brikkerne skal altså være låst og de skal ligge rigtigt ved load.
er der nogen med falke øje derude ;))
koden ser sådan ud: (og .fla'en ligger i MX mappen)
stop()
// set and declare initial properties and variables
pattern._visible = 0;
image._visible = 0;
timerToggle._visible = 0;
pieceNumbers._visible = 0;
edges._visible = 0;
scrambleButton._visible = 0;
areYouSure._visible = 0;
congrats._visible = 0;
unpauseButton._visible = 0;
pauseButton._visible = 0;
mustUnpause._visible = 0;
timing = false;
dialog = true;
numberCircle.useHandCursor = false;
mustUnpause.swapdepths(1000000);
areYouSure.swapdepths(1000001);
columns = 7;
//
// create a class for the puzzle pieces, register tham all to the class, make them appear on stage and arrange them into a grid
function pieceClass() {}
pieceClass.prototype = new MovieClip();
for (var i = 1; i<50; i++) {
Object.registerClass("puzzle"+i, pieceClass);
this.attachMovie("puzzle"+i, "piece"+i, i-50);
}
arrange();
//
// functions (named according to what they do)
function arrange() {
for (var i = 1; i<50; i++) {
var row = Math.ceil(i/columns);
var column = i-((row-1)*columns);
with (this["piece"+i]) {
_x = column*40+20;
_y = row*40+20;
_rotation = 0;
}
}
}
function scramble() {
for (var i = 1; i<50; i++) {
with (this["piece"+i]) {
_x = Math.floor(Math.random()*400)+360;
_y = Math.floor(Math.random()*400)+40;
_rotation = Math.floor(Math.random()*4)*90;
}
}
}
//
function snap(whichPiece) {
if (whichPiece._x>40 && whichPiece._x<320 && whichPiece._y>40 && whichPiece._y<320) {
var xSnapNumber = Math.floor((whichPiece._x-20)/40);
var ySnapNumber = Math.floor((whichPiece._y-20)/40);
if (((whichPiece._x-20)%40)/40<.5) {
whichPiece._x = xSnapNumber*40+20;
} else {
whichPiece._x = (xSnapNumber+1)*40+20;
}
if (((whichPiece._y-20)%40)/40<.5) {
whichPiece._y = ySnapNumber*40+20;
} else {
whichPiece._y = (ySnapNumber+1)*40+20;
}
}
}
//
function isItDone() {
for (var i = 1; i<50; i++) {
var row = Math.ceil(i/columns);
var column = i-((row-1)*columns);
with (this["piece"+i]) {
if (_x != column*40+20 || _y != row*40+20 || _rotation != 0) {
break;
}
}
}
if (i == 50) {
pause();
dialog = true;
congrats._visible = 1;
if (hours>0) {
congratsText = hours+" hours "+minutes+" minutes "+seconds+" seconds.";
} else {
congratsText = minutes+" minutes "+seconds+" seconds.";
}
}
}
//
function restartTimer() {
timing = true;
buttonPressTime = getTimer()/1000-pauseLength;
}
//
function pause() {
pauseTime = getTimer()/1000;
timing = false;
}
//
function unpause() {
unpauseTime = getTimer()/1000;
pauseLength = (unpauseTime-pauseTime)+pauseLength;
timing = true;
}
//
this.onEnterFrame = function() {
// when rolling over a piece, change cursor to hand cursor only if timer is running
pieceClass.prototype.useHandCursor = timing;
//
// run the timer
totalTime = getTimer()/1000-pauseLength;
goTime = totalTime-buttonPressTime;
if (timing) {
hours = Math.floor(goTime/3600);
minutes = Math.floor((goTime/3600-hours)*60);
seconds = Math.floor(((goTime/3600-hours)*60-minutes)*60);
if (seconds<10) {
seconds = "0"+seconds;
}
if (minutes<10) {
minutes = "0"+minutes;
}
if (hours<10) {
hours = "0"+hours;
}
}
//
// rotate the Option/Alt-clicked piece
if (rotating && increment<6) {
rotater._rotation += 15;
increment++;
if (increment == 6) {
isItDone();
}
} else {
rotating = false;
}
};
//
// determine what to do to all symbols registered to pieceClass (all the pieces) when they are clicked and released
pieceClass.prototype.onPress = function() {
if (!rotating) {
if (timing) {
depth++;
this.swapDepths(depth);
this.startDrag(false, 20, 20, 780, 580);
if (Key.isDown(16)) {
pieceNumber = this._name.slice(5);
}
if (Key.isDown(18)) {
rotating = true;
rotater = this;
increment = 0;
}
} else if (!dialog) {
dialog = true;
mustUnpause._visible = 1;
}
}
};
pieceClass.prototype.onRelease = function() {
stopDrag();
snap(this);
if (!dialog) {
isItDone();
}
};
//
// main stage buttons
patternButton.onRelease = function() {
edges._visible = false;
pattern._visible = !pattern._visible;
};
edgesButton.onRelease = function() {
pattern._visible = false;
edges._visible = !edges._visible;
};
numbersButton.onRelease = function() {
pieceNumbers._visible = !pieceNumbers._visible;
};
bevelButton.onRelease = function() {
for (i=1; i<=49; i++) {
_root["piece"+i].bevel._visible = !_root["piece"+i].bevel._visible;
}
};
previewButton.onPress = function() {
_root.image._visible = 1;
};
previewButton.onRelease = preview;
previewButton.onReleaseOutside = preview;
function preview() {
_root.image._visible = 0;
if (Key.isDown(18)) {
_root.image._visible = 1;
}
}
timerToggle.timerButton.onRelease = function() {
timer._visible = !timer._visible;
};
scrambleButton.button.onRelease = function() {
if (!dialog) {
areYouSure._visible = 1;
if (timing) {
unpauseButton._visible = 1;
pauseButton._visible = 0;
pause();
}
}
dialog = true;
};
pauseButton.onRelease = function() {
if (!dialog) {
pause();
unpauseButton._visible = 1;
pauseButton._visible = 0;
}
};
pauseButton.onRollOver = function() {
rotateInstruct._visible = 0;
};
pauseButton.onRollOut = function() {
rotateInstruct._visible = 1;
};
unpauseButton.onRelease = function() {
if (!dialog) {
unpause();
pauseButton._visible = 1;
unpauseButton._visible = 0;
}
};
unpauseButton.onRollOver = function() {
rotateInstruct._visible = 0;
};
unpauseButton.onRollOut = function() {
rotateInstruct._visible = 1;
};
numberCircle.onRollOver = function() {
rotateInstruct._visible = 0;
};
numberCircle.onRollOut = function() {
rotateInstruct._visible = 1;
};
cheatButton.useHandCursor = false;
cheatButton.onRelease = function() {
arrange();
};
//
// dialog buttons
startPuzzle.ok.onRelease = function() {
scramble();
restartTimer();
timer._visible = 1;
timerToggle._visible = 1;
scrambleButton._visible = 1;
pauseButton._visible = 1;
dialog = false;
startPuzzle._visible = 0;
};
mustUnpause.ok.onRelease = function() {
timer._visible = 1;
dialog = false;
mustUnpause._visible = 0;
};
congrats.ok.onRelease = function() {
scramble();
restartTimer();
timer._visible = 1;
timerToggle._visible = 1;
scrambleButton._visible = 1;
dialog = false;
congrats._visible = 0;
};
areYouSure.ok.onRelease = function() {
scramble();
restartTimer();
timer._visible = 1;
timerToggle._visible = 1;
unpausebutton._visible = 0;
pauseButton._visible = 1;
dialog = false;
areYouSure._visible = 0;
};
areYouSure.cancel.onRelease = function() {
dialog = false;
unpause();
unpauseButton._visible = 0;
pauseButton._visible = 1;
areYouSure._visible = 0;
};
