Ejemplo n.º 1
0
    /// <summary>
    ///проверяем можем ли мы поместить в данную ячейку такую кофету -  нужно избегать ситуаций с 3 и более в ряд на старте игры
    /// </summary>
    /// <param name="targetCell">Стартовая клетка</param>
    /// <param name="id">Id конфеты</param>
    /// <returns></returns>
    public static bool IsFreeCandyPlacement(MatchThreeCell targetCell, int id)
    {
        //Direction от 0 до 4 соответсвует enum
        for (int i = 0; i < 4; i++)
        {
            Direction direction = (Direction)i;
            int       counter   = 0;
            int       repeated  = 0;

            MatchThreeCell cell = targetCell;

            while (counter < 2)
            {
                cell = cell.GetNeighbour(direction);
                if (!cell || !cell.Candy)
                {
                    break;
                }

                if (cell.Candy.CandyData.Id == id)
                {
                    repeated++;
                }

                counter++;
            }

            if (repeated >= 2)
            {
                return(false);
            }
        }

        return(true);
    }
Ejemplo n.º 2
0
    public void SetNeighbour(Direction direction, MatchThreeCell cell)
    {
        if (GetNeighbour(direction))
        {
            return;
        }

        neighbours[(int)direction] = new Neighbour()
        {
            Direction = direction,
            Cell      = cell
        };
    }
Ejemplo n.º 3
0
    private void Start()
    {
        MainCamera = Camera.main;

        m_Field.Init();

        var firstCell = MatchThreeField.GetCell(0, 0);

        MatchThreeCell cell = firstCell;

        while (cell)
        {
            SetupCandiesLine(cell, Direction.Right);
            cell = cell.GetNeighbour(Direction.Up);
        }
    }
Ejemplo n.º 4
0
    private void SetupCandiesLine(MatchThreeCell firstCell, Direction direction)
    {
        MatchThreeCell cell = firstCell;

        while (cell)
        {
            MatchThreeCandy newCandy = m_Types.GetRandomCandy();
            //пробуем генерить пока не получим разрешенную кoнефетку
            //типов конфеток должно быть 5 или более - иначе возможен вариант вечного цикла
            while (!IsFreeCandyPlacement(cell, newCandy.CandyData.Id))
            {
                Destroy(newCandy.gameObject);
                newCandy = m_Types.GetRandomCandy();
            }

            cell.Candy = newCandy;
            cell.Candy.transform.position = cell.transform.position;
            cell = cell.GetNeighbour(direction);
        }
    }