Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 我正在开发as3内存中的游戏吗?_Actionscript 3_Flash - Fatal编程技术网

Actionscript 3 我正在开发as3内存中的游戏吗?

Actionscript 3 我正在开发as3内存中的游戏吗?,actionscript-3,flash,Actionscript 3,Flash,想知道如何在as3中制作一个记忆游戏,您首先拥有: 1-每次游戏开始时,牌都是随机的 2-至少有一个条件来验证卡片是否相同以及它们是否将消失 3-如果卡不相等,则返回正常状态 4-所有这些都只需在框架中包含卡片的movieclip 谢谢你的理解 到目前为止,我有以下代码: 导入flash.events.MouseEvent //variáveis relativo ao score, pattern and so on var pattern = new Array(); var buttons

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

1-每次游戏开始时,牌都是随机的

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

3-如果卡不相等,则返回正常状态

4-所有这些都只需在框架中包含卡片的movieclip

谢谢你的理解

到目前为止,我有以下代码:

导入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.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;
}
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;
}