From 81a407cc630859d7d197f9df66f5eea0d9eeb0d9 Mon Sep 17 00:00:00 2001 From: ArtemEmelyanov Date: Sat, 29 Oct 2022 14:07:33 +0400 Subject: [PATCH 1/5] =?UTF-8?q?=D0=AD=D1=82=D0=B0=D0=BF=201.=20=D0=A1?= =?UTF-8?q?=D0=BC=D0=B5=D0=BD=D0=B0=20=D0=BC=D0=B0=D1=81=D1=81=D0=B8=D0=B2?= =?UTF-8?q?=D0=B0=20=D0=BD=D0=B0=20=D1=81=D0=BF=D0=B8=D1=81=D0=BA=D0=B8.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Airbus/Airbus/MapWithSetPlanesGeneric.cs | 25 +++---- Airbus/Airbus/SetPlanesGeneric.cs | 88 +++++++++++------------- 2 files changed, 48 insertions(+), 65 deletions(-) diff --git a/Airbus/Airbus/MapWithSetPlanesGeneric.cs b/Airbus/Airbus/MapWithSetPlanesGeneric.cs index 6b7dd53..62b18f1 100644 --- a/Airbus/Airbus/MapWithSetPlanesGeneric.cs +++ b/Airbus/Airbus/MapWithSetPlanesGeneric.cs @@ -88,16 +88,13 @@ namespace Airbus public Bitmap ShowOnMap() { Shaking(); - for (int i = 0; i < _setPlanes.Count; i++) + foreach (var plane in _setPlanes.GetPlanes()) { - var plane = _setPlanes.Get(i); - if (plane != null) - { - return _map.CreateMap(_pictureWidth, _pictureHeight, plane); - } + return _map.CreateMap(_pictureWidth, _pictureHeight, plane); } return new(_pictureWidth, _pictureHeight); } + /// /// Перемещение объекта по крате /// @@ -119,11 +116,11 @@ namespace Airbus int j = _setPlanes.Count - 1; for (int i = 0; i < _setPlanes.Count; i++) { - if (_setPlanes.Get(i) == null) + if (_setPlanes[i] == null) { for (; j > i; j--) { - var plane = _setPlanes.Get(j); + var plane = _setPlanes[j]; if (plane != null) { _setPlanes.Insert(plane, i); @@ -181,19 +178,13 @@ namespace Airbus /// private void DrawPlanes(Graphics g) { - int width = _pictureWidth / _placeSizeWidth; - int height = _pictureHeight / _placeSizeHeight; - - for (int i = 0; i < _setPlanes.Count; i++) + foreach (var plane in _setPlanes.GetPlanes()) { // TODO установка позиции - if(_setPlanes.Get(i) != null) - { - _setPlanes.Get(i).SetObject((width - i % width - 1) * _placeSizeWidth,(height - i / width - 1) * _placeSizeHeight, _pictureWidth, _pictureHeight); - _setPlanes.Get(i)?.DrawningObject(g); - } + plane.DrawningObject(g); } } + } } diff --git a/Airbus/Airbus/SetPlanesGeneric.cs b/Airbus/Airbus/SetPlanesGeneric.cs index a7f7d3d..121aeea 100644 --- a/Airbus/Airbus/SetPlanesGeneric.cs +++ b/Airbus/Airbus/SetPlanesGeneric.cs @@ -10,75 +10,46 @@ namespace Airbus 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 SetPlanesGeneric(int count) { - _places = new T[count]; + _maxCount = count; + _places = new List(); } /// /// Добавление объекта в набор /// - /// Добавляемый самолёт + /// Добавляемый автомобиль /// public int Insert(T plane) { // TODO вставка в начало набора - return Insert(plane, 0); + // TODO проверка на _maxCount + return -1; } - /// /// Добавление объекта в набор на конкретную позицию /// - /// Добавляемый самолёт + /// Добавляемый автомобиль /// Позиция /// public int Insert(T plane, int position) { // TODO проверка позиции - // TODO проверка, что элемент массива по этой позиции пустой, если нет, то - // проверка, что после вставляемого элемента в массиве есть пустой элемент - // сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента // TODO вставка по позиции - - if(_places[position] == null) - { - _places[position] = plane; - return position; - } - else - { - int pos = -1; - bool isFree = false; - for (int i = 0; i < Count; i++) - { - if (_places[i] == null) - { - isFree = true; - pos = i; - break; - } - } - if (isFree) - { - for (var i = pos; i > position; --i) _places[i] = _places[i - 1]; - _places[position] = plane; - return position; - } - else - { - return -1; - } - } + _places[position] = plane; + return -1; } /// /// Удаление объекта из набора с конкретной позиции @@ -99,15 +70,36 @@ namespace Airbus /// /// /// - public T Get(int position) + public T this[int position] { - // TODO проверка позиции - if (position < 0 || position >= Count) + get { - return null; + // TODO проверка позиции + return _places[position]; + } + set + { + // TODO проверка позиции + // TODO вставка в список по позиции + } + } + /// + /// Проход по набору до первого пустого + /// + /// + public IEnumerable GetPlanes() + { + foreach (var plane in _places) + { + if (plane != null) + { + yield return plane; + } + else + { + yield break; + } } - return _places[position]; } } - } -- 2.25.1 From 71e7819cfd1425556f0d3a621aa3c76d1a9ee019 Mon Sep 17 00:00:00 2001 From: ArtemEmelyanov Date: Sat, 29 Oct 2022 14:12:01 +0400 Subject: [PATCH 2/5] =?UTF-8?q?=D0=AD=D1=82=D0=B0=D0=BF=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Airbus/Airbus/MapsCollection.cs | 69 +++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 Airbus/Airbus/MapsCollection.cs diff --git a/Airbus/Airbus/MapsCollection.cs b/Airbus/Airbus/MapsCollection.cs new file mode 100644 index 0000000..b86efbe --- /dev/null +++ b/Airbus/Airbus/MapsCollection.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Airbus +{ + internal class MapsCollection + { + /// + /// Словарь (хранилище) с картами + /// + readonly Dictionary> _mapStorages; + /// + /// Возвращение списка названий карт + /// + public List Keys => _mapStorages.Keys.ToList(); + /// + /// Ширина окна отрисовки + /// + private readonly int _pictureWidth; + /// + /// Высота окна отрисовки + /// + private readonly int _pictureHeight; + /// + /// Конструктор + /// + /// + /// + public MapsCollection(int pictureWidth, int pictureHeight) + { + _mapStorages = new Dictionary>(); + _pictureWidth = pictureWidth; + _pictureHeight = pictureHeight; + } + /// + /// Добавление карты + /// + /// Название карты + /// Карта + public void AddMap(string name, AbstractMap map) + { + // TODO Прописать логику для добавления + } + /// + /// Удаление карты + /// + /// Название карты + public void DelMap(string name) + { + // TODO Прописать логику для удаления + } + /// + /// Доступ к парковке + /// + /// + /// + public MapWithSetPlanesGeneric this[string ind] + { + get + { + // TODO Продумать логику получения объекта + return null; + } + } + } +} -- 2.25.1 From bc84a238c411816858a7828019ae60ca6fd7e7a6 Mon Sep 17 00:00:00 2001 From: ArtemEmelyanov Date: Sat, 29 Oct 2022 14:59:03 +0400 Subject: [PATCH 3/5] =?UTF-8?q?=D0=AD=D1=82=D0=B0=D0=BF=203?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Airbus/FormMapWithSetPlanes.Designer.cs | 151 ++++++++++++------ Airbus/Airbus/FormMapWithSetPlanes.cs | 127 +++++++++++---- 2 files changed, 193 insertions(+), 85 deletions(-) diff --git a/Airbus/Airbus/FormMapWithSetPlanes.Designer.cs b/Airbus/Airbus/FormMapWithSetPlanes.Designer.cs index 159ed8c..94089fb 100644 --- a/Airbus/Airbus/FormMapWithSetPlanes.Designer.cs +++ b/Airbus/Airbus/FormMapWithSetPlanes.Designer.cs @@ -29,6 +29,12 @@ private void InitializeComponent() { this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.groupBoxMaps = new System.Windows.Forms.GroupBox(); + this.buttonDeleteMap = new System.Windows.Forms.Button(); + this.listBoxMaps = new System.Windows.Forms.ListBox(); + this.buttonAddMap = new System.Windows.Forms.Button(); + this.textBoxNewMapName = new System.Windows.Forms.TextBox(); + this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox(); this.buttonLeft = new System.Windows.Forms.Button(); this.buttonRight = new System.Windows.Forms.Button(); this.buttonDown = new System.Windows.Forms.Button(); @@ -38,14 +44,15 @@ this.buttonRemovePlane = new System.Windows.Forms.Button(); this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox(); this.buttonAddPlane = new System.Windows.Forms.Button(); - this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox(); this.pictureBox = new System.Windows.Forms.PictureBox(); this.groupBox1.SuspendLayout(); + this.groupBoxMaps.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit(); this.SuspendLayout(); // // groupBox1 // + this.groupBox1.Controls.Add(this.groupBoxMaps); this.groupBox1.Controls.Add(this.buttonLeft); this.groupBox1.Controls.Add(this.buttonRight); this.groupBox1.Controls.Add(this.buttonDown); @@ -55,25 +62,81 @@ this.groupBox1.Controls.Add(this.buttonRemovePlane); this.groupBox1.Controls.Add(this.maskedTextBoxPosition); this.groupBox1.Controls.Add(this.buttonAddPlane); - this.groupBox1.Controls.Add(this.comboBoxSelectorMap); this.groupBox1.Dock = System.Windows.Forms.DockStyle.Right; - this.groupBox1.Location = new System.Drawing.Point(685, 0); - this.groupBox1.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.groupBox1.Location = new System.Drawing.Point(657, 0); this.groupBox1.Name = "groupBox1"; - this.groupBox1.Padding = new System.Windows.Forms.Padding(3, 4, 3, 4); - this.groupBox1.Size = new System.Drawing.Size(229, 600); + this.groupBox1.Size = new System.Drawing.Size(200, 614); this.groupBox1.TabIndex = 0; this.groupBox1.TabStop = false; this.groupBox1.Text = "Инструменты"; // + // groupBoxMaps + // + this.groupBoxMaps.Controls.Add(this.buttonDeleteMap); + this.groupBoxMaps.Controls.Add(this.listBoxMaps); + this.groupBoxMaps.Controls.Add(this.buttonAddMap); + this.groupBoxMaps.Controls.Add(this.textBoxNewMapName); + this.groupBoxMaps.Controls.Add(this.comboBoxSelectorMap); + this.groupBoxMaps.Location = new System.Drawing.Point(6, 22); + this.groupBoxMaps.Name = "groupBoxMaps"; + this.groupBoxMaps.Size = new System.Drawing.Size(188, 263); + this.groupBoxMaps.TabIndex = 10; + this.groupBoxMaps.TabStop = false; + this.groupBoxMaps.Text = "Карты"; + // + // buttonDeleteMap + // + this.buttonDeleteMap.Location = new System.Drawing.Point(11, 218); + this.buttonDeleteMap.Name = "buttonDeleteMap"; + this.buttonDeleteMap.Size = new System.Drawing.Size(171, 34); + this.buttonDeleteMap.TabIndex = 4; + this.buttonDeleteMap.Text = "Удалить карту"; + this.buttonDeleteMap.UseVisualStyleBackColor = true; + // + // listBoxMaps + // + this.listBoxMaps.FormattingEnabled = true; + this.listBoxMaps.ItemHeight = 15; + this.listBoxMaps.Location = new System.Drawing.Point(11, 118); + this.listBoxMaps.Name = "listBoxMaps"; + this.listBoxMaps.Size = new System.Drawing.Size(171, 94); + this.listBoxMaps.TabIndex = 3; + this.listBoxMaps.SelectedIndexChanged += new System.EventHandler(this.listBoxMaps_SelectedIndexChanged_1); + // + // buttonAddMap + // + this.buttonAddMap.Location = new System.Drawing.Point(11, 80); + this.buttonAddMap.Name = "buttonAddMap"; + this.buttonAddMap.Size = new System.Drawing.Size(171, 32); + this.buttonAddMap.TabIndex = 2; + this.buttonAddMap.Text = "Добавить карту"; + this.buttonAddMap.UseVisualStyleBackColor = true; + // + // textBoxNewMapName + // + this.textBoxNewMapName.Location = new System.Drawing.Point(11, 22); + this.textBoxNewMapName.Name = "textBoxNewMapName"; + this.textBoxNewMapName.Size = new System.Drawing.Size(171, 23); + this.textBoxNewMapName.TabIndex = 0; + // + // comboBoxSelectorMap + // + this.comboBoxSelectorMap.FormattingEnabled = true; + this.comboBoxSelectorMap.Items.AddRange(new object[] { + "Простая карта", + "Вторая карта"}); + this.comboBoxSelectorMap.Location = new System.Drawing.Point(11, 51); + this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; + this.comboBoxSelectorMap.Size = new System.Drawing.Size(171, 23); + this.comboBoxSelectorMap.TabIndex = 0; + // // buttonLeft // this.buttonLeft.BackgroundImage = global::Airbus.Properties.Resources.arrowLeft; this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonLeft.Location = new System.Drawing.Point(64, 541); - this.buttonLeft.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.buttonLeft.Location = new System.Drawing.Point(56, 572); this.buttonLeft.Name = "buttonLeft"; - this.buttonLeft.Size = new System.Drawing.Size(34, 40); + this.buttonLeft.Size = new System.Drawing.Size(30, 30); this.buttonLeft.TabIndex = 9; this.buttonLeft.UseVisualStyleBackColor = true; this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click); @@ -82,10 +145,9 @@ // this.buttonRight.BackgroundImage = global::Airbus.Properties.Resources.arrowRight; this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonRight.Location = new System.Drawing.Point(146, 541); - this.buttonRight.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.buttonRight.Location = new System.Drawing.Point(128, 572); this.buttonRight.Name = "buttonRight"; - this.buttonRight.Size = new System.Drawing.Size(34, 40); + this.buttonRight.Size = new System.Drawing.Size(30, 30); this.buttonRight.TabIndex = 8; this.buttonRight.UseVisualStyleBackColor = true; this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click); @@ -94,10 +156,9 @@ // this.buttonDown.BackgroundImage = global::Airbus.Properties.Resources.arrowDown; this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonDown.Location = new System.Drawing.Point(105, 541); - this.buttonDown.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.buttonDown.Location = new System.Drawing.Point(92, 572); this.buttonDown.Name = "buttonDown"; - this.buttonDown.Size = new System.Drawing.Size(34, 40); + this.buttonDown.Size = new System.Drawing.Size(30, 30); this.buttonDown.TabIndex = 7; this.buttonDown.UseVisualStyleBackColor = true; this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click); @@ -106,20 +167,18 @@ // this.buttonUp.BackgroundImage = global::Airbus.Properties.Resources.arrowUp; this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonUp.Location = new System.Drawing.Point(105, 493); - this.buttonUp.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.buttonUp.Location = new System.Drawing.Point(92, 536); this.buttonUp.Name = "buttonUp"; - this.buttonUp.Size = new System.Drawing.Size(34, 40); + this.buttonUp.Size = new System.Drawing.Size(30, 30); this.buttonUp.TabIndex = 6; this.buttonUp.UseVisualStyleBackColor = true; this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click); // // buttonShowOnMap // - this.buttonShowOnMap.Location = new System.Drawing.Point(19, 411); - this.buttonShowOnMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.buttonShowOnMap.Location = new System.Drawing.Point(17, 499); this.buttonShowOnMap.Name = "buttonShowOnMap"; - this.buttonShowOnMap.Size = new System.Drawing.Size(195, 41); + this.buttonShowOnMap.Size = new System.Drawing.Size(171, 31); this.buttonShowOnMap.TabIndex = 5; this.buttonShowOnMap.Text = "Посмотреть карту"; this.buttonShowOnMap.UseVisualStyleBackColor = true; @@ -127,10 +186,9 @@ // // buttonShowStorage // - this.buttonShowStorage.Location = new System.Drawing.Point(19, 345); - this.buttonShowStorage.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.buttonShowStorage.Location = new System.Drawing.Point(17, 459); this.buttonShowStorage.Name = "buttonShowStorage"; - this.buttonShowStorage.Size = new System.Drawing.Size(195, 45); + this.buttonShowStorage.Size = new System.Drawing.Size(171, 34); this.buttonShowStorage.TabIndex = 4; this.buttonShowStorage.Text = "Посмотреть хранилище"; this.buttonShowStorage.UseVisualStyleBackColor = true; @@ -138,10 +196,9 @@ // // buttonRemovePlane // - this.buttonRemovePlane.Location = new System.Drawing.Point(19, 225); - this.buttonRemovePlane.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.buttonRemovePlane.Location = new System.Drawing.Point(17, 400); this.buttonRemovePlane.Name = "buttonRemovePlane"; - this.buttonRemovePlane.Size = new System.Drawing.Size(195, 41); + this.buttonRemovePlane.Size = new System.Drawing.Size(171, 31); this.buttonRemovePlane.TabIndex = 3; this.buttonRemovePlane.Text = "Удалить самолёт"; this.buttonRemovePlane.UseVisualStyleBackColor = true; @@ -149,60 +206,45 @@ // // maskedTextBoxPosition // - this.maskedTextBoxPosition.Location = new System.Drawing.Point(19, 168); - this.maskedTextBoxPosition.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.maskedTextBoxPosition.Location = new System.Drawing.Point(17, 371); this.maskedTextBoxPosition.Mask = "00"; this.maskedTextBoxPosition.Name = "maskedTextBoxPosition"; - this.maskedTextBoxPosition.Size = new System.Drawing.Size(195, 27); + this.maskedTextBoxPosition.Size = new System.Drawing.Size(171, 23); this.maskedTextBoxPosition.TabIndex = 2; // // buttonAddPlane // - this.buttonAddPlane.Location = new System.Drawing.Point(19, 85); - this.buttonAddPlane.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.buttonAddPlane.Location = new System.Drawing.Point(17, 315); this.buttonAddPlane.Name = "buttonAddPlane"; - this.buttonAddPlane.Size = new System.Drawing.Size(195, 41); + this.buttonAddPlane.Size = new System.Drawing.Size(171, 31); this.buttonAddPlane.TabIndex = 1; this.buttonAddPlane.Text = "Добавить самолёт"; this.buttonAddPlane.UseVisualStyleBackColor = true; this.buttonAddPlane.Click += new System.EventHandler(this.buttonAddPlane_Click_1); // - // comboBoxSelectorMap - // - this.comboBoxSelectorMap.FormattingEnabled = true; - this.comboBoxSelectorMap.Items.AddRange(new object[] { - "Простая карта", - "Вторая карта"}); - this.comboBoxSelectorMap.Location = new System.Drawing.Point(19, 29); - this.comboBoxSelectorMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); - this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; - this.comboBoxSelectorMap.Size = new System.Drawing.Size(195, 28); - this.comboBoxSelectorMap.TabIndex = 0; - this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.comboBoxSelectorMap_SelectedIndexChanged_1); - // // pictureBox // this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill; this.pictureBox.Location = new System.Drawing.Point(0, 0); - this.pictureBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.pictureBox.Name = "pictureBox"; - this.pictureBox.Size = new System.Drawing.Size(685, 600); + this.pictureBox.Size = new System.Drawing.Size(657, 614); this.pictureBox.TabIndex = 0; this.pictureBox.TabStop = false; // // FormMapWithSetPlanes // - this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(914, 600); + this.ClientSize = new System.Drawing.Size(857, 614); this.Controls.Add(this.pictureBox); this.Controls.Add(this.groupBox1); - this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.Name = "FormMapWithSetPlanes"; - this.Text = "FormMapWithSetPlanes"; + this.Text = "Карта с набором объектов"; this.Click += new System.EventHandler(this.ButtonMove_Click); this.groupBox1.ResumeLayout(false); this.groupBox1.PerformLayout(); + this.groupBoxMaps.ResumeLayout(false); + this.groupBoxMaps.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit(); this.ResumeLayout(false); @@ -222,5 +264,10 @@ private Button buttonAddPlane; private ComboBox comboBoxSelectorMap; private PictureBox pictureBox; + private GroupBox groupBoxMaps; + private Button buttonDeleteMap; + private ListBox listBoxMaps; + private Button buttonAddMap; + private TextBox textBoxNewMapName; } } \ No newline at end of file diff --git a/Airbus/Airbus/FormMapWithSetPlanes.cs b/Airbus/Airbus/FormMapWithSetPlanes.cs index d750449..b09e3ed 100644 --- a/Airbus/Airbus/FormMapWithSetPlanes.cs +++ b/Airbus/Airbus/FormMapWithSetPlanes.cs @@ -14,42 +14,94 @@ namespace Airbus public partial class FormMapWithSetPlanes : Form { /// - /// Объект от класса карты с набором объектов + /// Словарь для выпадающего списка /// - private MapWithSetPlanesGeneric _mapPlanesCollectionGeneric; + private readonly Dictionary _mapsDict = new() + { + { "Простая карта", new SimpleMap() } + }; + /// + /// Объект от коллекции карт + /// + private readonly MapsCollection _mapsCollection; /// /// Конструктор /// public FormMapWithSetPlanes() { InitializeComponent(); + _mapsCollection = new MapsCollection(pictureBox.Width, pictureBox.Height); + comboBoxSelectorMap.Items.Clear(); + foreach (var elem in _mapsDict) + { + comboBoxSelectorMap.Items.Add(elem.Key); + } + } + /// + /// Заполнение listBoxMaps + /// + private void ReloadMaps() + { + int index = listBoxMaps.SelectedIndex; + listBoxMaps.Items.Clear(); + for (int i = 0; i < _mapsCollection.Keys.Count; i++) + { + listBoxMaps.Items.Add(_mapsCollection.Keys[i]); + } + if (listBoxMaps.Items.Count > 0 && (index == -1 || index >= listBoxMaps.Items.Count)) + { + listBoxMaps.SelectedIndex = 0; + } + else if (listBoxMaps.Items.Count > 0 && index > -1 && index < listBoxMaps.Items.Count) + { + listBoxMaps.SelectedIndex = index; + } + } + /// + /// Добавление карты + /// + /// + /// + private void ButtonAddMap_Click(object sender, EventArgs e) + { + if (comboBoxSelectorMap.SelectedIndex == -1 || string.IsNullOrEmpty(textBoxNewMapName.Text)) + { + MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (!_mapsDict.ContainsKey(comboBoxSelectorMap.Text)) + { + MessageBox.Show("Нет такой карты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _mapsCollection.AddMap(textBoxNewMapName.Text, + _mapsDict[comboBoxSelectorMap.Text]); + ReloadMaps(); } /// /// Выбор карты /// /// /// - private void comboBoxSelectorMap_SelectedIndexChanged_1(object sender, EventArgs e) + private void listBoxMaps_SelectedIndexChanged_1(object sender, EventArgs e) { - AbstractMap map = null; - switch (comboBoxSelectorMap.Text) + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); + } + /// + /// Удаление карты + /// + /// + /// + private void ButtonDeleteMap_Click(object sender, EventArgs e) + { + if (listBoxMaps.SelectedIndex == -1) { - case "Простая карта": - map = new SimpleMap(); - break; - case "Вторая карта": - map = new MyMap(); - break; - + return; } - if (map != null) + if (MessageBox.Show($"Удалить карту {listBoxMaps.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { - _mapPlanesCollectionGeneric = new - MapWithSetPlanesGeneric(pictureBox.Width, pictureBox.Height, map); - } - else - { - _mapPlanesCollectionGeneric = null; + _mapsCollection.DelMap(listBoxMaps.SelectedItem?.ToString() ?? string.Empty); + ReloadMaps(); } } /// @@ -59,7 +111,7 @@ namespace Airbus /// private void buttonAddPlane_Click_1(object sender, EventArgs e) { - if (_mapPlanesCollectionGeneric == null) + if (listBoxMaps.SelectedIndex == -1) { return; } @@ -67,10 +119,11 @@ namespace Airbus if (form.ShowDialog() == DialogResult.OK) { DrawningObjectPlane plane = new(form.SelectedPlane); - if (_mapPlanesCollectionGeneric + plane != -1) + if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + plane >= 0) { MessageBox.Show("Объект добавлен"); - pictureBox.Image = _mapPlanesCollectionGeneric.ShowSet(); + pictureBox.Image = + _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); } else { @@ -85,19 +138,25 @@ namespace Airbus /// private void buttonRemovePlane_Click_1(object sender, EventArgs e) { + if (listBoxMaps.SelectedIndex == -1) + { + return; + } if (string.IsNullOrEmpty(maskedTextBoxPosition.Text)) { return; } - if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) + if (MessageBox.Show("Удалить объект?", "Удаление", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } int pos = Convert.ToInt32(maskedTextBoxPosition.Text); - if (_mapPlanesCollectionGeneric - pos != null) + if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null) { MessageBox.Show("Объект удален"); - pictureBox.Image = _mapPlanesCollectionGeneric.ShowSet(); + pictureBox.Image = + _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); } else { @@ -111,11 +170,12 @@ namespace Airbus /// private void buttonShowStorage_Click_1(object sender, EventArgs e) { - if (_mapPlanesCollectionGeneric == null) + if (listBoxMaps.SelectedIndex == -1) { return; } - pictureBox.Image = _mapPlanesCollectionGeneric.ShowSet(); + pictureBox.Image = + _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); } /// /// Вывод карты @@ -124,11 +184,12 @@ namespace Airbus /// private void buttonShowOnMap_Click_1(object sender, EventArgs e) { - if (_mapPlanesCollectionGeneric == null) + if (listBoxMaps.SelectedIndex == -1) { return; } - pictureBox.Image = _mapPlanesCollectionGeneric.ShowOnMap(); + pictureBox.Image = + _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowOnMap(); } /// /// Перемещение @@ -137,7 +198,7 @@ namespace Airbus /// private void ButtonMove_Click(object sender, EventArgs e) { - if (_mapPlanesCollectionGeneric == null) + if (listBoxMaps.SelectedIndex == -1) { return; } @@ -159,9 +220,9 @@ namespace Airbus dir = Direction.Right; break; } - pictureBox.Image = _mapPlanesCollectionGeneric.MoveObject(dir); + pictureBox.Image = + _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? + string.Empty].MoveObject(dir); } - - } } -- 2.25.1 From 75a36c4019f947c1b9e30f4c7067d51186727947 Mon Sep 17 00:00:00 2001 From: ArtemEmelyanov Date: Sat, 29 Oct 2022 15:28:55 +0400 Subject: [PATCH 4/5] =?UTF-8?q?=D0=92=D1=80=D0=BE=D0=B4=D0=B5=20=D0=BA?= =?UTF-8?q?=D0=B0=D0=BA=20=D0=B4=D0=BE=D0=B4=D0=B5=D0=BB=D0=B0=D0=BD=D0=BD?= =?UTF-8?q?=D0=B0=D1=8F=20=D0=BB=D0=B0=D0=B1=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Airbus/FormMapWithSetPlanes.Designer.cs | 2 ++ Airbus/Airbus/FormMapWithSetPlanes.cs | 18 +++++------ Airbus/Airbus/MapWithSetPlanesGeneric.cs | 5 ++++ Airbus/Airbus/MapsCollection.cs | 10 +++++++ Airbus/Airbus/SetPlanesGeneric.cs | 30 +++++++++++++++---- 5 files changed, 51 insertions(+), 14 deletions(-) diff --git a/Airbus/Airbus/FormMapWithSetPlanes.Designer.cs b/Airbus/Airbus/FormMapWithSetPlanes.Designer.cs index 94089fb..1ed23c2 100644 --- a/Airbus/Airbus/FormMapWithSetPlanes.Designer.cs +++ b/Airbus/Airbus/FormMapWithSetPlanes.Designer.cs @@ -92,6 +92,7 @@ this.buttonDeleteMap.TabIndex = 4; this.buttonDeleteMap.Text = "Удалить карту"; this.buttonDeleteMap.UseVisualStyleBackColor = true; + this.buttonDeleteMap.Click += new System.EventHandler(this.buttonDeleteMap_Click_1); // // listBoxMaps // @@ -111,6 +112,7 @@ this.buttonAddMap.TabIndex = 2; this.buttonAddMap.Text = "Добавить карту"; this.buttonAddMap.UseVisualStyleBackColor = true; + this.buttonAddMap.Click += new System.EventHandler(this.buttonAddMap_Click_1); // // textBoxNewMapName // diff --git a/Airbus/Airbus/FormMapWithSetPlanes.cs b/Airbus/Airbus/FormMapWithSetPlanes.cs index b09e3ed..e80b800 100644 --- a/Airbus/Airbus/FormMapWithSetPlanes.cs +++ b/Airbus/Airbus/FormMapWithSetPlanes.cs @@ -18,7 +18,8 @@ namespace Airbus /// private readonly Dictionary _mapsDict = new() { - { "Простая карта", new SimpleMap() } + { "Простая карта", new SimpleMap() }, + { "Вторая карта", new MyMap() } }; /// /// Объект от коллекции карт @@ -62,7 +63,7 @@ namespace Airbus /// /// /// - private void ButtonAddMap_Click(object sender, EventArgs e) + private void buttonAddMap_Click_1(object sender, EventArgs e) { if (comboBoxSelectorMap.SelectedIndex == -1 || string.IsNullOrEmpty(textBoxNewMapName.Text)) { @@ -92,7 +93,7 @@ namespace Airbus /// /// /// - private void ButtonDeleteMap_Click(object sender, EventArgs e) + private void buttonDeleteMap_Click_1(object sender, EventArgs e) { if (listBoxMaps.SelectedIndex == -1) { @@ -122,8 +123,7 @@ namespace Airbus if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + plane >= 0) { MessageBox.Show("Объект добавлен"); - pictureBox.Image = - _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); } else { @@ -146,8 +146,7 @@ namespace Airbus { return; } - if (MessageBox.Show("Удалить объект?", "Удаление", - MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) + if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } @@ -155,8 +154,7 @@ namespace Airbus if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null) { MessageBox.Show("Объект удален"); - pictureBox.Image = - _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); } else { @@ -224,5 +222,7 @@ namespace Airbus _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].MoveObject(dir); } + + } } diff --git a/Airbus/Airbus/MapWithSetPlanesGeneric.cs b/Airbus/Airbus/MapWithSetPlanesGeneric.cs index 62b18f1..99bd5ac 100644 --- a/Airbus/Airbus/MapWithSetPlanesGeneric.cs +++ b/Airbus/Airbus/MapWithSetPlanesGeneric.cs @@ -178,10 +178,15 @@ namespace Airbus /// private void DrawPlanes(Graphics g) { + int width = _pictureWidth / _placeSizeWidth; + int height = _pictureHeight / _placeSizeHeight; + int i = 0; foreach (var plane in _setPlanes.GetPlanes()) { // TODO установка позиции + plane.SetObject((width - i % width - 1) * _placeSizeWidth, (height - i / width - 1) * _placeSizeHeight, _pictureWidth, _pictureHeight); plane.DrawningObject(g); + i++; } } diff --git a/Airbus/Airbus/MapsCollection.cs b/Airbus/Airbus/MapsCollection.cs index b86efbe..10b6827 100644 --- a/Airbus/Airbus/MapsCollection.cs +++ b/Airbus/Airbus/MapsCollection.cs @@ -43,6 +43,11 @@ namespace Airbus public void AddMap(string name, AbstractMap map) { // TODO Прописать логику для добавления + if (_mapStorages.ContainsKey(name)) + { + return; + } + _mapStorages.Add(name, new MapWithSetPlanesGeneric(_pictureWidth, _pictureHeight, map)); } /// /// Удаление карты @@ -51,6 +56,7 @@ namespace Airbus public void DelMap(string name) { // TODO Прописать логику для удаления + _mapStorages.Remove(name); } /// /// Доступ к парковке @@ -62,6 +68,10 @@ namespace Airbus get { // TODO Продумать логику получения объекта + if (_mapStorages.ContainsKey(ind)) + { + return _mapStorages[ind]; + } return null; } } diff --git a/Airbus/Airbus/SetPlanesGeneric.cs b/Airbus/Airbus/SetPlanesGeneric.cs index 121aeea..f1a02ba 100644 --- a/Airbus/Airbus/SetPlanesGeneric.cs +++ b/Airbus/Airbus/SetPlanesGeneric.cs @@ -36,7 +36,10 @@ namespace Airbus { // TODO вставка в начало набора // TODO проверка на _maxCount - return -1; + if (_places.Count + 1 >= _maxCount) + return -1; + _places.Insert(0, plane); + return 0; } /// /// Добавление объекта в набор на конкретную позицию @@ -48,8 +51,14 @@ namespace Airbus { // TODO проверка позиции // TODO вставка по позиции - _places[position] = plane; - return -1; + if (position >= _maxCount || position < 0) + { + return -1; + } + if (_places.Count + 1 >= _maxCount) + return -1; + _places.Insert(position, plane); + return position; } /// /// Удаление объекта из набора с конкретной позиции @@ -60,9 +69,12 @@ namespace Airbus { // TODO проверка позиции // TODO удаление объекта из массива, присовив элементу массива значение null - if (position < 0 || position >= Count || _places[position] == null) return null; + if (position >= _maxCount || position < 0) + { + return null; + } T DeletePlane = _places[position]; - _places[position] = null; + _places.RemoveAt(position); return DeletePlane; } /// @@ -75,12 +87,20 @@ namespace Airbus get { // TODO проверка позиции + if (position < 0 || position >= _maxCount) + { + return null; + } return _places[position]; } set { // TODO проверка позиции // TODO вставка в список по позиции + if (position < 0 || position >= _maxCount) + { + Insert(value, position); + } } } /// -- 2.25.1 From 080173f97f3f6c7b3c8177fdd0f2d3a96bc800bb Mon Sep 17 00:00:00 2001 From: ArtemEmelyanov Date: Fri, 4 Nov 2022 17:53:34 +0400 Subject: [PATCH 5/5] =?UTF-8?q?=D0=A1=D0=B4=D0=B0=D0=BD=D0=BD=D0=B0=D1=8F?= =?UTF-8?q?=20=D0=BB=D0=B0=D0=B1=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Airbus/Airbus/FormMapWithSetPlanes.cs | 2 -- Airbus/Airbus/MapsCollection.cs | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/Airbus/Airbus/FormMapWithSetPlanes.cs b/Airbus/Airbus/FormMapWithSetPlanes.cs index e80b800..2404f83 100644 --- a/Airbus/Airbus/FormMapWithSetPlanes.cs +++ b/Airbus/Airbus/FormMapWithSetPlanes.cs @@ -222,7 +222,5 @@ namespace Airbus _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].MoveObject(dir); } - - } } diff --git a/Airbus/Airbus/MapsCollection.cs b/Airbus/Airbus/MapsCollection.cs index 10b6827..34a6b36 100644 --- a/Airbus/Airbus/MapsCollection.cs +++ b/Airbus/Airbus/MapsCollection.cs @@ -74,6 +74,6 @@ namespace Airbus } return null; } - } + } } } -- 2.25.1