Example #1
0
    private HashSet <ElimateUnit> CreateAllElimateUnit()
    {
        HashSet <ElimateUnit> unitset = new HashSet <ElimateUnit>();

        for (int row = 0; row < Row_Max; row++)
        {
            for (int column = 0; column < Col_Max; column++)
            {
                if (ArrayTile[column, row] != null)
                {
                    ElimateType type;
                    do
                    {
                        type = ElimateUnit.RandomType();
                    }while ((column >= 2 &&
                             ArrayUnit[column - 1, row] != null && ArrayUnit[column - 1, row].Type == type &&
                             ArrayUnit[column - 2, row] != null && ArrayUnit[column - 2, row].Type == type) ||
                            (row >= 2 &&
                             ArrayUnit[column, row - 1] != null && ArrayUnit[column, row - 1].Type == type &&
                             ArrayUnit[column, row - 2] != null && ArrayUnit[column, row - 2].Type == type));

                    ElimateUnit unit = CreateElimateUnit(column, row, type);
                    unitset.Add(unit);
                }
            }
        }

        return(unitset);
    }
Example #2
0
    //空位填补
    public List <List <ElimateUnit> > FillHoles()
    {
        List <List <ElimateUnit> > unitColumnlis = new List <List <ElimateUnit> >();

        for (int col = 0; col < Col_Max; col++)
        {
            List <ElimateUnit> unitlist = null;
            for (int row = 0; row < Row_Max; row++)
            {
                if (ArrayTile[col, row] != null && ArrayUnit[col, row] == null)
                {
                    for (int lookup = row + 1; lookup < Row_Max; lookup++)
                    {
                        ElimateUnit unit = ArrayUnit[col, lookup];
                        if (unit != null)
                        {
                            ArrayUnit[col, lookup] = null;
                            ArrayUnit[col, row]    = unit;
                            unit.Row = row;

                            if (unitlist == null)
                            {
                                unitlist = new List <ElimateUnit>();
                                unitColumnlis.Add(unitlist);
                            }
                            unitlist.Add(unit);
                            break;
                        }
                    }
                }
            }
        }

        return(unitColumnlis);
    }
Example #3
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);
        }
    }
Example #4
0
 //取消选中
 private void DeselectUnit()
 {
     if (CurSelectUnit != null)
     {
         CurSelectUnit.IsSelect = false;
         CurSelectUnit          = null;
     }
 }
Example #5
0
    public void AddElimateUnit(ElimateUnit unit)
    {
        if (lisElimateUnit == null)
        {
            lisElimateUnit = new List <ElimateUnit>();
        }

        lisElimateUnit.Add(unit);
    }
Example #6
0
    private ElimateUnit CreateElimateUnit(int col, int row, ElimateType etype)
    {
        ElimateUnit unit = new ElimateUnit();

        unit.Type   = etype;
        unit.Column = col;
        unit.Row    = row;

        ArrayUnit[col, row] = unit;
        return(unit);
    }
Example #7
0
    public void AddViewsForElimateUnits(ElimateUnit unit)
    {
        int        unitprefabindex = (int)unit.Type;
        Vector2    pos             = PointForCell(unit.Column, unit.Row);
        GameObject obj             = ElimatePrefabs[unitprefabindex].Spawn(ElimateRootTransform, pos);

        //设置新生成的单元信息
        ElimateView unitview = obj.GetComponent <ElimateView>();

        unitview.transform.localScale = new Vector2(0.5f, 0.5f);
        unit.View = unitview;

        //todo 可以对unitview做处理


        //动画
        Sequence sequence = DOTween.Sequence();

        sequence.Append(unitview.transform.DOScale(1f, 0.25f))
        .PrependInterval(UnityEngine.Random.Range(0f, 0.5f)
                         );
    }
Example #8
0
    public List <List <ElimateUnit> > TopElimateUnits()
    {
        List <List <ElimateUnit> > unitColumns = new List <List <ElimateUnit> >();

        ElimateType et = ElimateType.ET_1;

        for (int col = 0; col < Col_Max; col++)
        {
            List <ElimateUnit> lis = null;

            for (int row = Row_Max - 1; row >= 0 && ArrayUnit[col, row] == null; row--)
            {
                if (ArrayTile[col, row] != null)
                {
                    ElimateType newt;
                    do
                    {
                        newt = ElimateUnit.RandomType();
                    }while (newt == et);

                    //随机的类型
                    et = newt;

                    //新单元
                    ElimateUnit unit = CreateElimateUnit(col, row, et);

                    if (lis == null)
                    {
                        lis = new List <ElimateUnit>();
                        unitColumns.Add(lis);
                    }

                    lis.Add(unit);
                }
            }
        }
        return(unitColumns);
    }
Example #9
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;
    }
Example #10
0
 //选中
 private void SelectUnit(ElimateUnit unit)
 {
     unit.IsSelect = true;
     CurSelectUnit = unit;
 }