Пример #1
0
    //鼠标操作交换位置时
    public void ExChangeSweets(GameSweet sweetOnclick1, GameSweet sweetOnclick2)
    {
        if (sweetOnclick1.Equals(sweetOnclick2))
        {
            return;
        }
        if (sweetOnclick1.CanMove() && sweetOnclick2.CanMove())
        {
            sweetsarray[sweetOnclick1.Y, sweetOnclick1.X] = sweetOnclick2;
            sweetsarray[sweetOnclick2.Y, sweetOnclick2.X] = sweetOnclick1;//记录位子更新

            if (MatchSweets(sweetOnclick1, sweetOnclick2.X, sweetOnclick2.Y) != null ||
                MatchSweets(sweetOnclick2, sweetOnclick1.X, sweetOnclick1.Y) != null ||
                sweetOnclick1.Type == SweetsType.RAINBOWCANDY ||
                sweetOnclick2.Type == SweetsType.RAINBOWCANDY)//可以交换时
            {
                sweetsarray[sweetOnclick1.Y, sweetOnclick1.X] = sweetOnclick2;
                sweetsarray[sweetOnclick2.Y, sweetOnclick2.X] = sweetOnclick1;//记录位子更新

                int tempx = sweetOnclick1.X
                , tempy   = sweetOnclick1.Y;
                sweetOnclick1.MoveComponent.Move(sweetOnclick2.X, sweetOnclick2.Y, fillTime);
                sweetOnclick2.MoveComponent.Move(tempx, tempy, fillTime);

                if (sweetOnclick1.Type == SweetsType.RAINBOWCANDY && sweetOnclick1.CanClear() && sweetOnclick2.CanClear())
                {
                    ClearColorSweet clearcolor = sweetOnclick1.GetComponent <ClearColorSweet>();
                    if (clearcolor != null)
                    {
                        clearcolor.ClearColor = sweetOnclick2.ColorComponent.Color;
                    }
                    ClearSweet(sweetOnclick1.X, sweetOnclick1.Y);
                }

                if (sweetOnclick2.Type == SweetsType.RAINBOWCANDY && sweetOnclick1.CanClear() && sweetOnclick2.CanClear())
                {
                    ClearColorSweet clearcolor = sweetOnclick2.GetComponent <ClearColorSweet>();
                    if (clearcolor != null)
                    {
                        clearcolor.ClearColor = sweetOnclick1.ColorComponent.Color;
                    }
                    ClearSweet(sweetOnclick2.X, sweetOnclick2.Y);
                }
                pressedSweet = null;
                enteredSweet = null;
                ClearAllMatchedSweet();
                StartCoroutine(AllFill());
            }
            else
            {
                sweetsarray[sweetOnclick1.Y, sweetOnclick1.X] = sweetOnclick1;
                sweetsarray[sweetOnclick2.Y, sweetOnclick2.X] = sweetOnclick2;//记录位子更新
            }
        }
    }
Пример #2
0
    //交换两个甜品的方法
    private void ExchangeSweets(GameSweet sweet1, GameSweet sweet2)
    {
        if (sweet1.CanMove() && sweet2.CanMove())
        {
            sweets[sweet1.X, sweet1.Y] = sweet2;
            sweets[sweet2.X, sweet2.Y] = sweet1;

            if (MatchSweets(sweet1, sweet2.X, sweet2.Y) != null || MatchSweets(sweet2, sweet1.X, sweet1.Y) != null || sweet1.Type == SweetsType.RAINBOWCANDY || sweet2.Type == SweetsType.RAINBOWCANDY)
            {
                int tempX = sweet1.X;
                int tempY = sweet1.Y;


                sweet1.MovedComponent.Move(sweet2.X, sweet2.Y, fillTime);
                sweet2.MovedComponent.Move(tempX, tempY, fillTime);

                if (sweet1.Type == SweetsType.RAINBOWCANDY && sweet1.CanClear() && sweet2.CanClear())
                {
                    ClearColorSweet clearColor = sweet1.GetComponent <ClearColorSweet>();

                    if (clearColor != null)
                    {
                        clearColor.ClearColor = sweet2.ColoredComponent.Color;
                    }

                    ClearSweet(sweet1.X, sweet1.Y);
                }

                if (sweet2.Type == SweetsType.RAINBOWCANDY && sweet2.CanClear() && sweet1.CanClear())
                {
                    ClearColorSweet clearColor = sweet2.GetComponent <ClearColorSweet>();

                    if (clearColor != null)
                    {
                        clearColor.ClearColor = sweet1.ColoredComponent.Color;
                    }

                    ClearSweet(sweet2.X, sweet2.Y);
                }


                ClearAllMatchedSweet();
                StartCoroutine(AllFill());

                pressedSweet = null;
                enteredSweet = null;
            }
            else
            {
                sweets[sweet1.X, sweet1.Y] = sweet1;
                sweets[sweet2.X, sweet2.Y] = sweet2;
            }
        }
    }
Пример #3
0
    /// <summary>
    /// 交换物品位置
    /// </summary>
    /// <param name="sweet1"></param>
    /// <param name="sweet2"></param>
    private void ExChangeSweets(GameSweet sweet1, GameSweet sweet2)
    {
        if (sweet1.CanMove() && sweet2.CanMove())         //如果2个物品都能移动
        {
            sweets[sweet1.X, sweet1.Y] = sweet2;
            sweets[sweet2.X, sweet2.Y] = sweet1;

            if (MatchSweets(sweet1, sweet2.X, sweet2.Y) != null ||
                MatchSweets(sweet2, sweet1.X, sweet1.Y) != null ||
                sweet1.Type == SweetsType.RAINBOWCANDY ||
                sweet2.Type == SweetsType.RAINBOWCANDY)                                         //如果完成匹配
            {
                int tempX = sweet1.X;
                int tempY = sweet1.Y;

                sweet1.MovedComponet.Move(sweet2.X, sweet2.Y, fillTime);
                sweet2.MovedComponet.Move(tempX, tempY, fillTime);

                if (sweet1.Type == SweetsType.RAINBOWCANDY && sweet1.CanClear() && sweet2.CanClear())                 //如果物品1是 特殊物品:消除颜色
                {
                    ClearColorSweet clearColor = sweet1.GetComponent <ClearColorSweet>();
                    if (clearColor != null)                     //容错
                    {
                        clearColor.ClearColor = sweet2.ColorComponet.Color;
                    }
                    ClearSweet(sweet1.X, sweet1.Y);
                }
                if (sweet2.Type == SweetsType.RAINBOWCANDY && sweet2.CanClear() && sweet2.CanClear())                 //如果物品2是 特殊物品:消除颜色
                {
                    ClearColorSweet clearColor = sweet2.GetComponent <ClearColorSweet>();
                    if (clearColor != null)
                    {
                        clearColor.ClearColor = sweet1.ColorComponet.Color;
                    }
                    ClearSweet(sweet2.X, sweet2.Y);
                }


                ClearAllMatchedSweet();                    //交换位置后,清除物品,并生成空格
                StartCoroutine(AllFill());                 //交换位置后填充

                pressedSweet = null;
                enterSweet   = null;
            }
            else
            {
                sweets[sweet1.X, sweet1.Y] = sweet1;
                sweets[sweet2.X, sweet1.Y] = sweet2;
            }
        }
    }
Пример #4
0
    /// <summary>
    /// 将两个甜品位置交换
    /// </summary>
    /// <param name="sweet1"></param>
    /// <param name="sweet2"></param>
    private void ExchangeSweets(GameSweet sweet1, GameSweet sweet2)
    {
        if (sweet1.CanMove() && sweet2.CanMove())
        {
            sweets[sweet1.X, sweet1.Y] = sweet2;
            sweets[sweet2.X, sweet2.Y] = sweet1;
            int tempX = sweet1.X;
            int tempY = sweet1.Y;
            if (MatchSweets(sweet1, sweet2.X, sweet2.Y) != null || MatchSweets(sweet2, sweet1.X, sweet1.Y) != null || sweet1.Type == SweetType.RAINBOWCANDY || sweet2.Type == SweetType.RAINBOWCANDY)
            {
                //如果匹配到了最少三个相同的甜品则交换位置,且不能返回之前的位置
                sweet1.MoveSweetComponent.Move(sweet2.X, sweet2.Y, fillTime);//由于两个携程会影响甜品的位置,因此之前要先记录之前的位置
                sweet2.MoveSweetComponent.Move(tempX, tempY, fillTime);
                //如果两个甜品中有最少一个彩虹糖也可进入该语句
                if (sweet1.Type == SweetType.RAINBOWCANDY && sweet1.CanClear() && sweet2.CanClear())
                {
                    ClearSameSweet clearColor = sweet1.GetComponent <ClearSameSweet>();

                    if (clearColor != null)
                    {
                        clearColor.Color = sweet2.ColorSweetComponent.Color;
                    }
                    ClearSweet(sweet1.X, sweet1.Y);
                }

                if (sweet2.Type == SweetType.RAINBOWCANDY && sweet2.CanClear() && sweet1.CanClear())
                {
                    ClearSameSweet clearColor = sweet2.GetComponent <ClearSameSweet>();

                    if (clearColor != null)
                    {
                        clearColor.Color = sweet1.ColorSweetComponent.Color;
                    }
                    ClearSweet(sweet2.X, sweet2.Y);
                }

                ClearAllMatchSweet();
                StartCoroutine(AllFill());
            }
            else
            {
                //如果没匹配到三个相同的三个元素,则先交换后返回
                sweets[sweet1.X, sweet1.Y] = sweet1;
                sweets[sweet2.X, sweet2.Y] = sweet2;
                sweet1.MoveSweetComponent.Move(sweet2.X, sweet2.Y, fillTime);//由于两个携程会影响甜品的位置,因此之前要先记录之前的位置
                sweet2.MoveSweetComponent.Move(tempX, tempY, fillTime);
                StartCoroutine(Wait(0.5f, sweet1, sweet2));
            }
        }
    }
Пример #5
0
 /// <summary>
 /// 两个甜品位置交换
 /// </summary>
 public void ExChangeSweet(GameSweet sweet1, GameSweet sweet2)
 {
     if (sweet1.CanMove() && sweet2.CanMove())
     {
         sweetArr[sweet1.X, sweet1.Y] = sweet2;
         sweetArr[sweet2.X, sweet2.Y] = sweet1;
         if (MatchSweets(sweet1, sweet2.X, sweet2.Y) != null || MatchSweets(sweet2, sweet1.X, sweet1.Y) != null || sweet1.Type == SweetsType.RainbowCandy || sweet2.Type == SweetsType.RainbowCandy)
         {
             //记录x、y的值 防止sweet1已移动完成后位置跟sweet2重叠
             var x = sweet1.X;
             var y = sweet1.Y;
             sweet1.moveSweet.Move(sweet2.X, sweet2.Y, fillTime);
             sweet2.moveSweet.Move(x, y, fillTime);
             //清除指定颜色所有甜品
             if (sweet1.Type == SweetsType.RainbowCandy && sweet1.CanClear() && sweet2.CanClear())
             {
                 ClearColorSweet clearColor = sweet1.GetComponent <ClearColorSweet>();
                 if (clearColor != null)
                 {
                     clearColor.ClearColor = sweet2.colorSweet.colorType;
                 }
                 ClearSweet(sweet1.X, sweet1.Y);
             }
             if (sweet2.Type == SweetsType.RainbowCandy && sweet1.CanClear() && sweet2.CanClear())
             {
                 ClearColorSweet clearColor = sweet2.GetComponent <ClearColorSweet>();
                 if (clearColor != null)
                 {
                     clearColor.ClearColor = sweet1.colorSweet.colorType;
                 }
                 ClearSweet(sweet2.X, sweet2.Y);
             }
             ClearAllMatchedSweet();
             StartCoroutine(AllFill());
             clickSweet = null;
             enterSweet = null;
         }
         else
         {
             sweetArr[sweet1.X, sweet1.Y] = sweet1;
             sweetArr[sweet2.X, sweet2.Y] = sweet2;
         }
     }
 }