function memory() {
this.createEmptyMovieClip("box",1);
var stime = getTimer();
timer.onEnterFrame = function() {
var gametime = getTimer() - stime;
var minuten = Math.floor(gametime / 60 / 1000);
var sekunden = Math.floor((gametime - minuten * 60 * 1000) / 1000);
this.timer.text = minuten + " : " + sekunden;
}
box._x = 100;
box._y = 100;
box.tiefe = 0;
box.anzahl = 12;
box.zeilen = 4;
box.spalten = (box.anzahl*2)/box.zeilen;
box.warten = false;
box.karte1 = "";
box.aTempNums = [];
for (var i = 1; i<=box.anzahl; i++) {
for (var j = 1; j<=2; j++) {
box.aTempNums.push(i);
}
}
box.aKarten = [];
while (box.aTempNums.length>0) {
var zufall = Math.floor(Math.random()*box.aTempNums.length);
box.aKarten.push(box.aTempNums[zufall]);
box.aTempNums.splice(zufall,1);
}
for (var i = 0; i<box.zeilen; i++) {
for (var j = 0; j<box.spalten; j++) {
box.attachMovie("mc_k"+box.aKarten[box.tiefe],"k"+box.tiefe+"_"+box.aKarten[box.tiefe],box.tiefe);
var obj = box["k"+box.tiefe+"_"+box.aKarten[box.tiefe]];
//test paar
//obj.onRollOver = function(){
// trace(this._name);
//}
//ende test
obj.onPress = function() {
if (!box.warten) {
box.umdrehen(this);
}
};
obj.stop();
obj._x = j*(obj._width+2);
obj._y = i*(obj._height+2);
box.tiefe++;
}
}
box.umdrehen = function(welche) {
if (box.karte1 == welche) {
return;
}
welche.play();
welche.onEnterFrame = function() {
if (this._currentframe>=this._totalframes) {
this.stop();
delete this.onEnterFrame;
}
};
if (box.karte1 == "") {
box.karte1 = welche;
} else {
box.warten = true;
pauseInterv = setInterval(box.pruefen, 1000, welche);
}
};
box.pruefen = function(wen) {
var eins = String(box.karte1).lastIndexOf("_");
var zwei = String(wen).lastIndexOf("_");
if (String(wen).substring(zwei+1) == String(box.karte1).substring(eins+1)) {
box.warten = false;
box.karte1.removeMovieClip();
wen.removeMovieClip();
box.karte1 = "";
box.anzahl -= 2;
if (box.anzahl <= 0) {
box.finished();
}
} else {
box.karte1.onEnterFrame = function() {
if (this._currentframe>1) {
this.gotoAndStop(this._currentframe-1);
} else {
box.warten = false;
this.stop();
box.karte1 = "";
delete this.onEnterFrame;
}
};
wen.onEnterFrame = function() {
if (this._currentframe>1) {
this.gotoAndStop(this._currentframe-1);
} else {
this.stop();
delete this.onEnterFrame;
}
};
}
clearInterval(pauseInterv);
};
box.finished = function() {
delete timer.onEnterFrame;
var gametime = getTimer() - stime;
var minuten = Math.floor(gametime / 60 / 1000);
var sekunden = Math.floor((gametime - minuten * 60 * 1000) / 1000);
this.timer.text = "Zeit: " + minuten + " : " + sekunden;
}
}
memory();