From 6be2956699080c9a5956977d70a11f0587ad1f96 Mon Sep 17 00:00:00 2001 From: Extrimal Date: Sun, 12 Nov 2023 17:12:10 +0300 Subject: [PATCH 1/4] =?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; + } + } } } + } -- 2.25.1 From 88833f3f180bee324d9ef9460a9c9776ea418761 Mon Sep 17 00:00:00 2001 From: Extrimal Date: Sun, 12 Nov 2023 23:43:30 +0300 Subject: [PATCH 2/4] =?UTF-8?q?=D0=BF=D0=BE=D0=BB=D1=83=D0=B3=D0=BE=D1=82?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0=D1=8F=20=D0=BB=D0=B0=D0=B1=D0=B04?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AircraftsGenericCollection.cs | 25 +-- .../AircraftsGenericStorage.cs | 15 +- .../AircraftCarrier/FormAircraftCarrier.cs | 3 - .../FormAircraftCollection.Designer.cs | 147 +++++++++--------- .../AircraftCarrier/FormAircraftCollection.cs | 97 ++++++++++-- AircraftCarrier/AircraftCarrier/SetGeneric.cs | 32 ++-- 6 files changed, 203 insertions(+), 116 deletions(-) diff --git a/AircraftCarrier/AircraftCarrier/AircraftsGenericCollection.cs b/AircraftCarrier/AircraftCarrier/AircraftsGenericCollection.cs index 13d8a2a..d2ca4b9 100644 --- a/AircraftCarrier/AircraftCarrier/AircraftsGenericCollection.cs +++ b/AircraftCarrier/AircraftCarrier/AircraftsGenericCollection.cs @@ -43,24 +43,22 @@ namespace AircraftCarrier.Generics return collect._collection.Insert(obj); } /// Перегрузка оператора вычитания - public static T? operator -(AircraftsGenericCollection collect, int pos) + public static bool operator -(AircraftsGenericCollection collect, int pos) { T? obj = collect._collection[pos]; if (obj != null) { - collect._collection.Remove(pos); + return collect._collection.Remove(pos); } - return obj; + return false; } - /// Получение объекта IMoveableObject public U? GetU(int pos) { return (U?)_collection[pos]?.GetMoveableObject; } - /// Вывод всего набора объектов - public Bitmap ShowAircraft() + public Bitmap ShowAircrafts() { Bitmap bmp = new(_pictureWidth, _pictureHeight); Graphics gr = Graphics.FromImage(bmp); @@ -89,15 +87,18 @@ namespace AircraftCarrier.Generics /// Метод прорисовки объектов private void DrawObjects(Graphics g) { - foreach (var car in _collection.GetAircrafts()) + int Width = _pictureWidth / _placeSizeWidth; + int Height = _pictureHeight / _placeSizeHeight; + int i = 0; + foreach (var aircraft in _collection.GetAircrafts()) { - if (car != null) + if (aircraft != null) { - // TODO получение объекта - // TODO установка позиции - // TODO прорисовка объекта - car.DrawTransport(g); + + aircraft.SetPosition(i % Width * _placeSizeWidth + 3, 600); + aircraft.DrawTransport(g); } + i++; } } } diff --git a/AircraftCarrier/AircraftCarrier/AircraftsGenericStorage.cs b/AircraftCarrier/AircraftCarrier/AircraftsGenericStorage.cs index c61bce3..2a5bd08 100644 --- a/AircraftCarrier/AircraftCarrier/AircraftsGenericStorage.cs +++ b/AircraftCarrier/AircraftCarrier/AircraftsGenericStorage.cs @@ -30,12 +30,18 @@ namespace AircraftCarrier.Generics /// Добавление набора public void AddSet(string name) { - // TODO Прописать логику для добавления + if (!_AircraftStorages.ContainsKey(name)) + { + _AircraftStorages.Add(name, new AircraftsGenericCollection(_pictureWidth, _pictureHeight)); + } } /// Удаление набора public void DelSet(string name) { - // TODO Прописать логику для удаления + if (_AircraftStorages.ContainsKey(name)) + { + _AircraftStorages.Remove(name); + } } /// Доступ к набору public AircraftsGenericCollection? @@ -43,7 +49,10 @@ namespace AircraftCarrier.Generics { get { - // TODO Продумать логику получения набора + if (_AircraftStorages.ContainsKey(ind)) + { + return _AircraftStorages[ind]; + } return null; } } diff --git a/AircraftCarrier/AircraftCarrier/FormAircraftCarrier.cs b/AircraftCarrier/AircraftCarrier/FormAircraftCarrier.cs index 0d6d11e..c49d400 100644 --- a/AircraftCarrier/AircraftCarrier/FormAircraftCarrier.cs +++ b/AircraftCarrier/AircraftCarrier/FormAircraftCarrier.cs @@ -50,7 +50,6 @@ namespace AircraftCarrier } Draw(); } - private void ButtonCreateAircraft_Click(object sender, EventArgs e) { Random random = new(); @@ -67,7 +66,6 @@ namespace AircraftCarrier 100)); Draw(); } - private void ButtonCreateAircraftCarrier_Click(object sender, EventArgs e) { Random random = new(); @@ -90,7 +88,6 @@ namespace AircraftCarrier _drawingAircraft.SetPosition(random.Next(10, 100), random.Next(10, 100)); Draw(); } - private void buttonStep_Click(object sender, EventArgs e) { if (_drawingAircraft == null) diff --git a/AircraftCarrier/AircraftCarrier/FormAircraftCollection.Designer.cs b/AircraftCarrier/AircraftCarrier/FormAircraftCollection.Designer.cs index add90e1..365da19 100644 --- a/AircraftCarrier/AircraftCarrier/FormAircraftCollection.Designer.cs +++ b/AircraftCarrier/AircraftCarrier/FormAircraftCollection.Designer.cs @@ -28,31 +28,31 @@ /// private void InitializeComponent() { - PictureBoxCollection = new PictureBox(); + pictureBoxCollection = new PictureBox(); PanelTools = new Panel(); + labelTools = new Label(); PanelSets = new Panel(); + ButtonRemoveObject = new Button(); + listBoxStorage = new ListBox(); + ButtonAddObject = new Button(); + textBoxStorageName = new TextBox(); + labelSets = new Label(); ButtonRefreshCollection = new Button(); ButtonRemoveAircraft = new Button(); MaskedTextBoxNumber = new MaskedTextBox(); ButtonAddAircraft = new Button(); - labelTools = new Label(); - labelSets = new Label(); - textBoxStorageName = new TextBox(); - ButtonAddObject = new Button(); - listBoxStorage = new ListBox(); - ButtonRemoveObject = new Button(); - ((System.ComponentModel.ISupportInitialize)PictureBoxCollection).BeginInit(); + ((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit(); PanelTools.SuspendLayout(); PanelSets.SuspendLayout(); SuspendLayout(); // - // PictureBoxCollection + // pictureBoxCollection // - PictureBoxCollection.Location = new Point(0, 0); - PictureBoxCollection.Name = "PictureBoxCollection"; - PictureBoxCollection.Size = new Size(768, 651); - PictureBoxCollection.TabIndex = 0; - PictureBoxCollection.TabStop = false; + pictureBoxCollection.Location = new Point(0, 0); + pictureBoxCollection.Name = "pictureBoxCollection"; + pictureBoxCollection.Size = new Size(793, 724); + pictureBoxCollection.TabIndex = 0; + pictureBoxCollection.TabStop = false; // // PanelTools // @@ -63,11 +63,20 @@ PanelTools.Controls.Add(ButtonRemoveAircraft); PanelTools.Controls.Add(MaskedTextBoxNumber); PanelTools.Controls.Add(ButtonAddAircraft); - PanelTools.Location = new Point(774, 12); + PanelTools.Location = new Point(799, 12); PanelTools.Name = "PanelTools"; - PanelTools.Size = new Size(232, 639); + PanelTools.Size = new Size(232, 712); PanelTools.TabIndex = 1; // + // labelTools + // + labelTools.AutoSize = true; + labelTools.Location = new Point(16, -4); + labelTools.Name = "labelTools"; + labelTools.Size = new Size(103, 20); + labelTools.TabIndex = 5; + labelTools.Text = "Инструменты"; + // // PanelSets // PanelSets.Controls.Add(ButtonRemoveObject); @@ -80,6 +89,52 @@ PanelSets.Size = new Size(204, 339); PanelSets.TabIndex = 4; // + // ButtonRemoveObject + // + ButtonRemoveObject.Location = new Point(20, 286); + ButtonRemoveObject.Name = "ButtonRemoveObject"; + ButtonRemoveObject.Size = new Size(168, 41); + ButtonRemoveObject.TabIndex = 4; + ButtonRemoveObject.Text = "Удалить набор"; + ButtonRemoveObject.UseVisualStyleBackColor = true; + ButtonRemoveObject.Click += ButtonRemoveObject_Click; + // + // 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; + listBoxStorage.SelectedIndexChanged += listBoxStorage_SelectedIndexChanged; + // + // ButtonAddObject + // + ButtonAddObject.Location = new Point(20, 83); + ButtonAddObject.Name = "ButtonAddObject"; + ButtonAddObject.Size = new Size(168, 41); + ButtonAddObject.TabIndex = 2; + ButtonAddObject.Text = "Добавить набор"; + ButtonAddObject.UseVisualStyleBackColor = true; + ButtonAddObject.Click += ButtonAddObject_Click; + // + // textBoxStorageName + // + textBoxStorageName.Location = new Point(41, 41); + textBoxStorageName.Name = "textBoxStorageName"; + textBoxStorageName.Size = new Size(125, 27); + textBoxStorageName.TabIndex = 1; + // + // labelSets + // + labelSets.AutoSize = true; + labelSets.Location = new Point(11, 9); + labelSets.Name = "labelSets"; + labelSets.Size = new Size(55, 20); + labelSets.TabIndex = 0; + labelSets.Text = "Набор"; + // // ButtonRefreshCollection // ButtonRefreshCollection.Location = new Point(36, 572); @@ -118,68 +173,16 @@ ButtonAddAircraft.UseVisualStyleBackColor = true; ButtonAddAircraft.Click += ButtonAddAircraft_Click; // - // labelTools - // - 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(1007, 651); + ClientSize = new Size(1033, 724); Controls.Add(PanelTools); - Controls.Add(PictureBoxCollection); + Controls.Add(pictureBoxCollection); Name = "FormAircraftCollection"; Text = "FormAircraftCollection"; - ((System.ComponentModel.ISupportInitialize)PictureBoxCollection).EndInit(); + ((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit(); PanelTools.ResumeLayout(false); PanelTools.PerformLayout(); PanelSets.ResumeLayout(false); @@ -189,7 +192,7 @@ #endregion - private PictureBox PictureBoxCollection; + private PictureBox pictureBoxCollection; private Panel PanelTools; private MaskedTextBox MaskedTextBoxNumber; private Button ButtonAddAircraft; diff --git a/AircraftCarrier/AircraftCarrier/FormAircraftCollection.cs b/AircraftCarrier/AircraftCarrier/FormAircraftCollection.cs index 89e381f..f4ebfd2 100644 --- a/AircraftCarrier/AircraftCarrier/FormAircraftCollection.cs +++ b/AircraftCarrier/AircraftCarrier/FormAircraftCollection.cs @@ -14,40 +14,107 @@ namespace AircraftCarrier { public partial class FormAircraftCollection : Form { - private readonly AircraftsGenericCollection _Aircrafts; + private readonly AircraftsGenericStorage _storage; public FormAircraftCollection() { InitializeComponent(); - _Aircrafts = new AircraftsGenericCollection(PictureBoxCollection.Width, PictureBoxCollection.Height); + _storage = new AircraftsGenericStorage(pictureBoxCollection.Width, pictureBoxCollection.Height); + } + /// Заполнение listBoxObjects + private void ReloadObjects() + { + int index = listBoxStorage.SelectedIndex; + listBoxStorage.Items.Clear(); + for (int i = 0; i < _storage.Keys.Count; i++) + { + listBoxStorage.Items.Add(_storage.Keys[i]); + } + if (listBoxStorage.Items.Count > 0 && (index == -1 || index >= listBoxStorage.Items.Count)) + { + listBoxStorage.SelectedIndex = 0; + } + else if (listBoxStorage.Items.Count > 0 && index > -1 && index < listBoxStorage.Items.Count) + { + listBoxStorage.SelectedIndex = index; + } + } + private void ButtonAddObject_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxStorageName.Text)) + { + MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _storage.AddSet(textBoxStorageName.Text); + ReloadObjects(); + } + private void listBoxStorage_SelectedIndexChanged(object sender, EventArgs e) + { + pictureBoxCollection.Image = _storage[listBoxStorage.SelectedItem?.ToString() ?? string.Empty]?.ShowAircrafts(); + } + private void ButtonRemoveObject_Click(object sender, EventArgs e) + { + if (listBoxStorage.SelectedIndex == -1) + { + return; + } + if (MessageBox.Show($"Удалить объект{listBoxStorage.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, + MessageBoxIcon.Question) == DialogResult.Yes) + { + _storage.DelSet(listBoxStorage.SelectedItem.ToString() + ?? string.Empty); + ReloadObjects(); + } } private void ButtonAddAircraft_Click(object sender, EventArgs e) { + if (listBoxStorage.SelectedIndex == -1) + { + return; + } + + var obj = _storage[listBoxStorage.SelectedItem.ToString() ?? string.Empty]; + if (obj == null) + { + return; + } + FormAircraftCarrier form = new(); if (form.ShowDialog() == DialogResult.OK) { - if (_Aircrafts + form.SelectedAircraft != -1) + if (obj + form.SelectedAircraft != -1) { MessageBox.Show("Объект добавлен"); - PictureBoxCollection.Image = _Aircrafts.ShowAircraft(); + pictureBoxCollection.Image = obj.ShowAircrafts(); } else { MessageBox.Show("Не удалось добавить объект"); } } - } private void ButtonRemoveAircraft_Click(object sender, EventArgs e) { - if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) + if (listBoxStorage.SelectedIndex == -1) + { + return; + } + var obj = _storage[listBoxStorage.SelectedItem.ToString() ?? + string.Empty]; + if (obj == null) + { + return; + } + if (MessageBox.Show("Удалить объект?", "Удаление", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } int pos = Convert.ToInt32(MaskedTextBoxNumber.Text); - if (_Aircrafts - pos != null) + if (obj - pos != null) { MessageBox.Show("Объект удален"); - PictureBoxCollection.Image = _Aircrafts.ShowAircraft(); + pictureBoxCollection.Image = obj.ShowAircrafts(); } else { @@ -56,9 +123,17 @@ namespace AircraftCarrier } private void ButtonRefreshCollection_Click(object sender, EventArgs e) { - PictureBoxCollection.Image = _Aircrafts.ShowAircraft(); + if (listBoxStorage.SelectedIndex == -1) + { + return; + } + var obj = _storage[listBoxStorage.SelectedItem.ToString() ?? + string.Empty]; + if (obj == null) + { + return; + } + pictureBoxCollection.Image = obj.ShowAircrafts(); } - - } } diff --git a/AircraftCarrier/AircraftCarrier/SetGeneric.cs b/AircraftCarrier/AircraftCarrier/SetGeneric.cs index 4ad9700..fdf0310 100644 --- a/AircraftCarrier/AircraftCarrier/SetGeneric.cs +++ b/AircraftCarrier/AircraftCarrier/SetGeneric.cs @@ -21,25 +21,25 @@ namespace AircraftCarrier.Generics _places = new List(count); } /// Добавление объекта в набор - public bool Insert(T Aircraft) + public int Insert(T Aircraft) { - // TODO вставка в начало набора - return true; + return Insert(Aircraft, 0); } /// Добавление объекта в набор на конкретную позицию - public bool Insert(T Aircraft, int position) + public int Insert(T Aircraft, int position) { - // TODO проверка позиции - // TODO проверка, что есть место для вставки - // TODO вставка по позиции - _places[position] = Aircraft; - return true; + if (position < 0 || position > Count || Count >= _maxCount) + return -1; + + _places.Insert(position, Aircraft); + return position; } /// Удаление объекта из набора с конкретной позиции public bool Remove(int position) { - // TODO проверка позиции - // TODO удаление объекта из списка + if (position < 0 || position >= Count) + return false; + _places.RemoveAt(position); return true; } /// Получение объекта из набора по позиции @@ -47,14 +47,16 @@ namespace AircraftCarrier.Generics { get { - // TODO проверка позиции + if (position < 0 || position >= Count) + return null; return _places[position]; } set { - // TODO проверка позиции - // TODO проверка свободных мест в списке - // TODO вставка в список по позиции + if (position < 0 || position > Count || Count >= _maxCount) + return; + + _places.Insert(position, value); } } /// Проход по списку -- 2.25.1 From 34bd3079ab9eae3b62465c20d11d310635694549 Mon Sep 17 00:00:00 2001 From: Extrimal Date: Tue, 14 Nov 2023 00:12:26 +0300 Subject: [PATCH 3/4] =?UTF-8?q?=D0=A1=D1=83=D0=BF=D0=B5=D1=80=20=D0=B7?= =?UTF-8?q?=D0=B0=D0=B2=D0=B5=D1=80=D1=88=D0=B5=D0=BD=D0=BD=D0=B0=D1=8F=20?= =?UTF-8?q?=D0=BB=D0=B0=D0=B1=D0=B0=204?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AircraftsGenericCollection.cs | 2 +- .../FormAircraftCarrier.Designer.cs | 23 ++++++++++--------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/AircraftCarrier/AircraftCarrier/AircraftsGenericCollection.cs b/AircraftCarrier/AircraftCarrier/AircraftsGenericCollection.cs index d2ca4b9..4a8a8bf 100644 --- a/AircraftCarrier/AircraftCarrier/AircraftsGenericCollection.cs +++ b/AircraftCarrier/AircraftCarrier/AircraftsGenericCollection.cs @@ -95,7 +95,7 @@ namespace AircraftCarrier.Generics if (aircraft != null) { - aircraft.SetPosition(i % Width * _placeSizeWidth + 3, 600); + aircraft.SetPosition(i % Width * _placeSizeWidth + 3, (Height - i / Width - 1) * _placeSizeHeight +5); aircraft.DrawTransport(g); } i++; diff --git a/AircraftCarrier/AircraftCarrier/FormAircraftCarrier.Designer.cs b/AircraftCarrier/AircraftCarrier/FormAircraftCarrier.Designer.cs index 933f90b..d1da1d4 100644 --- a/AircraftCarrier/AircraftCarrier/FormAircraftCarrier.Designer.cs +++ b/AircraftCarrier/AircraftCarrier/FormAircraftCarrier.Designer.cs @@ -46,7 +46,7 @@ pictureBox.Dock = DockStyle.Fill; pictureBox.Location = new Point(0, 0); pictureBox.Name = "pictureBox"; - pictureBox.Size = new Size(882, 453); + pictureBox.Size = new Size(1033, 724); pictureBox.SizeMode = PictureBoxSizeMode.AutoSize; pictureBox.TabIndex = 0; pictureBox.TabStop = false; @@ -57,7 +57,7 @@ buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonUp.BackgroundImage = Properties.Resources.Icon_Up; buttonUp.BackgroundImageLayout = ImageLayout.Zoom; - buttonUp.Location = new Point(791, 366); + buttonUp.Location = new Point(942, 637); buttonUp.Name = "buttonUp"; buttonUp.Size = new Size(30, 30); buttonUp.TabIndex = 2; @@ -69,7 +69,7 @@ buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonLeft.BackgroundImage = Properties.Resources.Icon_Left; buttonLeft.BackgroundImageLayout = ImageLayout.Zoom; - buttonLeft.Location = new Point(755, 402); + buttonLeft.Location = new Point(906, 673); buttonLeft.Name = "buttonLeft"; buttonLeft.Size = new Size(30, 30); buttonLeft.TabIndex = 3; @@ -81,7 +81,7 @@ buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonDown.BackgroundImage = Properties.Resources.Icon_Down; buttonDown.BackgroundImageLayout = ImageLayout.Zoom; - buttonDown.Location = new Point(791, 402); + buttonDown.Location = new Point(942, 673); buttonDown.Name = "buttonDown"; buttonDown.Size = new Size(30, 30); buttonDown.TabIndex = 4; @@ -93,7 +93,7 @@ buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonRight.BackgroundImage = Properties.Resources.Icon_Right; buttonRight.BackgroundImageLayout = ImageLayout.Zoom; - buttonRight.Location = new Point(827, 402); + buttonRight.Location = new Point(978, 673); buttonRight.Name = "buttonRight"; buttonRight.Size = new Size(30, 30); buttonRight.TabIndex = 5; @@ -103,7 +103,7 @@ // ButtonCreateAircraftCarrier // ButtonCreateAircraftCarrier.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - ButtonCreateAircraftCarrier.Location = new Point(234, 393); + ButtonCreateAircraftCarrier.Location = new Point(234, 664); ButtonCreateAircraftCarrier.Name = "ButtonCreateAircraftCarrier"; ButtonCreateAircraftCarrier.Size = new Size(204, 39); ButtonCreateAircraftCarrier.TabIndex = 6; @@ -114,7 +114,7 @@ // ButtonCreateAircraft // ButtonCreateAircraft.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - ButtonCreateAircraft.Location = new Point(12, 393); + ButtonCreateAircraft.Location = new Point(12, 664); ButtonCreateAircraft.Name = "ButtonCreateAircraft"; ButtonCreateAircraft.Size = new Size(204, 39); ButtonCreateAircraft.TabIndex = 7; @@ -128,7 +128,7 @@ comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxStrategy.FormattingEnabled = true; comboBoxStrategy.Items.AddRange(new object[] { "MoveToCenter", "MoveToBorder" }); - comboBoxStrategy.Location = new Point(706, 12); + comboBoxStrategy.Location = new Point(857, 12); comboBoxStrategy.Name = "comboBoxStrategy"; comboBoxStrategy.Size = new Size(151, 28); comboBoxStrategy.TabIndex = 8; @@ -136,7 +136,7 @@ // buttonStep // buttonStep.Anchor = AnchorStyles.Top | AnchorStyles.Right; - buttonStep.Location = new Point(763, 46); + buttonStep.Location = new Point(914, 46); buttonStep.Name = "buttonStep"; buttonStep.Size = new Size(94, 29); buttonStep.TabIndex = 9; @@ -146,7 +146,8 @@ // // buttonSelectAircraft // - buttonSelectAircraft.Location = new Point(457, 393); + buttonSelectAircraft.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + buttonSelectAircraft.Location = new Point(456, 664); buttonSelectAircraft.Name = "buttonSelectAircraft"; buttonSelectAircraft.Size = new Size(204, 39); buttonSelectAircraft.TabIndex = 10; @@ -158,7 +159,7 @@ // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(882, 453); + ClientSize = new Size(1033, 724); Controls.Add(buttonSelectAircraft); Controls.Add(buttonStep); Controls.Add(comboBoxStrategy); -- 2.25.1 From 25d0161b034370c40f12076283e7313003e46248 Mon Sep 17 00:00:00 2001 From: Extrimal Date: Tue, 14 Nov 2023 15:27:41 +0300 Subject: [PATCH 4/4] =?UTF-8?q?=D0=9D=D1=83=20=D0=B2=D1=81=D0=B5,=20=D0=B3?= =?UTF-8?q?=D0=BE=D1=82=D0=BE=D0=B2=D0=B0=D1=8F=20=D0=BB=D0=B0=D0=B1=D0=B0?= =?UTF-8?q?=204?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AircraftCarrier/AircraftCarrier/AircraftsGenericCollection.cs | 2 -- AircraftCarrier/AircraftCarrier/FormAircraftCollection.cs | 2 -- AircraftCarrier/AircraftCarrier/SetGeneric.cs | 1 - 3 files changed, 5 deletions(-) diff --git a/AircraftCarrier/AircraftCarrier/AircraftsGenericCollection.cs b/AircraftCarrier/AircraftCarrier/AircraftsGenericCollection.cs index 4a8a8bf..928955c 100644 --- a/AircraftCarrier/AircraftCarrier/AircraftsGenericCollection.cs +++ b/AircraftCarrier/AircraftCarrier/AircraftsGenericCollection.cs @@ -32,7 +32,6 @@ namespace AircraftCarrier.Generics _collection = new SetGeneric(width * height); } /// Перегрузка оператора сложения - public static int operator +(AircraftsGenericCollection collect, T? obj) { @@ -94,7 +93,6 @@ namespace AircraftCarrier.Generics { if (aircraft != null) { - aircraft.SetPosition(i % Width * _placeSizeWidth + 3, (Height - i / Width - 1) * _placeSizeHeight +5); aircraft.DrawTransport(g); } diff --git a/AircraftCarrier/AircraftCarrier/FormAircraftCollection.cs b/AircraftCarrier/AircraftCarrier/FormAircraftCollection.cs index f4ebfd2..61817b1 100644 --- a/AircraftCarrier/AircraftCarrier/FormAircraftCollection.cs +++ b/AircraftCarrier/AircraftCarrier/FormAircraftCollection.cs @@ -72,13 +72,11 @@ namespace AircraftCarrier { return; } - var obj = _storage[listBoxStorage.SelectedItem.ToString() ?? string.Empty]; if (obj == null) { return; } - FormAircraftCarrier form = new(); if (form.ShowDialog() == DialogResult.OK) { diff --git a/AircraftCarrier/AircraftCarrier/SetGeneric.cs b/AircraftCarrier/AircraftCarrier/SetGeneric.cs index fdf0310..006b946 100644 --- a/AircraftCarrier/AircraftCarrier/SetGeneric.cs +++ b/AircraftCarrier/AircraftCarrier/SetGeneric.cs @@ -72,5 +72,4 @@ namespace AircraftCarrier.Generics } } } - } -- 2.25.1