diff --git a/ProjectElectricLocomotive/ProjectElectricLocomotive/EntityLocomotive.cs b/ProjectElectricLocomotive/ProjectElectricLocomotive/EntityLocomotive.cs index e9543bd..9adfee6 100644 --- a/ProjectElectricLocomotive/ProjectElectricLocomotive/EntityLocomotive.cs +++ b/ProjectElectricLocomotive/ProjectElectricLocomotive/EntityLocomotive.cs @@ -8,7 +8,6 @@ namespace ProjectElectricLocomotive.Entities { public class EntityLocomotive { - //a new branch public int Speed { get; private set;} public double Weight { get; private set;} public Color BodyColor { get; private set;} diff --git a/ProjectElectricLocomotive/ProjectElectricLocomotive/FormLocomotiveCollections.Designer.cs b/ProjectElectricLocomotive/ProjectElectricLocomotive/FormLocomotiveCollections.Designer.cs index 562433d..3553baf 100644 --- a/ProjectElectricLocomotive/ProjectElectricLocomotive/FormLocomotiveCollections.Designer.cs +++ b/ProjectElectricLocomotive/ProjectElectricLocomotive/FormLocomotiveCollections.Designer.cs @@ -46,14 +46,14 @@ this.Instruments.Controls.Add(this.ButtonRefreshCollection); this.Instruments.Controls.Add(this.ButtonRemoveLocomotive); this.Instruments.Controls.Add(this.ButtonAddLocomotive); - this.Instruments.Location = new System.Drawing.Point(435, -40); + this.Instruments.Location = new System.Drawing.Point(815, 0); this.Instruments.Name = "Instruments"; - this.Instruments.Size = new System.Drawing.Size(191, 451); + this.Instruments.Size = new System.Drawing.Size(233, 596); this.Instruments.TabIndex = 0; // // maskedTextBoxNumber // - this.maskedTextBoxNumber.Location = new System.Drawing.Point(42, 123); + this.maskedTextBoxNumber.Location = new System.Drawing.Point(55, 124); this.maskedTextBoxNumber.Mask = "0"; this.maskedTextBoxNumber.Name = "maskedTextBoxNumber"; this.maskedTextBoxNumber.Size = new System.Drawing.Size(125, 27); @@ -63,7 +63,7 @@ // this.ButtonRefreshCollection.Anchor = System.Windows.Forms.AnchorStyles.Right; this.ButtonRefreshCollection.Font = new System.Drawing.Font("Candara Light", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - this.ButtonRefreshCollection.Location = new System.Drawing.Point(29, 249); + this.ButtonRefreshCollection.Location = new System.Drawing.Point(42, 326); this.ButtonRefreshCollection.Name = "ButtonRefreshCollection"; this.ButtonRefreshCollection.Size = new System.Drawing.Size(150, 36); this.ButtonRefreshCollection.TabIndex = 2; @@ -75,7 +75,7 @@ // this.ButtonRemoveLocomotive.Anchor = System.Windows.Forms.AnchorStyles.Right; this.ButtonRemoveLocomotive.Font = new System.Drawing.Font("Candara Light", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - this.ButtonRemoveLocomotive.Location = new System.Drawing.Point(29, 179); + this.ButtonRemoveLocomotive.Location = new System.Drawing.Point(42, 254); this.ButtonRemoveLocomotive.Name = "ButtonRemoveLocomotive"; this.ButtonRemoveLocomotive.Size = new System.Drawing.Size(150, 36); this.ButtonRemoveLocomotive.TabIndex = 1; @@ -87,7 +87,7 @@ // this.ButtonAddLocomotive.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.ButtonAddLocomotive.Font = new System.Drawing.Font("Candara Light", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - this.ButtonAddLocomotive.Location = new System.Drawing.Point(29, 52); + this.ButtonAddLocomotive.Location = new System.Drawing.Point(42, 41); this.ButtonAddLocomotive.Name = "ButtonAddLocomotive"; this.ButtonAddLocomotive.Size = new System.Drawing.Size(150, 36); this.ButtonAddLocomotive.TabIndex = 0; @@ -98,9 +98,9 @@ // pictureBoxCollections // this.pictureBoxCollections.Anchor = System.Windows.Forms.AnchorStyles.Left; - this.pictureBoxCollections.Location = new System.Drawing.Point(-3, -2); + this.pictureBoxCollections.Location = new System.Drawing.Point(-3, 0); this.pictureBoxCollections.Name = "pictureBoxCollections"; - this.pictureBoxCollections.Size = new System.Drawing.Size(458, 373); + this.pictureBoxCollections.Size = new System.Drawing.Size(821, 596); this.pictureBoxCollections.TabIndex = 1; this.pictureBoxCollections.TabStop = false; // @@ -108,7 +108,7 @@ // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(626, 370); + this.ClientSize = new System.Drawing.Size(1048, 593); this.Controls.Add(this.pictureBoxCollections); this.Controls.Add(this.Instruments); this.Name = "FormLocomotiveCollections"; diff --git a/ProjectElectricLocomotive/ProjectElectricLocomotive/FormLocomotiveCollections.resx b/ProjectElectricLocomotive/ProjectElectricLocomotive/FormLocomotiveCollections.resx index 1af7de1..f298a7b 100644 --- a/ProjectElectricLocomotive/ProjectElectricLocomotive/FormLocomotiveCollections.resx +++ b/ProjectElectricLocomotive/ProjectElectricLocomotive/FormLocomotiveCollections.resx @@ -1,64 +1,4 @@ - - - + diff --git a/ProjectElectricLocomotive/ProjectElectricLocomotive/LocomotiveGenericCollection.cs b/ProjectElectricLocomotive/ProjectElectricLocomotive/LocomotiveGenericCollection.cs index 67d182e..3e1b73a 100644 --- a/ProjectElectricLocomotive/ProjectElectricLocomotive/LocomotiveGenericCollection.cs +++ b/ProjectElectricLocomotive/ProjectElectricLocomotive/LocomotiveGenericCollection.cs @@ -44,13 +44,19 @@ namespace ProjectElectricLocomotive.Generics /// Перегрузка оператора вычитания public static T operator -(LocomotiveGenericCollection collect, int pos) { - return collect._collection.Remove(pos); + T? obj = collect._collection[pos]; + if (obj != null) + { + collect._collection.Remove(pos); + } + return obj; + //return collect._collection.Remove(pos); } // получение объекта imoveableObj public U? GetU(int pos) { - return (U?)_collection.Get(pos)?.GetMoveableObject; + return (U?)_collection[pos]?.GetMoveableObject; } /// Вывод всего набора объектов @@ -82,7 +88,7 @@ namespace ProjectElectricLocomotive.Generics int WidthObjCount = _pictureWidth / _placeSizeWidth; for (int i = 0; i < _collection.Count; i++) { - T? type = _collection.Get(i); + T? type = _collection[i]; if (type != null) { type.SetPosition( diff --git a/ProjectElectricLocomotive/ProjectElectricLocomotive/LocomotiveGenericStorage.cs b/ProjectElectricLocomotive/ProjectElectricLocomotive/LocomotiveGenericStorage.cs new file mode 100644 index 0000000..995847a --- /dev/null +++ b/ProjectElectricLocomotive/ProjectElectricLocomotive/LocomotiveGenericStorage.cs @@ -0,0 +1,83 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ProjectElectricLocomotive.DrawingObjects; +using ProjectElectricLocomotive.MovementStrategy; + +namespace ProjectElectricLocomotive.Generics +{ + internal class LocomotiveGenericStorage + { + /// + /// Словарь (хранилище) + /// + readonly Dictionary> _locomotivesStorage; + + /// + /// Возвращение списка названий наборов + /// + public List Keys => _locomotivesStorage.Keys.ToList(); + + + private readonly int _pictureWidth; + + private readonly int _pictureHeight; + + /// + /// Конструктор + /// + /// + /// + public LocomotiveGenericStorage(int pictureWidth, int pictureHeight) + { + _locomotivesStorage = new Dictionary>(); + _pictureWidth = pictureWidth; + _pictureHeight = pictureHeight; + } + /// + /// Добавление набора + /// + /// Название набора + public void AddSet(string name) + { + if (!_locomotivesStorage.ContainsKey(name)) + { + _locomotivesStorage.Add(name, new LocomotiveGenericCollection(_pictureWidth, _pictureHeight)); + } + } + + /// + /// Удаление набора + /// + /// Название набора + public void DelSet(string name) + { + if (!_locomotivesStorage.ContainsKey(name)) + { + _locomotivesStorage.Remove(name); + } + } + + + /// + /// Доступ к набору + /// + /// + /// + public LocomotiveGenericCollection? + this[string ind] + { + get + { + // TODO Продумать логику получения набора + if (_locomotivesStorage.ContainsKey(ind)) + { + return _locomotivesStorage[ind]; + } + return null; + } + } + } +} diff --git a/ProjectElectricLocomotive/ProjectElectricLocomotive/SetGeneric.cs b/ProjectElectricLocomotive/ProjectElectricLocomotive/SetGeneric.cs index 3b43fb2..3364f94 100644 --- a/ProjectElectricLocomotive/ProjectElectricLocomotive/SetGeneric.cs +++ b/ProjectElectricLocomotive/ProjectElectricLocomotive/SetGeneric.cs @@ -8,11 +8,17 @@ namespace ProjectElectricLocomotive.Generics { internal class SetGeneric where T : class { - private readonly T[] _places; - public int Count => _places.Length; + + private readonly List _places; + + public int Count => _places.Count; + + /// Максимальное количество объектов в списке + private readonly int _maxCount; public SetGeneric(int count) { - _places = new T[count]; + _maxCount = count; + _places = new List(count); } /// Добавление объекта в набор @@ -49,15 +55,10 @@ namespace ProjectElectricLocomotive.Generics return position; } return -1; - // TODO проверка позиции - // TODO проверка, что элемент массива по этой позиции пустой, если нет, то - // проверка, что после вставляемого элемента в массиве есть пустой элемент // } public T Remove(int position) { - // TODO проверка позиции - // TODO удаление объекта из массива, присвоив элементу массива значение null if (position >= Count || position < 0) return null; @@ -65,12 +66,47 @@ namespace ProjectElectricLocomotive.Generics _places[position] = null; return tmp; } + + + public T? this[int position] + { + get + { + if (position < 0 || position >= Count) return null; + return _places[position]; + } + set + { + if (position < 0 || position >= Count) return; + if(value == null) return; + _places[position] = value; + // TODO проверка позиции + // TODO проверка свободных мест в списке + // TODO вставка в список по позиции + } + } + /// + /// Проход по списку + /// + /// + public IEnumerable GetCars(int? maxLocos = null) + { + for (int i = 0; i < _places.Count; ++i) + { + yield return _places[i]; + if (maxLocos.HasValue && i == maxLocos.Value) + { + yield break; + } + } + } + //Получение объекта из набора по позиции - public T Get(int position) + /* public T Get(int position) { // TODO проверка позиции if (position < 0 || position >= Count) return null; return _places[position]; - } + }*/ } }