Exemple #1
0
        public void Swap(Cell cell1, Cell cell2)
        {
            lastSwappedCell1 = cell1;
            lastSwappedCell2 = cell2;

            Item item1 = cell1.Item;

            cell1.SetItem(cell2.Item);
            cell2.SetItem(item1);
        }
Exemple #2
0
        public Collapse CollapseColumns(IEnumerable <int> columnArray)
        {
            Collapse collapse = new Collapse();

            //search in every column
            foreach (var column in columnArray)
            {
                //begin from bottom row
                for (int row = 0; row < rows - 1; row++)
                {
                    //if you find a null item
                    if (cells[row, column].IsEmpty)
                    {
                        //start searching for the first non-null
                        for (int row2 = row + 1; row2 < rows; row2++)
                        {
                            //if you find one, bring it down (i.e. replace it with the null you found)
                            if (!cells[row2, column].IsEmpty)
                            {
                                Cell cell1 = cells[row, column];
                                Cell cell2 = cells[row2, column];

                                //assign the item
                                cell1.SetItem(cell2.Item);
                                cell2.Clear();

                                //calculate the biggest distance
                                collapse.MaxDistance = Mathf.Max(row2 - row, collapse.MaxDistance);

                                collapse.AddCell(cell1);
                                break;
                            }
                        }
                    }
                }
            }

            return(collapse);
        }