我正在创建 Flash“记忆”游戏,想发现 2 张相等的卡片。我需要制作“再试一次”按钮,删除所有卡片并生成新卡片。
这是主要的游戏功能:
public function MemoryGame()
{
tryAgain.addEventListener(MouseEvent.CLICK, darKarta);
timer = new Timer(1000); //create a new timer that ticks every second.
timer.addEventListener(TimerEvent.TIMER, tick, false, 0, true); //listen for the timer tick
txtTime = new TextField();
addChild(txtTime);
tmpTime = timer.currentCount;
timer.start();
_cards = new Array();
_totalMatches = 18;
_currentMatches = 0;
createCards();
}
这是 createCards 函数:
private function createCards():void
{
_cardX = 45;
_cardY = 10;
for(var i:Number = 0; i < 2; i++)
{
_card = new Card();
addChild(_card);
_boarder = new Boarder();
_card.setType(_boarder);
_card.x = _cardX;
_card.y = _cardY;
_cardX += _card.width + 5;
_card.addEventListener(MouseEvent.CLICK, checkCards);
_cards.push(_card);
}
for(var j:Number = 0; j < 2; j++)
{
_card = new Card();
addChild(_card);
_blueBoard = new BlueBoard();
_card.setType(_blueBoard);
_card.x = _cardX;
_card.y = _cardY;
_cardX += _card.width + 5;
_card.addEventListener(MouseEvent.CLICK, checkCards);
_cards.push(_card);
}
for(var r:Number = 0; r < 2; r++)
{
_card = new Card();
addChild(_card);
_penktas = new Penktas();
_card.setType(_penktas);
_card.x = _cardX;
_card.y = _cardY;
_cardX += _card.width + 5;
_card.addEventListener(MouseEvent.CLICK, checkCards);
_cards.push(_card);
}
这是 removeCard 功能:
function removeCards(e:MouseEvent):void
{
//for(var iv:Number = 0; iv < 18; iv++)
{
addEventListener(Event.ENTER_FRAME, remCards);
//}
}
function remCards(evt:Event):void
{
if (contains(_card)) {
removeChild(evt.currentTarget._card);
}
}
但它只删除最后一张卡,我不知道如何将它们全部删除。你有什么想法吗?谢谢你。