diff --git a/HoistingCrane/HoistingCrane/CollectionGenericObjects/AbstractCompany.cs b/HoistingCrane/HoistingCrane/CollectionGenericObjects/AbstractCompany.cs index 6b7102b..c689725 100644 --- a/HoistingCrane/HoistingCrane/CollectionGenericObjects/AbstractCompany.cs +++ b/HoistingCrane/HoistingCrane/CollectionGenericObjects/AbstractCompany.cs @@ -1,5 +1,4 @@ using HoistingCrane.Drawning; -using System; namespace HoistingCrane.CollectionGenericObjects { public abstract class AbstractCompany @@ -48,7 +47,7 @@ namespace HoistingCrane.CollectionGenericObjects } public static DrawningTrackedVehicle operator -(AbstractCompany company, int position) { - return company.arr?.Remove(position) ?? null; + return company.arr?.Remove(position); } public DrawningTrackedVehicle? GetRandomObject() @@ -75,7 +74,6 @@ namespace HoistingCrane.CollectionGenericObjects } return bitmap; } - /// /// Вывод заднего фона /// diff --git a/HoistingCrane/HoistingCrane/CollectionGenericObjects/Garage.cs b/HoistingCrane/HoistingCrane/CollectionGenericObjects/Garage.cs index e2da629..6ba0162 100644 --- a/HoistingCrane/HoistingCrane/CollectionGenericObjects/Garage.cs +++ b/HoistingCrane/HoistingCrane/CollectionGenericObjects/Garage.cs @@ -1,7 +1,4 @@ using HoistingCrane.Drawning; -using System; -using System.Collections.Specialized; - namespace HoistingCrane.CollectionGenericObjects { public class Garage : AbstractCompany @@ -23,7 +20,6 @@ namespace HoistingCrane.CollectionGenericObjects } } } - protected override void SetObjectsPosition() { int countWidth = pictureWidth / _placeSizeWidth; @@ -39,7 +35,7 @@ namespace HoistingCrane.CollectionGenericObjects arr?.Get(i)?.SetPictureSize(pictureWidth, pictureHeight); arr?.Get(i)?.SetPosition(_placeSizeWidth * currentPosWidth + 25, _placeSizeHeight * currentPosHeight + 15); } - + if (currentPosWidth > 0) currentPosWidth--; else @@ -54,5 +50,6 @@ namespace HoistingCrane.CollectionGenericObjects } } + } } diff --git a/HoistingCrane/HoistingCrane/CollectionGenericObjects/ICollectionGenericObjects.cs b/HoistingCrane/HoistingCrane/CollectionGenericObjects/ICollectionGenericObjects.cs index 04b8de7..ae99e89 100644 --- a/HoistingCrane/HoistingCrane/CollectionGenericObjects/ICollectionGenericObjects.cs +++ b/HoistingCrane/HoistingCrane/CollectionGenericObjects/ICollectionGenericObjects.cs @@ -1,5 +1,4 @@ -using System; -namespace HoistingCrane.CollectionGenericObjects +namespace HoistingCrane.CollectionGenericObjects { public interface ICollectionGenericObjects where T: class diff --git a/HoistingCrane/HoistingCrane/CollectionGenericObjects/ListGenericObjects.cs b/HoistingCrane/HoistingCrane/CollectionGenericObjects/ListGenericObjects.cs index c92ca52..6f07ab5 100644 --- a/HoistingCrane/HoistingCrane/CollectionGenericObjects/ListGenericObjects.cs +++ b/HoistingCrane/HoistingCrane/CollectionGenericObjects/ListGenericObjects.cs @@ -1,5 +1,6 @@ using System; using System.CodeDom.Compiler; +using System.Windows.Forms.VisualStyles; namespace HoistingCrane.CollectionGenericObjects { @@ -44,19 +45,14 @@ namespace HoistingCrane.CollectionGenericObjects public T? Get(int position) { - // TODO проверка позиции if (position >= Count || position < 0) return null; return list[position]; } - - public int Insert(T obj) { - // TODO проверка, что не превышено максимальное количество элементов - // TODO вставка в конец набора - if (Count == _maxCount) - { - return -1; + if (Count == _maxCount) + { + return -1; } list.Add(obj); return Count; @@ -64,21 +60,16 @@ namespace HoistingCrane.CollectionGenericObjects public int Insert(T obj, int position) { - // TODO проверка, что не превышено максимальное количество элементов - // TODO проверка позиции - // TODO вставка по позиции if (position < 0 || position >= Count || Count == _maxCount) { return -1; } list.Insert(position, obj); - return position; + return position; } public T? Remove(int position) { - // TODO проверка позиции - // TODO удаление объекта из списка - if (position >= 0 && position < list.Count) + if(position >= 0 && position < list.Count) { T? temp = list[position]; list.RemoveAt(position); diff --git a/HoistingCrane/HoistingCrane/CollectionGenericObjects/MassivGenericObjects.cs b/HoistingCrane/HoistingCrane/CollectionGenericObjects/MassivGenericObjects.cs index afe3a36..fbd554d 100644 --- a/HoistingCrane/HoistingCrane/CollectionGenericObjects/MassivGenericObjects.cs +++ b/HoistingCrane/HoistingCrane/CollectionGenericObjects/MassivGenericObjects.cs @@ -11,7 +11,7 @@ namespace HoistingCrane.CollectionGenericObjects } public int Count { - get { return arr.Length; } + get { return arr.Length; } } public int MaxCount { @@ -61,28 +61,33 @@ namespace HoistingCrane.CollectionGenericObjects public int Insert(T obj, int position) { - //todo Проверка позиции - if (position < 0 || position > Count) + + if (position < 0 || position >= Count) { return -1; } - if (arr[position] == null) + int copyPos = position - 1; + + while (position < Count) { - arr[position] = obj; - return position; - } - else - { - if (Insert(obj, position + 1) != -1) - { - return position; - } - if (Insert(obj, position - 1) != -1) + if (arr[position] == null) { + arr[position] = obj; return position; } + position++; } + while (copyPos > 0) + { + if (arr[copyPos] == null) + { + arr[copyPos] = obj; + return copyPos; + } + copyPos--; + } + return -1; } diff --git a/HoistingCrane/HoistingCrane/CollectionGenericObjects/StorageCollection.cs b/HoistingCrane/HoistingCrane/CollectionGenericObjects/StorageCollection.cs index ae9901b..0aa587f 100644 --- a/HoistingCrane/HoistingCrane/CollectionGenericObjects/StorageCollection.cs +++ b/HoistingCrane/HoistingCrane/CollectionGenericObjects/StorageCollection.cs @@ -41,17 +41,12 @@ namespace HoistingCrane.CollectionGenericObjects /// тип коллекции public void AddCollection(string name, CollectionType collectionType) { - if (!string.IsNullOrEmpty(name) && !Keys.Contains(name)) - { - if(collectionType == CollectionType.Massive) - { - dict.Add(name, new MassivGenericObjects ()); - } - if(collectionType == CollectionType.List) - { - dict.Add(name, new ListGenericObjects ()); - } - } + if (dict.ContainsKey(name)) return; + if (collectionType == CollectionType.None) return; + else if (collectionType == CollectionType.Massive) + dict[name] = new MassivGenericObjects(); + else if (collectionType == CollectionType.List) + dict[name] = new ListGenericObjects(); } /// /// Удаление коллекции @@ -59,8 +54,10 @@ namespace HoistingCrane.CollectionGenericObjects /// Название коллекции public void DelCollection(string name) { - if (dict.ContainsKey(name)) + if (Keys.Contains(name)) + { dict.Remove(name); + } } /// /// Доступ к коллекции @@ -71,8 +68,9 @@ namespace HoistingCrane.CollectionGenericObjects { get { - if (name == null || !dict.ContainsKey(name)) { return null; } - return dict[name]; + if (dict.ContainsKey(name)) + return dict[name]; + return null; } } /// @@ -197,5 +195,6 @@ namespace HoistingCrane.CollectionGenericObjects _ => null, }; } + } } diff --git a/HoistingCrane/HoistingCrane/FormCarCollection.cs b/HoistingCrane/HoistingCrane/FormCarCollection.cs index 978fbe7..612b6a7 100644 --- a/HoistingCrane/HoistingCrane/FormCarCollection.cs +++ b/HoistingCrane/HoistingCrane/FormCarCollection.cs @@ -247,4 +247,4 @@ namespace HoistingCrane } } -} +} \ No newline at end of file diff --git a/HoistingCrane/HoistingCrane/FormCarConfig.cs b/HoistingCrane/HoistingCrane/FormCarConfig.cs index 1908fc4..2d0cd40 100644 --- a/HoistingCrane/HoistingCrane/FormCarConfig.cs +++ b/HoistingCrane/HoistingCrane/FormCarConfig.cs @@ -45,7 +45,6 @@ namespace HoistingCrane { _carDelegate += carDelegate; } - } /// /// Отрисовка объекта @@ -105,6 +104,7 @@ namespace HoistingCrane { (sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor ?? Color.White, DragDropEffects.Move | DragDropEffects.Copy); } + /// /// Передача объекта /// @@ -118,6 +118,7 @@ namespace HoistingCrane Close(); } } + /// /// Прорисовка основным цветом /// diff --git a/HoistingCrane/HoistingCrane/MovementStrategy/AbstractStrategy.cs b/HoistingCrane/HoistingCrane/MovementStrategy/AbstractStrategy.cs index 43e18e9..f8f3173 100644 --- a/HoistingCrane/HoistingCrane/MovementStrategy/AbstractStrategy.cs +++ b/HoistingCrane/HoistingCrane/MovementStrategy/AbstractStrategy.cs @@ -47,7 +47,6 @@ FieldWidth = width; FieldHeight = height; } - /// /// Шаг перемещения /// @@ -119,7 +118,6 @@ /// /// protected abstract bool IsTargetDestination(); - /// /// Попытка перемещения в требуемом направлении /// diff --git a/HoistingCrane/HoistingCrane/MovementStrategy/MoveToBorder.cs b/HoistingCrane/HoistingCrane/MovementStrategy/MoveToBorder.cs index 99cb56b..3d19b4d 100644 --- a/HoistingCrane/HoistingCrane/MovementStrategy/MoveToBorder.cs +++ b/HoistingCrane/HoistingCrane/MovementStrategy/MoveToBorder.cs @@ -1,4 +1,6 @@ -namespace HoistingCrane.MovementStrategy +using System.Configuration; + +namespace HoistingCrane.MovementStrategy { public class MoveToBorder : AbstractStrategy { @@ -12,7 +14,6 @@ return objParams.RightBorder + GetStep() >= FieldWidth && objParams.DownBorder + GetStep() >= FieldHeight; } - protected override void MoveToTarget() { ObjectParameters? objParams = GetObjectParameters;