Ejemplo n.º 1
0
        public void Shift(int index, out int overlaps, out int unbuildables)
        {
            overlaps     = 0;
            unbuildables = 0;

            if (index >= 0 && index < Variables.Count && Variables[index].IsSelected())
            {
                Point pos = LineToMatrix(Variables[index].GetValue());
                int   row = pos.VerticalPosition;
                int   col = pos.HorizontalPosition;

                int rowShift = row + Variables[index].Height;
                int colShift = col + Variables[index].Length;

                string key;

                for (int x = row; x < rowShift; ++x)
                {
                    AddInMatrices(x, colShift, Variables[index].Name, index);

                    key = "" + x + "," + colShift;
                    if (Failures.ContainsKey(key))
                    {
                        if (!Failures[key].Contains("###"))
                        {
                            ++overlaps;
                        }
                        else
                        {
                            ++unbuildables;
                        }
                    }

                    key = "" + x + "," + col;
                    if (Failures.ContainsKey(key))
                    {
                        if (!Failures[key].Contains("###"))
                        {
                            --overlaps;
                        }
                        else
                        {
                            --unbuildables;
                        }
                    }

                    ClearInMatrices(x, col, Variables[index].Name, index);
                }

                Variables[index].ShiftValue();
            }
        }
Ejemplo n.º 2
0
        private void AddInMatrices(int row, int col, string buildingShort, int buildingIndex)
        {
            var temp = _matrixType[row, col].FirstOrDefault(s => s.Contains("@"));

            bool fail = !(_matrixType[row, col].Count == 0 ||
                          (temp != null && temp.Length <= 3));

            _matrixType[row, col].Add(buildingShort);
            _matrixIndex[row, col].Add(buildingIndex);
            if (fail)
            {
                var key = "" + row + "," + col;

                if (!Failures.ContainsKey(key))
                {
                    Failures.Add(key, string.Join("", _matrixType[row, col].ToArray()));
                }
                else
                {
                    Failures[key] += buildingShort;
                }
            }
        }
Ejemplo n.º 3
0
        private void ClearInMatrices(int row, int col, string buildingShort, int buildingIndex)
        {
            if (_matrixIndex[row, col].Contains(buildingIndex))
            {
                _matrixType[row, col].Remove(buildingShort);
                _matrixIndex[row, col].Remove(buildingIndex);

                var key = "" + row + "," + col;

                if (Failures.ContainsKey(key))
                {
                    if (_matrixType[row, col].Count < 2 ||
                        _matrixType[row, col].Contains("###") ||
                        (_matrixType[row, col].Count == 1 && _matrixType[row, col][0].Contains("@")))
                    {
                        Failures.Remove(key);
                    }
                    else
                    {
                        Failures[key] = string.Join("", _matrixType[row, col].ToArray());
                    }
                }
            }
        }