Example #1
0
    /// <summary>
    /// ������ʯ��λ��
    /// </summary>
    /// <param name="swap"></param>
    private void SwapJewels(theSwap swap)
    {
        //Debug.Log("di er ci"+swapping.jewelBx + "" + swapping.jewelBy);
        int dirA, dirB;//����������ʯ�Ľ�������1��2�ң�3�ϣ�4��
        bool verifyRock = false;//�ж��Ƿ��Ǹ�ʯͷ
        bool[,] markedForRemoval = new bool[boardSize, boardSize];

        if (swap.jewelAx > swap.jewelBx)
        {
            dirA = 2;
            dirB = 1;
        }
        else if (swap.jewelBx > swap.jewelAx)
        {
            dirA = 1;
            dirB = 2;
        }
        else if (swap.jewelAy > swap.jewelBy)
        {
            dirA = 4;
            dirB = 3;
        }
        else
        {
            dirA = 3;
            dirB = 4;
        }

        Jewel objIn;
        //��������ʯ��tag��ʯͷ����verifyRock=true
        if (jewelMapPosition[swap.jewelAx, swap.jewelAy].tag == "Rock" || jewelMapPosition[swap.jewelBx, swap.jewelBy].tag == "Rock")
        {
            verifyRock = true;
        }
        else
        {
            verifyRock = false;
        }

        //�������ʯͷ�ͽ��н���
        if (!verifyRock)
        { //�����������
            objIn = jewelMapPosition[swap.jewelAx, swap.jewelAy].gameObject.GetComponent<Jewel>();
            objIn.Move(dirA);

            objIn = jewelMapPosition[swap.jewelBx, swap.jewelBy].gameObject.GetComponent<Jewel>();
            objIn.Move(dirB);

            GameObject j = jewelMapPosition[swap.jewelAx, swap.jewelAy];
            jewelMapPosition[swap.jewelAx, swap.jewelAy] = jewelMapPosition[swap.jewelBx, swap.jewelBy];
            jewelMapPosition[swap.jewelBx, swap.jewelBy] = j;
        }

        //��ȡ��ʯA�����(0:��4\1:5\2:����\3:��4\4:TL\-1:��ͨ)
        int SpeA = CheckSpe(swap.jewelAx, swap.jewelAy);
        //��ȡ��ʯA�����(0:��4\1:5\2:����\3:��4\4:TL\-1:��ͨ)
        int SpeB = CheckSpe(swap.jewelBx, swap.jewelBy);

        #region ��ʯA��5����  1
        if (SpeA == 1)
        {
            if (SpeB == 0)
            {
                string tagname = jewelMapPosition[swap.jewelBx, swap.jewelBy].tag;
                for (int y = 0; y < boardSize; y++)
                {
                    for (int x = 0; x < boardSize; x++)
                    {
                        if (jewelMapPosition[x, y].tag == tagname)
                        {
                            GameObject jA = jewelMapPosition[x, y];
                            jA.GetComponent<Renderer>().material.mainTexture = (Texture2D)Resources.Load("Textures/Jewels/JewelsH");
                            SpeClear(x, y, CheckSpe(x, y), ref markedForRemoval);
                            markedForRemoval[x, y] = true;

                        }
                    }
                }
                markedForRemoval[swap.jewelAx, swap.jewelAy] = true;
            }
            if (SpeB == 1)
            {
                for (int y = 0; y < boardSize; y++)
                {
                    for (int x = 0; x < boardSize; x++)
                    {
                        markedForRemoval[x, y] = true;
                    }
                }
                markedForRemoval[swap.jewelAx, swap.jewelAy] = true;
            }
            if (SpeB == 2)
            {
                string tagname = jewelMapPosition[swap.jewelBx, swap.jewelBy].tag;
                for (int y = 0; y < boardSize; y++)
                {
                    for (int x = 0; x < boardSize; x++)
                    {
                        if (jewelMapPosition[x, y].tag == tagname)
                        {
                            GameObject jA = jewelMapPosition[x, y];
                            jA.GetComponent<Renderer>().material.mainTexture = (Texture2D)Resources.Load("Textures/Jewels/JewelsSqu");
                            SpeClear(x, y, CheckSpe(x, y), ref markedForRemoval);
                            markedForRemoval[x, y] = true;
                        }
                    }
                }
                markedForRemoval[swap.jewelAx, swap.jewelAy] = true;
            }
            if (SpeB == 3)
            {
                string tagname = jewelMapPosition[swap.jewelBx, swap.jewelBy].tag;
                for (int y = 0; y < boardSize; y++)
                {
                    for (int x = 0; x < boardSize; x++)
                    {
                        if (jewelMapPosition[x, y].tag == tagname)
                        {
                            GameObject jA = jewelMapPosition[x, y];
                            jA.GetComponent<Renderer>().material.mainTexture = (Texture2D)Resources.Load("Textures/Jewels/JewelsV");
                            SpeClear(x, y, CheckSpe(x, y), ref markedForRemoval);
                            markedForRemoval[x, y] = true;
                        }
                    }
                }
                markedForRemoval[swap.jewelAx, swap.jewelAy] = true;
            }
            if (SpeB == 4)
            {
                string tagname = jewelMapPosition[swap.jewelBx, swap.jewelBy].tag;
                for (int y = 0; y < boardSize; y++)
                {
                    for (int x = 0; x < boardSize; x++)
                    {
                        if (jewelMapPosition[x, y].tag == tagname)
                        {
                            GameObject jA = jewelMapPosition[x, y];
                            jA.GetComponent<Renderer>().material.mainTexture = (Texture2D)Resources.Load("Textures/Jewels/JewelsTL");
                            SpeClear(x, y, CheckSpe(x, y), ref markedForRemoval);
                            markedForRemoval[x, y] = true;
                        }
                    }
                }
                markedForRemoval[swap.jewelAx, swap.jewelAy] = true;
            }
            if (SpeB == -1)
            {
                string tagname = jewelMapPosition[swap.jewelBx, swap.jewelBy].tag;
                for (int y = 0; y < boardSize; y++)
                {
                    for (int x = 0; x < boardSize; x++)
                    {
                        if (jewelMapPosition[x, y].tag == tagname)
                        {
                            markedForRemoval[x, y] = true;
                            SpeClear(x, y, CheckSpe(x, y), ref markedForRemoval);
                        }
                    }
                }
                markedForRemoval[swap.jewelAx, swap.jewelAy] = true;
            }
            //����һ��
            for (int y = 0; y < boardSize; y++)
            {
                for (int x = 0; x < boardSize; x++)
                {
                    //����õ��������
                    if (markedForRemoval[x, y])
                        RemoveJewelAt(x, y);
                }
            }
            needToDropJewels = true;
            delayDrop = 0.3f;
            canSwap = false;
        }
        #endregion
        #region ��ʯA��4����  0
        if (SpeA == 0)
        {
            if (SpeB == 0 || SpeB == 3)
            {
                for (int i = 0; i < boardSize; i++)
                {
                    if (IsJewelAt(swap.jewelBx, i) && markedForRemoval[swap.jewelBx, i] == false)
                        markedForRemoval[swap.jewelBx, i] = true;
                }
                for (int i = 0; i < boardSize; i++)
                {
                    if (IsJewelAt(i, swap.jewelBy) && markedForRemoval[i, swap.jewelBy] == false)
                        markedForRemoval[i, swap.jewelBy] = true;
                }
            }
            if (SpeB == 1)
            {
                string tagname = jewelMapPosition[swap.jewelAx, swap.jewelAy].tag;
                for (int y = 0; y < boardSize; y++)
                {
                    for (int x = 0; x < boardSize; x++)
                    {
                        if (jewelMapPosition[x, y].tag == tagname)
                        {
                            GameObject jA = jewelMapPosition[x, y];
                            int vh = UnityEngine.Random.Range(1, 2);
                            if (vh == 1)
                                jA.GetComponent<Renderer>().material.mainTexture = (Texture2D)Resources.Load("Textures/Jewels/JewelsH");
                            else
                                jA.GetComponent<Renderer>().material.mainTexture = (Texture2D)Resources.Load("Textures/Jewels/JewelsV");
                            SpeClear(x, y, CheckSpe(x, y), ref markedForRemoval);
                        }
                    }
                }
            }
            if (SpeB == 2)
            {
                int px = UnityEngine.Random.Range(0, boardSize - 1);
                int py = UnityEngine.Random.Range(0, boardSize - 1);
                for (int i = 0; i < boardSize; i++)
                {
                    if (IsJewelAt(px, i) && markedForRemoval[px, i] == false)
                        markedForRemoval[px, i] = true;
                }
                for (int i = 0; i < boardSize; i++)
                {
                    if (IsJewelAt(i, py) && markedForRemoval[i, px] == false)
                        markedForRemoval[i, px] = true;
                }
            }
            //if (SpeB == 4)
            //{
            //    string tagname = jewelMapPosition[swap.jewelBx, swap.jewelBy].tag;
            //    for (int y = 0; y < boardSize; y++)
            //    {
            //        for (int x = 0; x < boardSize; x++)
            //        {
            //            if (jewelMapPosition[x, y].tag == tagname)
            //            {
            //                GameObject jA = jewelMapPosition[x, y];
            //                jA.GetComponent<Renderer>().material.mainTexture = (Texture2D)Resources.Load("Textures/Jewels/JewelsTL");
            //                SpeClear(x, y, CheckSpe(x, y), ref markedForRemoval);
            //            }
            //        }
            //    }
            //}

            //����һ��
            for (int y = 0; y < boardSize; y++)
            {
                for (int x = 0; x < boardSize; x++)
                {
                    //����õ��������
                    if (markedForRemoval[x, y])
                        RemoveJewelAt(x, y);
                }
            }
            if (SpeB != -1)
            {
                needToDropJewels = true;
                delayDrop = 0.3f;
                canSwap = false;
            }
        }
        #endregion
        #region ��ʯA�������� 2
        if (SpeA == 2)
        {
            if (SpeB == 0 || SpeB == 3)
            {
                int px = UnityEngine.Random.Range(0, boardSize - 1);
                int py = UnityEngine.Random.Range(0, boardSize - 1);
                markedForRemoval[swap.jewelAx, swap.jewelAy] = true;
                markedForRemoval[swap.jewelBx, swap.jewelBy] = true;
                for (int i = 0; i < boardSize; i++)
                {
                    if (IsJewelAt(px, i))
                    {
                        if (markedForRemoval[px, i] == false)
                            markedForRemoval[px, i] = true;
                    }
                }
                for (int i = 0; i < boardSize; i++)
                {
                    if (IsJewelAt(i, py))
                    {
                        if (markedForRemoval[i, px] == false)
                            markedForRemoval[i, px] = true;
                    }
                }
            }
            if (SpeB == 1)
            {
                string tagname = jewelMapPosition[swap.jewelAx, swap.jewelAy].tag;
                for (int y = 0; y < boardSize; y++)
                {
                    for (int x = 0; x < boardSize; x++)
                    {
                        if (jewelMapPosition[x, y].tag == tagname)
                        {
                            GameObject jA = jewelMapPosition[x, y];
                            jA.GetComponent<Renderer>().material.mainTexture = (Texture2D)Resources.Load("Textures/Jewels/JewelsSqu");
                            SpeClear(x, y, CheckSpe(x, y), ref markedForRemoval);
                        }
                    }
                }
            }
            if (SpeB == 2)
            {
                int px = UnityEngine.Random.Range(1, boardSize - 2);
                int py = UnityEngine.Random.Range(1, boardSize - 2);
                int px1 = UnityEngine.Random.Range(1, boardSize - 2);
                int py1 = UnityEngine.Random.Range(1, boardSize - 2);
                int px2 = UnityEngine.Random.Range(1, boardSize - 2);
                int py2 = UnityEngine.Random.Range(1, boardSize - 2);
                //markedForRemoval[swap.jewelAx, swap.jewelAy] = true;
                //markedForRemoval[swap.jewelBx, swap.jewelBy] = true;
                for (int i = 0; i <= 4; i++)
                {
                    //Debug.Log(i);
                    if (i == 0)
                    {
                        if (IsJewelAt(px, py))
                        {
                            if (markedForRemoval[px, py] == false)
                                markedForRemoval[px, py] = true;
                        }
                        if (IsJewelAt(px1, py1))
                        {
                            if (markedForRemoval[px1, py1] == false)
                                markedForRemoval[px1, py1] = true;
                        }
                        if (IsJewelAt(px2, py2))
                        {
                            if (markedForRemoval[px2, py2] == false)
                                markedForRemoval[px2, py2] = true;
                        }
                    }
                    if (i == 1)
                    {
                        //markedForRemoval[swap.jewelAx, swap.jewelAy] = true;
                        //markedForRemoval[swap.jewelBx, swap.jewelBy] = true;
                        if (IsJewelAt(px + 1, py))
                        {
                            if (markedForRemoval[px + 1, py] == false)
                                markedForRemoval[px + 1, py] = true;
                        }
                        if (IsJewelAt(px1 + 1, py1))
                        {
                            if (markedForRemoval[px1 + 1, py1] == false)
                                markedForRemoval[px1 + 1, py1] = true;
                        }
                        if (IsJewelAt(px2 + 1, py2))
                        {
                            if (markedForRemoval[px2 + 1, py2] == false)
                                markedForRemoval[px2 + 1, py2] = true;
                        }
                    }
                    if (i == 2)
                    {
                        //markedForRemoval[swap.jewelAx, swap.jewelAy] = true;
                        //markedForRemoval[swap.jewelBx, swap.jewelBy] = true;
                        if (IsJewelAt(px - 1, py) && markedForRemoval[px - 1, py] == false)
                            markedForRemoval[px - 1, py] = true;
                        if (IsJewelAt(px1 - 1, py1) && markedForRemoval[px1 - 1, py1] == false)
                            markedForRemoval[px1 - 1, py1] = true;
                        if (IsJewelAt(px2 - 1, py2) && markedForRemoval[px2 - 1, py2] == false)
                            markedForRemoval[px2 - 1, py2] = true;
                    }
                    if (i == 3)
                    {
                        //markedForRemoval[swap.jewelAx, swap.jewelAy] = true;
                        //markedForRemoval[swap.jewelBx, swap.jewelBy] = true;
                        if (IsJewelAt(px, py + 1))
                        {
                            if (markedForRemoval[px, py + 1] == false)
                                markedForRemoval[px, py + 1] = true;
                        }
                        if (IsJewelAt(px1, py1 + 1))
                        {
                            if (markedForRemoval[px1, py1 + 1] == false)
                                markedForRemoval[px1, py1 + 1] = true;
                        }
                        if (IsJewelAt(px2, py2 + 1))
                        {
                            if (markedForRemoval[px2, py2 + 1] == false)
                                markedForRemoval[px2, py2 + 1] = true;
                        }
                    }
                    if (i == 4)
                    {
                        //markedForRemoval[swap.jewelAx, swap.jewelAy] = true;
                        //markedForRemoval[swap.jewelBx, swap.jewelBy] = true;
                        if (IsJewelAt(px, py - 1))
                        {
                            if (markedForRemoval[px, py - 1] == false)
                                markedForRemoval[px, py - 1] = true;
                        }
                        if (IsJewelAt(px1, py1 - 1))
                        {
                            if (markedForRemoval[px1, py1 - 1] == false)
                                markedForRemoval[px1, py1 - 1] = true;
                        }
                        if (IsJewelAt(px2, py2 - 1))
                        {
                            if (markedForRemoval[px2, py2 - 1] == false)
                                markedForRemoval[px2, py2 - 1] = true;
                        }
                    }
                }
            }

            //����һ��
            for (int y = 0; y < boardSize; y++)
            {
                for (int x = 0; x < boardSize; x++)
                {
                    //����õ��������
                    if (markedForRemoval[x, y])
                        RemoveJewelAt(x, y);
                }
            }

            if (SpeB != -1)
            {
                needToDropJewels = true;
                delayDrop = 0.3f;
                canSwap = false;
            }
        }
        #endregion
        #region ��ʯA��4����  3
        if (SpeA == 3)
        {
            if (SpeB == 0 || SpeB == 3)
            {
                for (int i = 0; i < boardSize; i++)
                {
                    if (IsJewelAt(swap.jewelBx, i) && markedForRemoval[swap.jewelBx, i] == false)
                        markedForRemoval[swap.jewelBx, i] = true;
                }
                for (int i = 0; i < boardSize; i++)
                {
                    if (IsJewelAt(i, swap.jewelBy) && markedForRemoval[i, swap.jewelBy] == false)
                        markedForRemoval[i, swap.jewelBy] = true;
                }
            }
            if (SpeB == 1)
            {
                string tagname = jewelMapPosition[swap.jewelAx, swap.jewelAy].tag;
                for (int y = 0; y < boardSize; y++)
                {
                    for (int x = 0; x < boardSize; x++)
                    {
                        if (jewelMapPosition[x, y].tag == tagname)
                        {
                            GameObject jA = jewelMapPosition[x, y];
                            int vh = UnityEngine.Random.Range(1, 2);
                            if (vh == 1)
                                jA.GetComponent<Renderer>().material.mainTexture = (Texture2D)Resources.Load("Textures/Jewels/JewelsH");
                            else
                                jA.GetComponent<Renderer>().material.mainTexture = (Texture2D)Resources.Load("Textures/Jewels/JewelsV");
                            SpeClear(x, y, CheckSpe(x, y), ref markedForRemoval);
                        }
                    }
                }
            }
            if (SpeB == 2)
            {
                int px = UnityEngine.Random.Range(0, boardSize - 1);
                int py = UnityEngine.Random.Range(0, boardSize - 1);
                for (int i = 0; i < boardSize; i++)
                {
                    if (IsJewelAt(px, i) && markedForRemoval[px, i] == false)
                        markedForRemoval[px, i] = true;
                }
                for (int i = 0; i < boardSize; i++)
                {
                    if (IsJewelAt(i, py) && markedForRemoval[i, px] == false)
                        markedForRemoval[i, px] = true;
                }
            }
            //if (SpeB == 4)
            //{
            //    string tagname = jewelMapPosition[swap.jewelBx, swap.jewelBy].tag;
            //    for (int y = 0; y < boardSize; y++)
            //    {
            //        for (int x = 0; x < boardSize; x++)
            //        {
            //            if (jewelMapPosition[x, y].tag == tagname)
            //            {
            //                GameObject jA = jewelMapPosition[x, y];
            //                jA.GetComponent<Renderer>().material.mainTexture = (Texture2D)Resources.Load("Textures/Jewels/JewelsTL");
            //                SpeClear(x, y, CheckSpe(x, y), ref markedForRemoval);
            //            }
            //        }
            //    }
            //}

            //����һ��
            for (int y = 0; y < boardSize; y++)
            {
                for (int x = 0; x < boardSize; x++)
                {
                    //����õ��������
                    if (markedForRemoval[x, y])
                        RemoveJewelAt(x, y);
                }
            }
            if (SpeB != -1)
            {
                needToDropJewels = true;
                delayDrop = 0.3f;
                canSwap = false;
            }
        }
        #endregion
        #region ��ʯATL����   4
        //if (SpeA == 4)
        //{
        //    if (SpeB == 0 || SpeB == 3)
        //    {
        //        for (int i = 0; i < boardSize; i++)
        //        {
        //            if (IsJewelAt(swap.jewelBx, i) && markedForRemoval[swap.jewelBx, i] == false)
        //                markedForRemoval[swap.jewelBx, i] = true;
        //        }
        //        for (int i = 0; i < boardSize; i++)
        //        {
        //            if (IsJewelAt(i, swap.jewelBy) && markedForRemoval[i, swap.jewelBy] == false)
        //                markedForRemoval[i, swap.jewelBy] = true;
        //        }
        //    }
        //    if (SpeB == 1)
        //    {
        //        string tagname = jewelMapPosition[swap.jewelAx, swap.jewelAy].tag;
        //        for (int y = 0; y < boardSize; y++)
        //        {
        //            for (int x = 0; x < boardSize; x++)
        //            {
        //                if (jewelMapPosition[x, y].tag == tagname)
        //                {
        //                    GameObject jA = jewelMapPosition[x, y];
        //                    int vh = UnityEngine.Random.Range(1, 2);
        //                    if (vh == 1)
        //                        jA.GetComponent<Renderer>().material.mainTexture = (Texture2D)Resources.Load("Textures/Jewels/JewelsH");
        //                    else
        //                        jA.GetComponent<Renderer>().material.mainTexture = (Texture2D)Resources.Load("Textures/Jewels/JewelsV");
        //                    SpeClear(x, y, CheckSpe(x, y), ref markedForRemoval);
        //                }
        //            }
        //        }
        //    }
        //    if (SpeB == 2)
        //    {
        //        int px = UnityEngine.Random.Range(0, boardSize - 1);
        //        int py = UnityEngine.Random.Range(0, boardSize - 1);
        //        for (int i = 0; i < boardSize; i++)
        //        {
        //            if (IsJewelAt(px, i) && markedForRemoval[px, i] == false)
        //                markedForRemoval[px, i] = true;
        //        }
        //        for (int i = 0; i < boardSize; i++)
        //        {
        //            if (IsJewelAt(i, py) && markedForRemoval[i, px] == false)
        //                markedForRemoval[i, px] = true;
        //        }
        //    }
        //    //if (SpeB == 4)
        //    //{
        //    //    string tagname = jewelMapPosition[swap.jewelBx, swap.jewelBy].tag;
        //    //    for (int y = 0; y < boardSize; y++)
        //    //    {
        //    //        for (int x = 0; x < boardSize; x++)
        //    //        {
        //    //            if (jewelMapPosition[x, y].tag == tagname)
        //    //            {
        //    //                GameObject jA = jewelMapPosition[x, y];
        //    //                jA.GetComponent<Renderer>().material.mainTexture = (Texture2D)Resources.Load("Textures/Jewels/JewelsTL");
        //    //                SpeClear(x, y, CheckSpe(x, y), ref markedForRemoval);
        //    //            }
        //    //        }
        //    //    }
        //    //}

        //    //����һ��
        //    for (int y = 0; y < boardSize; y++)
        //    {
        //        for (int x = 0; x < boardSize; x++)
        //        {
        //            //����õ��������
        //            if (markedForRemoval[x, y])
        //                RemoveJewelAt(x, y);
        //        }
        //    }
        //    needToDropJewels = true;
        //    delayDrop = 0.3f;
        //    canSwap = false;
        //}
        #endregion
    }
Example #2
0
    private void SwapJewels(theSwap swap)
    {
        int dirA, dirB;
        bool verifyRock = false;

        if (swap.jewelAx > swap.jewelBx)
        {
            dirA = 2;
            dirB = 1;
        }
        else if (swap.jewelBx > swap.jewelAx)
        {
            dirA = 1;
            dirB = 2;
        }
        else if (swap.jewelAy > swap.jewelBy)
        {
            dirA = 4;
            dirB = 3;
        }
        else
        {
            dirA = 3;
            dirB = 4;
        }

        Jewel objIn;

        if (jewelMapPosition[swap.jewelAx, swap.jewelAy].tag == "Rock" || jewelMapPosition[swap.jewelBx, swap.jewelBy].tag == "Rock")
        {
            verifyRock = true;
        }
        else
        {
            verifyRock = false;
        }

        if (!verifyRock)
        { //Handles the swap
            objIn = jewelMapPosition[swap.jewelAx, swap.jewelAy].gameObject.GetComponent<Jewel>();
            objIn.Move(dirA);

            objIn = jewelMapPosition[swap.jewelBx, swap.jewelBy].gameObject.GetComponent<Jewel>();
            objIn.Move(dirB);

            GameObject j = jewelMapPosition[swap.jewelAx, swap.jewelAy];
            jewelMapPosition[swap.jewelAx, swap.jewelAy] = jewelMapPosition[swap.jewelBx, swap.jewelBy];
            jewelMapPosition[swap.jewelBx, swap.jewelBy] = j;
        }
    }