Exemple #1
0
    public void SwipeElement(MoveDir dir)
    {
        if (m_Pause)
        {
            return;
        }
        if (m_TouchElement == null)
        {
            return;
        }
        BoxElementControl curControl = m_TouchElement.GetComponent <BoxElementControl>();

        GameObject nbObj = curControl.GetNeighbor(dir);

        if (nbObj == null)
        {
            return;
        }

        BoxElementControl nbControl = nbObj.GetComponent <BoxElementControl>();
        MoveDir           opDir     = BoxElementControl.OppositeDir(dir);

        if (curControl.GetState() == BoxState.FIX && nbControl.GetState() == BoxState.FIX)
        {
            curControl.SwipeTo(dir);
            nbControl.SwipeTo(opDir);
        }
        m_TouchElement = null;
    }
Exemple #2
0
    public void CheckMoveBack()
    {
        int w = m_BG.GetCoordW();
        int h = m_BG.GetCoordH();

        for (int y = 0; y < h; y++)
        {
            for (int x = 0; x < w; x++)
            {
                GameObject obj = m_BG.GetElementByCoord(new Coord2D(x, y));
                if (obj == null)
                {
                    continue;               //no object
                }
                BoxElementControl curControl = obj.GetComponent <BoxElementControl>();
                if (curControl.ReadyToMoveBack())
                {
                    MoveDir    swipeDir = curControl.GetSwipeDir();
                    MoveDir    opDir    = BoxElementControl.OppositeDir(swipeDir);
                    GameObject nb       = curControl.GetNeighbor(opDir);
                    if (nb == null)
                    {
                        continue;
                    }
                    BoxElementControl nbControl = nb.GetComponent <BoxElementControl>();
                    if (nbControl.ReadyToMoveBack())    //no match
                    {
                        curControl.MoveBack();
                        nbControl.MoveBack();
                    }
                    else    //nb match success
                    {
                        curControl.DoNotMoveBack();
                    }
                }
            }
        }
    }