Beispiel #1
0
    //
    private void TrySwapHorizontal(int horizontalDetal, int vertiaclDetal)
    {
        int toCol = SwipeFromCol + horizontalDetal;
        int toRow = SwipeFromRow + vertiaclDetal;

        if (toCol < 0 || toCol >= LgcLevel.Col_Max)
        {
            return;
        }

        if (toRow < 0 || toRow >= LgcLevel.Row_Max)
        {
            return;
        }

        ElimateUnit toUnit = CurLevel.GetElimateUnit(toCol, toRow);

        if (toUnit == null)
        {
            return;
        }

        ElimateUnit fromUnit = CurLevel.GetElimateUnit(SwipeFromCol, SwipeFromRow);

        if (SwipeHandler != null)
        {
            LgcSwap sp = new LgcSwap();
            sp.first  = fromUnit;
            sp.second = toUnit;
            SwipeHandler(sp);
        }
    }
Beispiel #2
0
    public bool Equals(LgcSwap sp)
    {
        if (sp != null)
        {
            return(false);
        }

        return((sp.first == first && sp.second == second) ||
               (sp.second == first && sp.first == second));
    }
Beispiel #3
0
    //hashset 需要重写 Equals
    public override bool Equals(object obj)
    {
        if (obj == null)
        {
            return(false);
        }

        LgcSwap sp = obj as LgcSwap;

        return(Equals(sp));
    }
Beispiel #4
0
    public void ElimateInvalidSwap(LgcSwap swap, Action completion)
    {
        swap.first.View.ViewIn.gameObject.SetActive(true);
        swap.first.View.ViewOut.gameObject.SetActive(false);

        swap.second.View.ViewIn.gameObject.SetActive(false);
        swap.second.View.ViewOut.gameObject.SetActive(true);

        float duration = 0.3f;

        swap.first.View.transform.DOMove(swap.second.View.transform.position, duration).SetEase(Ease.OutExpo).SetLoops(2, LoopType.Yoyo).OnComplete(() => completion());
        swap.second.View.transform.DOMove(swap.first.View.transform.position, duration).SetEase(Ease.OutExpo).SetLoops(2, LoopType.Yoyo);
    }
Beispiel #5
0
    //交换LgcSwap里两个对象在列表中的位置
    public void PerformSwap(LgcSwap sp)
    {
        int col_a = sp.first.Column;
        int row_a = sp.first.Row;

        int col_b = sp.second.Column;
        int row_b = sp.second.Row;

        //swap position
        ArrayUnit[col_a, row_a] = sp.second;
        ArrayUnit[col_b, row_b] = sp.first;

        //swap the sp
        sp.first.Column  = col_b;
        sp.first.Row     = row_b;
        sp.second.Column = col_a;
        sp.second.Row    = row_a;
    }
Beispiel #6
0
 //是否可交换 (hashset通过散射码查找效率非常高)
 public bool IsPossibleSwape(LgcSwap sp)
 {
     return(PossibleSwapSet.Contains(sp));
 }
Beispiel #7
0
    //查找是否存在链结构
    public void FindPossibleSwape()
    {
        HashSet <LgcSwap> spset = new HashSet <LgcSwap>();

        for (int row = 0; row < Row_Max; row++)
        {
            for (int col = 0; col < Col_Max; col++)
            {
                ElimateUnit unit = ArrayUnit[col, row];

                if (unit != null)
                {
                    if (col < Col_Max - 1)
                    {
                        //是否没有Tile或没有ElimateUnit
                        ElimateUnit otherunit = ArrayUnit[col + 1, row];
                        if (otherunit != null)
                        {
                            ArrayUnit[col, row]     = otherunit;
                            ArrayUnit[col + 1, row] = unit;
                        }

                        if (IsHasChainForUnit(col + 1, row) || IsHasChainForUnit(col, row))
                        {
                            LgcSwap sp = new LgcSwap();
                            sp.first  = unit;
                            sp.second = otherunit;
                            spset.Add(sp);
                        }

                        ArrayUnit[col, row]     = unit;
                        ArrayUnit[col + 1, row] = otherunit;
                    }

                    if (row < Row_Max - 1)
                    {
                        ElimateUnit otherunit = ArrayUnit[col, row + 1];
                        if (otherunit != null)
                        {
                            ArrayUnit[col, row]     = otherunit;
                            ArrayUnit[col, row + 1] = unit;

                            if (IsHasChainForUnit(col, row + 1) || IsHasChainForUnit(col, row))
                            {
                                LgcSwap sp = new LgcSwap();
                                sp.first  = unit;
                                sp.second = otherunit;
                                spset.Add(sp);
                            }

                            ArrayUnit[col, row]     = unit;
                            ArrayUnit[col, row + 1] = otherunit;
                        }
                    }
                }
            }
        }

        //找到是否交换后有链结构的组合
        PossibleSwapSet = spset;
    }