Esempio n. 1
0
    public void Swap(float direction, GridController gridController)
    {
        iVec2 targetCellPosition;

        if (direction > 0)
        {
            Debug.Log("Swap left.");
            this.selected      = false;
            targetCellPosition = new iVec2(this.cell.position.x - 1, this.cell.position.y);
        }
        else
        {
            Debug.Log("Swap right.");
            this.selected      = false;
            targetCellPosition = new iVec2(this.cell.position.x + 1, this.cell.position.y);
        }
        Cell targetCell = gridController.GetCellAtPosition(targetCellPosition);

        if (targetCell)
        {
            BaseTile targetTileSwap = targetCell.tile;
            Cell     thisCell       = this.cell;

            if (this.size == 7 && targetTileSwap.size == 7)
            {
                gridController.BlackTileMerged();
                targetTileSwap.Destroy(1);
                Destroy(1);
            }
            else
            {
                targetCell.tile = this;
                thisCell.tile   = targetTileSwap;
                this.SetCell(targetTileSwap.cell);
                targetTileSwap.SetCell(thisCell);
            }

            RootController.Instance.GameManager().turnsUsed++;
            gridController.MoveUpWhiteTiles();
        }
    }