Exemplo n.º 1
0
    public void RefreshCell()
    {
        safeCount++;
        if (safeCount > 1000)
        {
            safeCount = 0;
            ConfirmInfo confirmInfo = new ConfirmInfo(LanguageUtil.GetTxt(11602), LanguageUtil.GetTxt(11601), ExitFight, null, false);
            ConfirmModel.Instance.AddConfirm(confirmInfo);
            return;
        }

        CellModel.Instance.anims = new List <List <CellAnimInfo> > ();

        List <CellInfo> allElments = new List <CellInfo> ();

        for (int i = 0; i < BattleModel.Instance.crtBattle.ShowHeight(); i++)
        {
            List <CellInfo> xCells = CellModel.Instance.allCells[i];
            for (int j = 0; j < xCells.Count; j++)
            {
                CellInfo cellInfo = xCells[j];
                if (cellInfo.isBlank == false && cellInfo.isMonsterHold == false && cellInfo.config.cell_type == (int)CellType.five)
                {
                    CoverInfo coverInfo = CoverModel.Instance.GetCoverByPos(cellInfo.posY, cellInfo.posX);
                    if (coverInfo.IsNull())
                    {
                        allElments.Add(cellInfo);
                    }
                }
            }
        }

        int switchTimes = 0;

        while (allElments.Count > 1)
        {
            int      randomA = UnityEngine.Random.Range(0, allElments.Count);
            CellInfo cellA   = allElments[randomA];
            allElments.RemoveAt(randomA);

            int      randomB = UnityEngine.Random.Range(0, allElments.Count);
            CellInfo cellB   = allElments[randomB];
            allElments.RemoveAt(randomB);

            switchTimes++;
            CellModel.Instance.SwitchPos(cellA, cellB);
            cellA.SwitchPos(cellB);
        }

        if (FuncCheckDead.IsDead())
        {
            RefreshCell();
        }
        else
        {
            safeCount = 0;
        }
    }
Exemplo n.º 2
0
    private static void RecursionMove(List <CellMoveInfo> moveAnims)
    {
        bool change = false;
        int  random = Random.Range(0, 2);
        int  i;

        if (random > 0)
        {
            for (i = 0; i < moveCells.Count; i++)
            {
                CellInfo moveCell  = moveCells[i];
                CellInfo blankCell = FindBlank(moveCell);
                if (blankCell != null && blankCell.isBlank)
                {
                    allCells[blankCell.posY].RemoveAt(blankCell.posX);
                    allCells[blankCell.posY].Insert(blankCell.posX, moveCell);
                    allCells[moveCell.posY].RemoveAt(moveCell.posX);
                    allCells[moveCell.posY].Insert(moveCell.posX, blankCell);

                    blankCell.SwitchPos(moveCell);
                    change = true;
                }
                AddMoveAnim(moveCell, moveAnims);
            }
        }
        else
        {
            for (i = moveCells.Count - 1; i >= 0; i--)
            {
                CellInfo moveCell  = moveCells[i];
                CellInfo blankCell = FindBlank(moveCell);
                if (blankCell != null && blankCell.isBlank)
                {
                    allCells[blankCell.posY].RemoveAt(blankCell.posX);
                    allCells[blankCell.posY].Insert(blankCell.posX, moveCell);
                    allCells[moveCell.posY].RemoveAt(moveCell.posX);
                    allCells[moveCell.posY].Insert(moveCell.posX, blankCell);

                    blankCell.SwitchPos(moveCell);
                    change = true;
                }
                AddMoveAnim(moveCell, moveAnims);
            }
        }


        if (change)
        {
            RecursionMove(moveAnims);
        }
    }
Exemplo n.º 3
0
    private static void SingleMove(bool single = false, bool isDeductStep = false)
    {
        bool change = false;

        CellModel.Instance.lineCells.Sort();
        //fill
        int n = CellModel.Instance.lineCells.Count - 1;

        for (; n >= 0; n--)
        {
            CellInfo blankTopCell = CellModel.Instance.lineCells[n];
            bool     isCoverOpen  = CoverModel.Instance.IsOpen(blankTopCell.posX, blankTopCell.posY);
            if (blankTopCell.isMonsterHold == false && blankTopCell.posY == 0 && isCoverOpen)
            {
                WallInfo topWall = WallModel.Instance.GetWallByPos(blankTopCell.posY, blankTopCell.posX, (int)CellDirType.up);
                if (topWall.CanPass())
                {
                    CellInfo addCell = CellModel.Instance.FillNewItem(blankTopCell, n, isDeductStep);
                    CellModel.Instance.AddMoveAnim(addCell, false);
                }
            }
        }

        int i;

        for (i = 0; i < CellModel.Instance.lineCells.Count; i++)
        {
            CellInfo blankCell   = CellModel.Instance.lineCells[i];
            bool     isCoverOpen = CoverModel.Instance.CanMoveIn(blankCell.posX, blankCell.posY);
            bool     hasFall     = false;
            if (blankCell.isMonsterHold == false && isCoverOpen)
            {
                if (blankCell.posY > 0 || (blankCell.posY == 0 && blankCell.IsHump() == false))
                {
                    //fall
                    WallInfo topWall = WallModel.Instance.GetWallByPos(blankCell.posY, blankCell.posX, (int)CellDirType.up);

                    CellInfo topCell = CellModel.Instance.GetCellByPos(blankCell.posX, blankCell.posY - 1);
                    if (topWall.CanPass())
                    {
                        if (topCell != null && topCell.CanMove())
                        {
                            CellModel.Instance.SwitchPos(blankCell, topCell);
                            blankCell.SwitchPos(topCell);
                            CellModel.Instance.AddMoveAnim(topCell, false);
                            hasFall = true;
                            change  = true;
                            break;
                        }
                    }
                    //Slid
                    if (hasFall == false)
                    {
                        if (topCell == null && blankCell.posY != 0)
                        {
                            continue;
                        }
                        if (topCell != null && topCell.isBlank)
                        {
                            //isCoverOpen = CoverModel.Instance.IsOpen(topCell.posX, topCell.posY);
                            if (topCell.isBlindBlank == false && topCell.isMonsterHold == false)
                            {
                                continue;
                            }
                        }

                        CellInfo slidCell = FindSlider(blankCell);
                        if (slidCell != null && slidCell.CanMove())
                        {
                            int posn = (int)CellDirType.left_up;
                            if (slidCell.posX > blankCell.posX)
                            {
                                posn = (int)CellDirType.right_up;
                            }
                            WallInfo slidWall = WallModel.Instance.GetWallByPos(blankCell.posY, blankCell.posX, posn);
                            if (slidWall.CanPass())
                            {
                                CellModel.Instance.SwitchPos(slidCell, blankCell);
                                slidCell.SwitchPos(blankCell);
                                CellModel.Instance.AddMoveAnim(slidCell, true);
                                change = true;
                                break;
                            }
                        }
                    }
                }
            }
        }
        if (change && single == false)
        {
            SingleMove(false, isDeductStep);
        }
    }
Exemplo n.º 4
0
    private void OnClickSelectHander(GameObject go)
    {
        PropTouchItem itemCtr = go.GetComponent <PropTouchItem>();

        if (itemCtr.valid)
        {
            CellInfo cellInfo = CellModel.Instance.GetCellByPos(itemCtr.control_x, itemCtr.control_y);
            switch (crtPropId)
            {
            case 10002:

                CellModel.Instance.anims = new List <List <CellAnimInfo> >();
                List <CellAnimInfo> stepMoves = new List <CellAnimInfo>();
                CellModel.Instance.anims.Add(stepMoves);

                if (cellInfo != null)
                {
                    cellInfo.isLink = true;
                    CellModel.Instance.lineCells.Add(cellInfo);

                    cellInfo.isBlank = true;
                    CellModel.Instance.AddAnim(cellInfo, CellAnimType.clear);

                    FightModule.crtFightStadus = FightStadus.prop_clear;
                    PromptModel.Instance.Pop(LanguageUtil.GetTxt(11410));
                }
                Show(0);
                PropModel.Instance.crtProp.Use();
                PropModel.Instance.ChangePropStadus(PropStadus.unSelect);
                break;

            case 10003:

                if (selectDepth == 1)
                {
                    //change
                    depth0Cell.SetConfig(itemCtr.control_id);
                    depth0Cell.changer = 0;
                    List <CellInfo> changeCells = new List <CellInfo>();
                    changeCells.Add(depth0Cell);
                    PromptModel.Instance.Pop(LanguageUtil.GetTxt(11411));
                    PropModel.Instance.PropChangeCellsEvent(changeCells);

                    Show(0);
                    PropModel.Instance.crtProp.Use();
                    PropModel.Instance.ChangePropStadus(PropStadus.unSelect);
                    return;
                }

                if (selectDepth == 0)
                {
                    depth0Cell   = cellInfo;
                    tipText.text = LanguageUtil.GetTxt(11412);
                    tipBg.rectTransform.sizeDelta = new Vector2(tipText.preferredWidth + 80, tipBg.rectTransform.sizeDelta.y);
                    CreatBrushs(cellInfo);
                }

                break;

            case 10005:

                if (selectDepth == 1)
                {
                    CellModel.Instance.anims = new List <List <CellAnimInfo> >();
                    stepMoves = new List <CellAnimInfo>();
                    CellModel.Instance.anims.Add(stepMoves);

                    CellModel.Instance.SwitchPos(depth0Cell, cellInfo);
                    depth0Cell.SwitchPos(cellInfo);

                    List <CellInfo> changeCells = new List <CellInfo>();
                    changeCells.Add(depth0Cell);
                    changeCells.Add(cellInfo);

                    PromptModel.Instance.Pop(LanguageUtil.GetTxt(11413));
                    PropModel.Instance.PropChangeCellsEvent(changeCells);

                    Show(0);
                    PropModel.Instance.crtProp.Use();
                    PropModel.Instance.ChangePropStadus(PropStadus.unSelect);
                    return;
                }

                if (selectDepth == 0)
                {
                    List <CellInfo> neighbors = CellModel.Instance.GetNeighbors(cellInfo);

                    bool hasSwitch = ShowSwitchList(neighbors, cellInfo);

                    if (hasSwitch == true)
                    {
                        tipText.text = LanguageUtil.GetTxt(11414);
                        tipBg.rectTransform.sizeDelta = new Vector2(tipText.preferredWidth + 80, tipBg.rectTransform.sizeDelta.y);
                        depth0Cell = cellInfo;
                    }
                    else
                    {
                        PromptModel.Instance.Pop(LanguageUtil.GetTxt(11415));
                        ShowList();
                    }
                }

                break;
            }
        }
        else
        {
            PromptModel.Instance.Pop(LanguageUtil.GetTxt(11415));
        }
    }