From 6be2956699080c9a5956977d70a11f0587ad1f96 Mon Sep 17 00:00:00 2001 From: Extrimal Date: Sun, 12 Nov 2023 17:12:10 +0300 Subject: [PATCH] =?UTF-8?q?=D0=92=D0=BE=D0=B7=D0=B2=D1=80=D0=B0=D1=89?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B7=D0=BB=D1=8B=D1=85=20=D0=BA?= =?UTF-8?q?=D0=BD=D0=BE=D0=BF=D0=BE=D0=BA(Laba4)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AircraftsGenericCollection.cs | 28 ++--- .../AircraftsGenericStorage.cs | 51 +++++++++ .../FormAircraftCollection.Designer.cs | 108 +++++++++++++++--- .../AircraftCarrier/FormAircraftCollection.cs | 2 + AircraftCarrier/AircraftCarrier/SetGeneric.cs | 77 +++++++------ 5 files changed, 199 insertions(+), 67 deletions(-) create mode 100644 AircraftCarrier/AircraftCarrier/AircraftsGenericStorage.cs diff --git a/AircraftCarrier/AircraftCarrier/AircraftsGenericCollection.cs b/AircraftCarrier/AircraftCarrier/AircraftsGenericCollection.cs index 5c73147..13d8a2a 100644 --- a/AircraftCarrier/AircraftCarrier/AircraftsGenericCollection.cs +++ b/AircraftCarrier/AircraftCarrier/AircraftsGenericCollection.cs @@ -31,7 +31,8 @@ namespace AircraftCarrier.Generics _pictureHeight = picHeight; _collection = new SetGeneric(width * height); } - /// Перегрузка оператора сложения + /// Перегрузка оператора сложения + public static int operator +(AircraftsGenericCollection collect, T? obj) { @@ -42,20 +43,22 @@ namespace AircraftCarrier.Generics return collect._collection.Insert(obj); } /// Перегрузка оператора вычитания - public static bool operator -(AircraftsGenericCollection collect, int pos) + public static T? operator -(AircraftsGenericCollection collect, int pos) { - T? obj = collect._collection.Get(pos); + T? obj = collect._collection[pos]; if (obj != null) { - return collect._collection.Remove(pos); + collect._collection.Remove(pos); } - return false; + return obj; } + /// Получение объекта IMoveableObject public U? GetU(int pos) { - return (U?)_collection.Get(pos)?.GetMoveableObject; + return (U?)_collection[pos]?.GetMoveableObject; } + /// Вывод всего набора объектов public Bitmap ShowAircraft() { @@ -86,15 +89,14 @@ namespace AircraftCarrier.Generics /// Метод прорисовки объектов private void DrawObjects(Graphics g) { - int inRow = _pictureWidth / _placeSizeWidth; - for (int i = 0; i < _collection.Count; i++) + foreach (var car in _collection.GetAircrafts()) { - DrawningAircraft aircraft = _collection.Get(i); - if (aircraft != null) + if (car != null) { - - aircraft.SetPosition(i % inRow * _placeSizeWidth+3, (_collection.Count / inRow - 1 - i / inRow) * _placeSizeHeight + 5); - aircraft.DrawTransport(g); + // TODO получение объекта + // TODO установка позиции + // TODO прорисовка объекта + car.DrawTransport(g); } } } diff --git a/AircraftCarrier/AircraftCarrier/AircraftsGenericStorage.cs b/AircraftCarrier/AircraftCarrier/AircraftsGenericStorage.cs new file mode 100644 index 0000000..c61bce3 --- /dev/null +++ b/AircraftCarrier/AircraftCarrier/AircraftsGenericStorage.cs @@ -0,0 +1,51 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using AircraftCarrier.DrawningObjects; +using AircraftCarrier.MovementStrategy; +namespace AircraftCarrier.Generics +{ + /// Класс для хранения коллекции + internal class AircraftsGenericStorage + { + /// Словарь (хранилище) + readonly Dictionary> _AircraftStorages; + /// Возвращение списка названий наборов + public List Keys => _AircraftStorages.Keys.ToList(); + /// Ширина окна отрисовки + private readonly int _pictureWidth; + /// Высота окна отрисовки + private readonly int _pictureHeight; + /// Конструктор + public AircraftsGenericStorage(int pictureWidth, int pictureHeight) + { + _AircraftStorages = new Dictionary>(); + _pictureWidth = pictureWidth; + _pictureHeight = pictureHeight; + } + /// Добавление набора + public void AddSet(string name) + { + // TODO Прописать логику для добавления + } + /// Удаление набора + public void DelSet(string name) + { + // TODO Прописать логику для удаления + } + /// Доступ к набору + public AircraftsGenericCollection? + this[string ind] + { + get + { + // TODO Продумать логику получения набора + return null; + } + } + } +} diff --git a/AircraftCarrier/AircraftCarrier/FormAircraftCollection.Designer.cs b/AircraftCarrier/AircraftCarrier/FormAircraftCollection.Designer.cs index 02deed5..add90e1 100644 --- a/AircraftCarrier/AircraftCarrier/FormAircraftCollection.Designer.cs +++ b/AircraftCarrier/AircraftCarrier/FormAircraftCollection.Designer.cs @@ -30,38 +30,59 @@ { PictureBoxCollection = new PictureBox(); PanelTools = new Panel(); + PanelSets = new Panel(); ButtonRefreshCollection = new Button(); ButtonRemoveAircraft = new Button(); MaskedTextBoxNumber = new MaskedTextBox(); ButtonAddAircraft = new Button(); - LabelTools = new Label(); + labelTools = new Label(); + labelSets = new Label(); + textBoxStorageName = new TextBox(); + ButtonAddObject = new Button(); + listBoxStorage = new ListBox(); + ButtonRemoveObject = new Button(); ((System.ComponentModel.ISupportInitialize)PictureBoxCollection).BeginInit(); PanelTools.SuspendLayout(); + PanelSets.SuspendLayout(); SuspendLayout(); // // PictureBoxCollection // PictureBoxCollection.Location = new Point(0, 0); PictureBoxCollection.Name = "PictureBoxCollection"; - PictureBoxCollection.Size = new Size(599, 450); + PictureBoxCollection.Size = new Size(768, 651); PictureBoxCollection.TabIndex = 0; PictureBoxCollection.TabStop = false; // // PanelTools // PanelTools.BorderStyle = BorderStyle.FixedSingle; + PanelTools.Controls.Add(labelTools); + PanelTools.Controls.Add(PanelSets); PanelTools.Controls.Add(ButtonRefreshCollection); PanelTools.Controls.Add(ButtonRemoveAircraft); PanelTools.Controls.Add(MaskedTextBoxNumber); PanelTools.Controls.Add(ButtonAddAircraft); - PanelTools.Location = new Point(599, 12); + PanelTools.Location = new Point(774, 12); PanelTools.Name = "PanelTools"; - PanelTools.Size = new Size(202, 438); + PanelTools.Size = new Size(232, 639); PanelTools.TabIndex = 1; // + // PanelSets + // + PanelSets.Controls.Add(ButtonRemoveObject); + PanelSets.Controls.Add(listBoxStorage); + PanelSets.Controls.Add(ButtonAddObject); + PanelSets.Controls.Add(textBoxStorageName); + PanelSets.Controls.Add(labelSets); + PanelSets.Location = new Point(16, 37); + PanelSets.Name = "PanelSets"; + PanelSets.Size = new Size(204, 339); + PanelSets.TabIndex = 4; + // // ButtonRefreshCollection // - ButtonRefreshCollection.Location = new Point(15, 206); + ButtonRefreshCollection.Location = new Point(36, 572); ButtonRefreshCollection.Name = "ButtonRefreshCollection"; ButtonRefreshCollection.Size = new Size(168, 41); ButtonRefreshCollection.TabIndex = 3; @@ -71,7 +92,7 @@ // // ButtonRemoveAircraft // - ButtonRemoveAircraft.Location = new Point(15, 137); + ButtonRemoveAircraft.Location = new Point(36, 497); ButtonRemoveAircraft.Name = "ButtonRemoveAircraft"; ButtonRemoveAircraft.Size = new Size(168, 41); ButtonRemoveAircraft.TabIndex = 2; @@ -81,7 +102,7 @@ // // MaskedTextBoxNumber // - MaskedTextBoxNumber.Location = new Point(36, 95); + MaskedTextBoxNumber.Location = new Point(57, 438); MaskedTextBoxNumber.Name = "MaskedTextBoxNumber"; MaskedTextBoxNumber.Size = new Size(125, 27); MaskedTextBoxNumber.TabIndex = 1; @@ -89,7 +110,7 @@ // // ButtonAddAircraft // - ButtonAddAircraft.Location = new Point(15, 19); + ButtonAddAircraft.Location = new Point(36, 391); ButtonAddAircraft.Name = "ButtonAddAircraft"; ButtonAddAircraft.Size = new Size(168, 41); ButtonAddAircraft.TabIndex = 0; @@ -97,21 +118,63 @@ ButtonAddAircraft.UseVisualStyleBackColor = true; ButtonAddAircraft.Click += ButtonAddAircraft_Click; // - // LabelTools + // labelTools // - LabelTools.AutoSize = true; - LabelTools.Location = new Point(615, 0); - LabelTools.Name = "LabelTools"; - LabelTools.Size = new Size(103, 20); - LabelTools.TabIndex = 0; - LabelTools.Text = "Инструменты"; + labelTools.AutoSize = true; + labelTools.Location = new Point(16, -4); + labelTools.Name = "labelTools"; + labelTools.Size = new Size(103, 20); + labelTools.TabIndex = 5; + labelTools.Text = "Инструменты"; + // + // labelSets + // + labelSets.AutoSize = true; + labelSets.Location = new Point(11, 9); + labelSets.Name = "labelSets"; + labelSets.Size = new Size(55, 20); + labelSets.TabIndex = 0; + labelSets.Text = "Набор"; + // + // textBoxStorageName + // + textBoxStorageName.Location = new Point(41, 41); + textBoxStorageName.Name = "textBoxStorageName"; + textBoxStorageName.Size = new Size(125, 27); + textBoxStorageName.TabIndex = 1; + // + // ButtonAddObject + // + ButtonAddObject.Location = new Point(20, 83); + ButtonAddObject.Name = "ButtonAddObject"; + ButtonAddObject.Size = new Size(168, 41); + ButtonAddObject.TabIndex = 2; + ButtonAddObject.Text = "Добавить набор"; + ButtonAddObject.UseVisualStyleBackColor = true; + // + // listBoxStorage + // + listBoxStorage.FormattingEnabled = true; + listBoxStorage.ItemHeight = 20; + listBoxStorage.Location = new Point(29, 147); + listBoxStorage.Name = "listBoxStorage"; + listBoxStorage.Size = new Size(150, 124); + listBoxStorage.TabIndex = 3; + // + // ButtonRemoveObject + // + ButtonRemoveObject.Location = new Point(20, 286); + ButtonRemoveObject.Name = "ButtonRemoveObject"; + ButtonRemoveObject.Size = new Size(168, 41); + ButtonRemoveObject.TabIndex = 4; + ButtonRemoveObject.Text = "Удалить набор"; + ButtonRemoveObject.UseVisualStyleBackColor = true; // // FormAircraftCollection // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(800, 450); - Controls.Add(LabelTools); + ClientSize = new Size(1007, 651); Controls.Add(PanelTools); Controls.Add(PictureBoxCollection); Name = "FormAircraftCollection"; @@ -119,8 +182,9 @@ ((System.ComponentModel.ISupportInitialize)PictureBoxCollection).EndInit(); PanelTools.ResumeLayout(false); PanelTools.PerformLayout(); + PanelSets.ResumeLayout(false); + PanelSets.PerformLayout(); ResumeLayout(false); - PerformLayout(); } #endregion @@ -129,8 +193,14 @@ private Panel PanelTools; private MaskedTextBox MaskedTextBoxNumber; private Button ButtonAddAircraft; - private Label LabelTools; private Button ButtonRefreshCollection; private Button ButtonRemoveAircraft; + private Panel PanelSets; + private Label labelTools; + private Label labelSets; + private Button ButtonAddObject; + private TextBox textBoxStorageName; + private Button ButtonRemoveObject; + private ListBox listBoxStorage; } } \ No newline at end of file diff --git a/AircraftCarrier/AircraftCarrier/FormAircraftCollection.cs b/AircraftCarrier/AircraftCarrier/FormAircraftCollection.cs index 1f3e5a4..89e381f 100644 --- a/AircraftCarrier/AircraftCarrier/FormAircraftCollection.cs +++ b/AircraftCarrier/AircraftCarrier/FormAircraftCollection.cs @@ -58,5 +58,7 @@ namespace AircraftCarrier { PictureBoxCollection.Image = _Aircrafts.ShowAircraft(); } + + } } diff --git a/AircraftCarrier/AircraftCarrier/SetGeneric.cs b/AircraftCarrier/AircraftCarrier/SetGeneric.cs index 2317c18..4ad9700 100644 --- a/AircraftCarrier/AircraftCarrier/SetGeneric.cs +++ b/AircraftCarrier/AircraftCarrier/SetGeneric.cs @@ -8,60 +8,67 @@ namespace AircraftCarrier.Generics internal class SetGeneric where T : class { - /// Массив объектов, которые храним - private readonly T?[] _places; + /// Список объектов, которые храним + private readonly List _places; /// Количество объектов в массиве - public int Count => _places.Length; + public int Count => _places.Count; + /// Максимальное количество объектов в списке + private readonly int _maxCount; /// Конструктор public SetGeneric(int count) { - _places = new T?[count]; + _maxCount = count; + _places = new List(count); } /// Добавление объекта в набор - public int Insert(T Aircraft) + public bool Insert(T Aircraft) { - return Insert(Aircraft, 0); + // TODO вставка в начало набора + return true; } /// Добавление объекта в набор на конкретную позицию - public int Insert(T Aircraft, int position) + public bool Insert(T Aircraft, int position) { - int nullIndex = -1, i; - - if (position < 0 || position >= Count) - return -1; - - for (i = position; i < Count; i++) - { - if (_places[i] == null) - { - nullIndex = i; - break; - } - } - if (nullIndex < 0) - return -1; - - for (i = nullIndex; i > position; i--) - { - _places[i] = _places[i - 1]; - } - + // TODO проверка позиции + // TODO проверка, что есть место для вставки + // TODO вставка по позиции _places[position] = Aircraft; - return position; + return true; } /// Удаление объекта из набора с конкретной позиции public bool Remove(int position) { - if (position < 0 || position >= Count) return false; - _places[position] = null; + // TODO проверка позиции + // TODO удаление объекта из списка return true; } /// Получение объекта из набора по позиции - public T? Get(int position) + public T? this[int position] { - if (position < 0 || position >= Count) - return null; - return _places[position]; + get + { + // TODO проверка позиции + return _places[position]; + } + set + { + // TODO проверка позиции + // TODO проверка свободных мест в списке + // TODO вставка в список по позиции + } + } + /// Проход по списку + public IEnumerable GetAircrafts(int? maxAircrafts = null) + { + for (int i = 0; i < _places.Count; ++i) + { + yield return _places[i]; + if (maxAircrafts.HasValue && i == maxAircrafts.Value) + { + yield break; + } + } } } + }