如何比较2个数组?数组

2023-09-08 15:08:40 作者:有些爱永远只是演戏

我有两个阵列,即组合和truecombo。用户填写通过点击各种按钮在舞台上与影片剪辑组合,truecombo是正确的组合。

I have two arrays, namely combo and truecombo. The user fills the combo with MovieClips by clicking on various buttons on the stage, truecombo is the correct combination.

在任何给定的点(enterFrame)闪光灯正在检查是否两者是一样的,如果是的话,做一些东西。就目前这是我的code(修改了好几次,像类型转换的指数,在组合的末尾添加.parent [O]等两件事情会发生,无论是一方或另一方。

At any given point (enterFrame) Flash is checking whether the two are the same, if yes, then do some stuff. For the time being this is my code (altered several times, like with Typecasting the indices, adding .parent at the end of combo[o] etc. 2 things will happen, either one or the other.

此语句也不会满意,此时添加和组合阵斩将继续,或条件将立即满足时combo.length = 6,检查我的code。

Either the statement will not be satisfied, at which point the adding and chopping of the combo array will continue, or the condition will be instantly met when combo.length = 6. Check my code.

更新:我有我目前的code一个Dropbox的文件。单击此按钮FLA 链接这里是SWF的链接的剥离下来一如既往的易用性和安全性。

UPDATE: I have a dropbox file with my current code. Click this for FLA link and here is the SWF link stripped down as always for ease and security.

/*stage.*/addEventListener(Event.ENTER_FRAME, checkthis);
function checkthis(e:Event)
{
    for(var o:int=0;o<= combo.length; o++) 
    {
        if((combo[o] == truecombo[o]) && (combo.length==truecombo.length))
        {
            equal=true;
        }
    }
    if (equal==true)
    {

        stage.removeEventListener(Event.ENTER_FRAME, checkthis);
        endSeq();
    }
}
function endSeq():void
{
    bravo.play();
    for (var i:int = 0; i < combo.length; i++)
    {
        var element:DisplayObject = combo[i];
        element.parent.removeChild(element);
    }
    firebb.gotoAndPlay(2);
    windbb.gotoAndPlay(2);
    spiritbb.gotoAndPlay(2);
    earthbb.gotoAndPlay(2);
}

这是我怎么把我的新元素的组合阵列。

This is how I push my new elements to the combo array.

function add(element:DisplayObject)
{
    twist.gotoAndPlay(2);

    element.width = WIDTH;
    element.height = HEIGHT;

    if (this.combo.length >= MAX_ELEMENTS)
    {
        removeChild(this.combo.shift());
    }

    this.combo.push(element as DisplayObject);
    this.addChild(element);
    this.reorder();
}

function reorder()
{
    for (var i:int = 0; i < combo.length; i++)
    {
        var element:DisplayObject = combo[i];
        element.x = OFFSET_X + (i * SEP_X);
        element.y = OFFSET_Y;
    }
}

这也是为什么我有我的truecombo及其内容创建。

And this is how I have my truecombo and its contents created.

var fireb:firebtn = new firebtn();
var spiritb:spiritbtn = new spiritbtn();
var earthb:earthbtn = new earthbtn();
var windb:windbtn = new windbtn();
var combo:Array=new Array();

const truecombo:Array = [fireb,windb,spiritb,windb,earthb,fireb];

对不起,我没有意见,我想这是pretty的不言自明的。先谢谢了。

Sorry for the lack of comments, I'd guess it's pretty self-explanatory. Thanks in advance.

推荐答案

下面是一个非常简单的循环:

Here's a really simple loop:

var equal:Boolean=true
if(combo.length == truecombo.length) {
    for(var i:int=0; i<combo.length; i++) {
        if(combo[i] != truecombo[i]) {
            equal=false;
            break;
        }
    }
} else {
    equal=false;
}

if(equal) {
    //do whatever
}

这假定两者相等,直到我们找到了其他方式。因此,如果长度是不同的,它们不相等。如果我日元素不同的是,他们是不相等的。

This assumes both are equal, until we find out otherwise. So if the lengths are different, they are not equal. If the ith element is different, they are not equal.

在最后,检查您的标志等于是真实的,做任何你想做的事情。

In the end, you check if your flag equal is true and do whatever you want to do.