Ejemplo n.º 1
0
    public static void DeleteLine(MatchThree_Candy obj, MatchThree_Cell targetCell, int id)
    {
        //Direction от 0 до 4 соответсвует enum
        for (int i = 0; i < 4; i++)
        {
            Direction       direction = (Direction)i;
            int             counter   = 0;
            MatchThree_Cell cell      = targetCell;

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

                if (cell.Candy.CandyData.Id == id)
                {
                    Destroy(cell.Candy.gameObject);
//                    DragCandiesLine(cell);
                }
                else
                {
                    break;
                }

                counter++;
            }
        }

        Destroy(obj.gameObject);
//        DragCandiesLine(targetCell);
    }
Ejemplo n.º 2
0
    public static MatchThree_Cell GetCell(MatchThree_Candy candy)
    {
        foreach (var row in GameField)
        {
            foreach (var cell in row.Where(cell => cell.Candy == candy))
            {
                return(cell);
            }
        }

        return(null);
    }
Ejemplo n.º 3
0
    public MatchThree_Candy GetRandomCandy()
    {
        MatchThree_CandyData candyData = m_CandiesData[Random.Range(0, m_CandiesData.Length)];
        GameObject           obj       = Instantiate(candyData.Prefab);
        MatchThree_Candy     candy     = obj.AddComponent <MatchThree_Candy>();

        candy.CandyData = candyData;
        SpriteRenderer spriteRenderer = obj.GetComponent <SpriteRenderer>();

        spriteRenderer.color = candyData.Color;

        return(candy);
    }
Ejemplo n.º 4
0
    private static void SetCandy(MatchThree_Cell firstCell, MatchThree_Types types)
    {
        MatchThree_Cell  cell     = firstCell;
        MatchThree_Candy newCandy = types.GetRandomCandy();

        while (!IsFreeCandyPlacement(cell, newCandy.CandyData.Id))
        {
            Destroy(newCandy.gameObject);
            newCandy = types.GetRandomCandy();
        }

        cell.Candy = newCandy;
        cell.Candy.transform.position = cell.transform.position;
    }
Ejemplo n.º 5
0
    private void OnMouseUp()
    {
        inDrag = false;
        if (currentCollider)
        {
            MatchThree_Candy targetCandy = currentCollider.GetComponent <MatchThree_Candy>();
            var targetCell  = MatchThree_Field.GetCell(targetCandy);
            var currentCell = MatchThree_Field.GetCell(this);

            //пытаемся поменять ячейки
            currentCell.Candy = targetCandy;
            targetCell.Candy  = this;

            //проверить валидность
            bool isFreePlacement = MatchThree_Controller.IsFreeCandyPlacement(targetCell, CandyData.Id);
            if (isFreePlacement)
            {
                isFreePlacement = MatchThree_Controller.IsFreeCandyPlacement(currentCell, targetCandy.CandyData.Id);
            }

            //если смена НЕ приведет к совпадению 3-х
            if (isFreePlacement)
            {
                targetCell.Candy   = targetCandy;
                currentCell.Candy  = this;
                transform.position = baseCandyPosition;
                return;
            }

            //Если приведет к совпадению 3-х
            transform.position             = targetCell.transform.position;
            targetCandy.transform.position = currentCell.transform.position;

            MatchThree_Controller.DeleteLine(this, targetCell, CandyData.Id);
//            MatchThree_Controller.DeleteLine(targetCandy, currentCell, CandyData.Id); // как то удалять если совпала переставленная конфетка =/

//            MatchThree_Controller.DragCandies("OnMouseUp 1");
            return;
        }

        transform.position = baseCandyPosition;
//        MatchThree_Controller.DragCandies("OnMouseUp 2");
    }
Ejemplo n.º 6
0
    private void SetupCandiesLine(MatchThree_Cell firstCell, Direction direction)
    {
        MatchThree_Cell cell = firstCell;

        while (cell)
        {
            MatchThree_Candy 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);
        }
    }