PDA

View Full Version : Memory game checking problem



youwh
May 9th, 2008, 02:19 PM
I'm doing a memory flip & match card game. Right now my problem in the script is every 2 cards I clicked the result is also "correct" How could I fix this problem?

ActionScript Code:


private function cardLoaded(e:Event):void {
var bmp:Bitmap=Bitmap(l.content);
var bmpd:BitmapData=bmp.bitmapData.clone();
var bmp2:Bitmap=new Bitmap(bmpd);
allCardsArray.push(bmp);
allCardsArray2.push(bmp2);


l.contentLoaderInfo.removeEventListener(Event.COMP LETE,cardLoaded);

l.contentLoaderInfo.removeEventListener(IOErrorEve nt.IO_ERROR,cardNotLoaded);

if (allCardsArray.length == 30) {
trace("All cards were loaded!");

for (var i:int=0; i < allCardsArray.length; i++) {
bmp=allCardsArray;
card=new Card ;
addChild(card);
card.addEventListener(MouseEvent.CLICK,checkCards) ; cardsRandom.push(card);

card.setType(allCardsArray[i]);
card.y=10 + i % 6 * 92;
card.x=10 + Math.floor(i / 6) * 72;



bmp2=allCardsArray2[i];
card=new Card ;
addChild(card);
card.addEventListener(MouseEvent.CLICK,checkCards) ;
cardsRandom.push(card);
card.setType(allCardsArray2[i]);
card.y=10 + i % 6 * 92;
card.x=370 + Math.floor(i / 6) * 72;

}
} else {
loadCardNum(allCardsArray.length);
}[I]//run the loadCardNum() function if no card is loaded
} //--------------------------------------------------------------------------------------------------
private function checkCards(event:MouseEvent):void {
var card:MovieClip=event.currentTarget as MovieClip;

card.removeEventListener(MouseEvent.CLICK,checkCar ds);

var size:int=cardArray.length;

if (size == 1) {// yes there is 1 card is opened

if (String(cardArray[0]._type) == String(card._type)) {

trace("match!");

cardArray=new Array ;
} else {

trace("wrong!");

}
}
}




cardArray.push(card);



the problem now is where is the best place to put this code in. I've tried put it in the loop, but no luck. Any ideas?

youwh
May 17th, 2008, 04:29 PM
bump?