我是在 as3 内存中开发游戏吗?

Am I developing a game in as3 memory?

想知道如何在您首先拥有的 as3 中制作记忆游戏:

1-每次游戏运行卡牌都是随机的

2-至少有一个条件来验证卡片是否相同以及它们是否会消失。

3- 如果卡片不等于 return 正常

4-所有只是在帧中包含卡片的动画片段

谢谢理解

到目前为止我有这个代码:

导入flash.events.MouseEvent;

//variáveis relativo ao score, pattern and so on
var pattern = new Array();
var buttons = new Array();
buttons.push(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p);
var position = 0;

//Dizer aos botões que esperam ser clicados pelo rato
a.addEventListener(MouseEvent.CLICK, Clicked);
b.addEventListener(MouseEvent.CLICK, Clicked);
c.addEventListener(MouseEvent.CLICK, Clicked);
d.addEventListener(MouseEvent.CLICK, Clicked);
e.addEventListener(MouseEvent.CLICK, Clicked);
f.addEventListener(MouseEvent.CLICK, Clicked);
g.addEventListener(MouseEvent.CLICK, Clicked);
h.addEventListener(MouseEvent.CLICK, Clicked);
i.addEventListener(MouseEvent.CLICK, Clicked);
j.addEventListener(MouseEvent.CLICK, Clicked);
k.addEventListener(MouseEvent.CLICK, Clicked);
l.addEventListener(MouseEvent.CLICK, Clicked);
m.addEventListener(MouseEvent.CLICK, Clicked);
n.addEventListener(MouseEvent.CLICK, Clicked);
o.addEventListener(MouseEvent.CLICK, Clicked);
p.addEventListener(MouseEvent.CLICK, Clicked);

function Clicked(clickInfo:MouseEvent){
trace("Clique");
switch(clickInfo.target){
case a:
clickInfo.target.gotoAndStop(2);
break;
case b:
clickInfo.target.gotoAndStop(3);
}
}

我希望你点击任何字母,让它们出现在我决定的 4 个对象中

第 1 步:您需要创建一个 Card class 来处理翻转并显示适合其指定值的图像。基本上,方法如下:

Card.assign(type:int); // To assign a value and tell the card which face to show.
Card.unflip(); // Show back and enable mouse.
Card.flip(); // Show face and disable mouse.

第 2 步:将相同的值分配给随机的卡片对。

// Must contain 16 cards.
var Cards:Vector.<Card> = new Vector.<Card>;
Cards.push(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p);

// Lets make a copy.
var aCopy:Vector.<Cards> = Cards.slice();

// Lets take 8 random pairs and assign them values.
for (var i:int = 1, i <= 8; i++)
{
    var aCard:Card = extractRandom(aCopy);
    var bCard:Card = extractRandom(aCopy);

    aCard.assign(i);
    bCard.assign(i);
}

function extractRandom(list:Vector.<Cards>):Card
{
    // Obtain random card.
    var anIndex:int = list.length * Math.random();
    var result:Card = list[anIndex];

    // Remove it from list.
    // That is why we are working with the copy of the original array.
    list.splice(anIndex, 1);

    return result;
}

第 3 步:核心循环。

for each (var aCard:Card in Cards)
{
    aCard.addEventListener(MouseEvent.CLICK, onClick);
}

// To store selected cards.
var firstCard:Card;
var secondCard:Card;

// To keep track of user's progress.
var totalPairs:int = 8;
var matchedPairs:int = 0;

function onClick(e:Event):void
{
    // If secondCard is set then user is watching 2
    // wrong cards at he moment. Must ignore clicks.
    if (secondCard) return;

    // Get reference to the clicked card.
    var aCard:Cards = e.currentTarget as Card;

    if (firstCard)
    {
        // Save the second selected card reference.
        secondCard = aCard;
        secondCard.flip();

        if (firstCard.type == secondCard.type)
        {
            // If cards are matched then just leave them open immediately.
            firstCard = null;
            secondCard = null;

            matchedPairs++;

            if (matchedPairs == totalPairs)
            {
                // Win.
            }
        }
        else
        {
            // Otherwise let user watch the for a while and then close.
            setTimeout(unMatch, 1000);
        }
    }
    else
    {
        // Save the first selected card reference.
        firstCard = aCard;
        firstCard.flip();
    }
}

function unMatch():void
{
    firstCard.unflip();
    secondCard.unflip();

    firstCard = null;
    secondCard = null;
}