Exemple #1
0
    private static Cell GetTopCell(List <Cell> activeCells, Cell targetCell, Chuzzle c)
    {
        if (targetCell == null || targetCell.IsTemporary)
        {
            targetCell = GamefieldUtility.CellAt(activeCells, c.Current.x,
                                                 activeCells.Where(x => !x.IsTemporary).Min(x => x.y));
            if (targetCell.Type == CellTypes.Block)
            {
                targetCell = targetCell.GetTopWithType();
            }
        }
        else
        {
            targetCell = targetCell.GetTopWithType();

            if (targetCell == null)
            {
                targetCell = GamefieldUtility.CellAt(activeCells, c.Current.x,
                                                     activeCells.Where(x => !x.IsTemporary).Min(x => x.y));
                if (targetCell.Type == CellTypes.Block)
                {
                    targetCell = targetCell.GetTopWithType();
                }
            }
        }
        return(targetCell);
    }
Exemple #2
0
    private static Cell GetLeftCell(List <Cell> activeCells, Cell targetCell, Chuzzle c)
    {
        if (targetCell == null)
        {
            targetCell = GamefieldUtility.CellAt(activeCells, activeCells.Max(x => x.x), c.Current.y);
            if (targetCell.Type == CellTypes.Block)
            {
                targetCell = targetCell.GetLeftWithType();
            }
        }
        else
        {
            //if block
            targetCell = targetCell.GetLeftWithType();

            if (targetCell == null)
            {
                targetCell = GamefieldUtility.CellAt(activeCells, activeCells.Max(x => x.x),
                                                     c.Current.y);
                if (targetCell.Type == CellTypes.Block)
                {
                    targetCell = targetCell.GetLeftWithType();
                }
            }
        }
        return(targetCell);
    }
Exemple #3
0
    public Cell GetCellAt(int x, int y, bool createIfNotFound = true)
    {
        var cell = GamefieldUtility.CellAt(Cells, x, y);

        if (cell == null && createIfNotFound)
        {
            var newCell = new Cell(x, y);
            AddCell(x, y, newCell);
            return(newCell);
        }
        return(cell);
    }
Exemple #4
0
    private void MoveChuzzles(List <Cell> activeCells)
    {
        foreach (var c in SelectedChuzzles)
        {
            var copyPosition = c.transform.position;

            var real       = GamefieldUtility.ToRealCoordinates(c);
            var targetCell = GamefieldUtility.CellAt(activeCells, real.x, real.y);

            var difference = c.transform.position - GamefieldUtility.ConvertXYToPosition(real.x, real.y, Chuzzle.Scale);

            var isNeedCopy = false;

            if (targetCell != null && !targetCell.IsTemporary)
            {
                if (!_isVerticalDrag)
                {
                    if (difference.x > 0)
                    {
                        isNeedCopy = targetCell.Right == null ||
                                     (targetCell.Right != null && targetCell.Right.Type != CellTypes.Usual);
                        if (isNeedCopy)
                        {
                            var rightCell = GetRightCell(activeCells, targetCell.Right, c);
                            copyPosition = rightCell.Position + difference - new Vector3(Chuzzle.Scale.x, 0, 0);
                        }
                    }
                    else
                    {
                        isNeedCopy = targetCell.Left == null ||
                                     (targetCell.Left != null && targetCell.Left.Type != CellTypes.Usual);
                        if (isNeedCopy)
                        {
                            var leftCell = GetLeftCell(activeCells, targetCell.Left, c);
                            copyPosition = leftCell.Position + difference + new Vector3(Chuzzle.Scale.x, 0, 0);
                        }
                    }
                }
                else
                {
                    if (difference.y > 0)
                    {
                        isNeedCopy = targetCell.Top == null ||
                                     (targetCell.Top != null &&
                                      (targetCell.Top.Type == CellTypes.Block || targetCell.Top.IsTemporary));
                        if (isNeedCopy)
                        {
                            var topCell = GetTopCell(activeCells, targetCell.Top, c);
                            copyPosition = topCell.Position + difference - new Vector3(0, Chuzzle.Scale.y, 0);
                        }
                    }
                    else
                    {
                        isNeedCopy = targetCell.Bottom == null ||
                                     (targetCell.Bottom != null && targetCell.Bottom.Type == CellTypes.Block);
                        if (isNeedCopy)
                        {
                            var bottomCell = GetBottomCell(activeCells, targetCell.Bottom, c);
                            copyPosition = bottomCell.Position + difference + new Vector3(0, Chuzzle.Scale.y, 0);
                        }
                    }
                }
            }
            else
            {
                isNeedCopy = true;
            }

            if (targetCell == null || targetCell.Type == CellTypes.Block || targetCell.IsTemporary)
            {
                switch (CurrentDirection)
                {
                case Direction.Left:
                    //if border
                    targetCell = GetLeftCell(activeCells, targetCell, c);
                    break;

                case Direction.Right:
                    targetCell = GetRightCell(activeCells, targetCell, c);
                    break;

                case Direction.Top:
                    //if border
                    targetCell = GetTopCell(activeCells, targetCell, c);
                    break;

                case Direction.Bottom:
                    targetCell = GetBottomCell(activeCells, targetCell, c);
                    break;

                default:
                    throw new ArgumentOutOfRangeException("Current direction can not be shit");
                }

                c.transform.position = targetCell.Position + difference;

                // Debug.Log("New coord: "+GamefieldUtility.ToRealCoordinates(c)+" for "+c.gameObject.name + " pos: "+c.transform.position);
            }

            if (difference.magnitude < (Chuzzle.Scale.x / 25))
            {
                isNeedCopy = false;
            }

            if (isNeedCopy)
            {
                c.Teleportable.Show();
                c.Teleportable.Copy.transform.position = copyPosition;
            }
            else
            {
                c.Teleportable.Hide();
            }
        }
    }