Frame 2
function newGame() {
goodjob._visible = false;
numCards = 8;
flippedCards = [];
matchCard = 0;
matches = 0;
misses = 0;
score = 0;
scoretxt.embedFonts = true;
scoretxt.setTextFormat("scorefont");
scoretxt.text = score;
matchestxt.embedFonts = true;
matchestxt.setTextFormat("scorefont");
matchestxt.text = matches;
missestxt.embedFonts = true;
missestxt.setTextFormat("scorefont");
missestxt.text = misses;
i = 1;
while (i < (numCards + 1)) {
this["card" + i].id = i;
this["card" + i]._visible = true;
this["card" + i]._alpha = 100;
this["card" + i].duplicateMovieClip("card" + (numCards + i), numCards + (i * 10));
this["card" + (numCards + i)].id = i;
i++;
}
placeCards();
}
function placeCards() {
cardArray = [];
cardsPerRow = 4;
curRow = 1;
cardtop._visible = false;
i = 1;
while (i < ((numCards * 2) + 1)) {
cardtop.duplicateMovieClip("cardtop" + i, i * 100);
if (i > (cardsPerRow * curRow)) {
this["cardtop" + i]._y = this["cardtop" + i]._y + ((this["cardtop" + i]._height + 10) * curRow);
curRow++;
} else {
this["cardtop" + i]._y = this["cardtop" + (i - 1)]._y;
this["cardtop" + i]._x = (this["cardtop" + (i - 1)]._x + this["cardtop" + i]._width) + 10;
}
this["cardtop" + i].onRelease = function () {
this.flip("notflipped");
};
cardArray.push("card" + i);
i++;
}
cardArray.sort(randomsort);
i = 0;
while (i < cardArray.length) {
this[cardArray[i]]._x = this["cardtop" + (i + 1)]._x;
this[cardArray[i]]._y = this["cardtop" + (i + 1)]._y;
this[cardArray[i]].place = i + 1;
i++;
}
}
function checkMatch(id, card) {
if (matchCard == 0) {
matchCard = id;
flippedCards.push(card);
} else if (matchCard == id) {
score = score + 10;
scoretxt.text = score;
matchCard = 0;
matches++;
matchestxt.text = matches;
endgame();
flippedCards.push(card);
i = 0;
while (i < flippedCards.length) {
this[flippedCards[i]].fadeOut();
i++;
}
flippedCards = [];
} else {
if (score >= 5) {
score = score - 5;
} else {
score = 0;
}
scoretxt.text = score;
misses++;
missestxt.text = misses;
matchCard = 0;
flippedCards.push(card);
i = 0;
while (i < flippedCards.length) {
this[flippedCards[i]].flip("flipped");
i++;
}
flippedCards = [];
}
}
function endgame() {
trace((("matches " + matches) + " total ") + numCards);
if (matches == numCards) {
goodjob._visible = true;
goodjob.chest.gotoAndPlay("open");
_parent.smallchest.gotoAndPlay("open");
}
}
function randomsort(element1, element2) {
ran = Math.floor(Math.random() * 2) + 1;
if (ran == 1) {
return(-1);
}
if (ran == 2) {
return(1);
}
}
stop();
MovieClip.prototype.flip = function (card) {
if (card == "notflipped") {
this.num = this._name.split("cardtop").join("");
this.num = this.num - 1;
this.num++;
trace((("cardtop" + this.num) + " ") + this._parent.cardArray[this.num - 1]);
this._parent[this._parent.cardArray[this.num - 1]]._xscale = 0;
this.onEnterFrame = function () {
this._xscale = this._xscale - 40;
if (this._xscale <= 0) {
delete this.onEnterFrame;
this._xscale = 0;
this._parent[cardArray[this.num - 1]].onEnterFrame = function () {
this._xscale = this._xscale + 40;
if (this._xscale >= 100) {
delete this.onEnterFrame;
this._parent.checkMatch(this.id, this._name);
this._xscale = 100;
}
};
}
};
} else if (card == "flipped") {
this.num = this.place;
this._parent["cardtop" + this.num]._xscale = 0;
this.startwait = 0;
this.onEnterFrame = function () {
this.startwait++;
if (this.startwait >= 10) {
this._xscale = this._xscale - 40;
if (this._xscale <= 0) {
delete this.onEnterFrame;
this._xscale = 0;
this._parent["cardtop" + this.num].onEnterFrame = function () {
this._xscale = this._xscale + 40;
if (this._xscale >= 100) {
delete this.onEnterFrame;
this._xscale = 100;
}
};
}
}
};
}
};
MovieClip.prototype.fadeOut = function () {
this.onEnterFrame = function () {
this._alpha = this._alpha - 35;
if (this._alpha <= 0) {
delete this.onEnterFrame;
this._visible = false;
}
};
};
newGame();
Symbol 12 Button
on (release) {
_parent.newGame();
}