From 3139d13fa46955b94c5b6c21db6ce7b550710b2a Mon Sep 17 00:00:00 2001 From: Anastasia Date: Sun, 13 Nov 2022 16:20:54 +0400 Subject: [PATCH 1/6] =?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=BE=D0=BA.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MapWithSetAirplanesGeneric.cs | 22 ++--- .../AirplaneWithRadar/SetAirplanesGeneric.cs | 92 ++++++++++++------- 2 files changed, 69 insertions(+), 45 deletions(-) diff --git a/AirplaneWithRadar/AirplaneWithRadar/MapWithSetAirplanesGeneric.cs b/AirplaneWithRadar/AirplaneWithRadar/MapWithSetAirplanesGeneric.cs index 31b77aa..70af78c 100644 --- a/AirplaneWithRadar/AirplaneWithRadar/MapWithSetAirplanesGeneric.cs +++ b/AirplaneWithRadar/AirplaneWithRadar/MapWithSetAirplanesGeneric.cs @@ -94,13 +94,9 @@ namespace AirplaneWithRadar public Bitmap ShowOnMap() { Shaking(); - for (int i = 0; i < _setAirplanes.Count; i++) + foreach (var airplane in _setAirplanes.GetAirplanes()) { - var airplane = _setAirplanes.Get(i); - if (airplane != null) - { - return _map.CreateMap(_pictureWidth, _pictureHeight, airplane); - } + return _map.CreateMap(_pictureWidth, _pictureHeight, airplane); } return new(_pictureWidth, _pictureHeight); } @@ -125,11 +121,11 @@ namespace AirplaneWithRadar int j = _setAirplanes.Count - 1; for (int i = 0; i < _setAirplanes.Count; i++) { - if (_setAirplanes.Get(i) == null) + if (_setAirplanes[i] == null) { for (; j > i; j--) { - var airplane = _setAirplanes.Get(j); + var airplane = _setAirplanes[j]; if (airplane != null) { _setAirplanes.Insert(airplane, i); @@ -178,14 +174,12 @@ namespace AirplaneWithRadar /// private void DrawAirplanes(Graphics g) { - int numInRow = _pictureWidth / _placeSizeWidth; - int maxLeft = (numInRow - 1) * _placeSizeWidth; - for (int i = 0; i < _setAirplanes.Count; i++) + foreach (var airplane in _setAirplanes.GetAirplanes()) { - var airplane = _setAirplanes.Get(i); - airplane?.SetObject(maxLeft - i % numInRow * _placeSizeWidth + 5, i / numInRow * _placeSizeHeight + 10, _pictureWidth, _pictureHeight); - airplane?.DrawingObject(g); + // TODO установка позиции + airplane.DrawingObject(g); } } + } } diff --git a/AirplaneWithRadar/AirplaneWithRadar/SetAirplanesGeneric.cs b/AirplaneWithRadar/AirplaneWithRadar/SetAirplanesGeneric.cs index 2a28e06..56ab757 100644 --- a/AirplaneWithRadar/AirplaneWithRadar/SetAirplanesGeneric.cs +++ b/AirplaneWithRadar/AirplaneWithRadar/SetAirplanesGeneric.cs @@ -14,20 +14,25 @@ namespace AirplaneWithRadar 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 SetAirplanesGeneric(int count) { - _places = new T[count]; + _maxCount = count; + _places = new List(); } /// /// Добавление объекта в набор @@ -36,7 +41,13 @@ namespace AirplaneWithRadar /// public int Insert(T airplane) { - return Insert(airplane, 0); + // TODO вставка в начало набора + // TODO проверка на _maxCount + if (Count < _maxCount) + { + return Insert(airplane, 0); + } + return -1; } /// /// Добавление объекта в набор на конкретную позицию @@ -46,21 +57,13 @@ namespace AirplaneWithRadar /// public int Insert(T airplane, int position) { - int positionNullElement = position; - while (Get(positionNullElement) != null) - { - positionNullElement++; - } - if (positionNullElement > Count || positionNullElement < 0) + // TODO проверка позиции + // TODO вставка по позиции + if (position < 0 || position >= _maxCount) { return -1; } - while (positionNullElement != position) - { - _places[positionNullElement] = _places[positionNullElement - 1]; - positionNullElement--; - } - _places[position] = airplane; + _places.Insert(position, airplane); return position; } /// @@ -70,32 +73,59 @@ namespace AirplaneWithRadar /// public T Remove(int position) { - if (position > Count || position < 0) + // TODO проверка позиции + if (position < 0 || position >= Count) { return null; } - else - { - var removedObject = _places[position]; - _places[position] = null; - return removedObject; - } + T airplane = _places[position]; + _places.RemoveAt(position); + return airplane; } /// /// Получение объекта из набора по позиции /// /// /// - public T Get(int position) + public T this[int position] { - if (position > Count || position < 0) - { - return null; - } - else + get { + // TODO проверка позиции + if (position < 0 || position >= Count) + { + return null; + } return _places[position]; } + set + { + // TODO проверка позиции + // TODO вставка в список по позиции + if (position < 0 || position >= _maxCount) + { + return; + } + _places.Add(value); + } + } + /// + /// Проход по набору до первого пустого + /// + /// + public IEnumerable GetAirplanes() + { + foreach (var airplane in _places) + { + if (airplane != null) + { + yield return airplane; + } + else + { + yield break; + } + } } } } -- 2.25.1 From 8aea9040e078ce985c3995cce7ec2c737301b2ac Mon Sep 17 00:00:00 2001 From: Anastasia Date: Sun, 13 Nov 2022 16:32:58 +0400 Subject: [PATCH 2/6] =?UTF-8?q?=D0=AD=D1=82=D0=B0=D0=BF=202.=20=D0=9A?= =?UTF-8?q?=D0=BB=D0=B0=D1=81=D1=81=20MapsCollection.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AirplaneWithRadar/MapsCollection.cs | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 AirplaneWithRadar/AirplaneWithRadar/MapsCollection.cs diff --git a/AirplaneWithRadar/AirplaneWithRadar/MapsCollection.cs b/AirplaneWithRadar/AirplaneWithRadar/MapsCollection.cs new file mode 100644 index 0000000..13d0079 --- /dev/null +++ b/AirplaneWithRadar/AirplaneWithRadar/MapsCollection.cs @@ -0,0 +1,84 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AirplaneWithRadar +{ + /// + /// Класс для хранения коллекции карт + /// + 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 Прописать логику для добавления + if (!Keys.Contains(name)) + { + _mapStorages.Add(name, new MapWithSetAirplanesGeneric(_pictureWidth, _pictureHeight, map)); + } + } + /// + /// Удаление карты + /// + /// Название карты + public void DelMap(string name) + { + // TODO Прописать логику для удаления + if (Keys.Contains(name)) + { + _mapStorages.Remove(name); + } + } + /// + /// Доступ к парковке + /// + /// + /// + public MapWithSetAirplanesGeneric this[string ind] + { + get + { + // TODO Продумать логику получения объекта + if (Keys.Contains(ind)) + { + return _mapStorages[ind]; + } + return null; + } + } + } +} -- 2.25.1 From 75c4394c6fa9405651931b7ea57e3ef258accd49 Mon Sep 17 00:00:00 2001 From: Anastasia Date: Sun, 13 Nov 2022 19:19:33 +0400 Subject: [PATCH 3/6] =?UTF-8?q?=D0=AD=D1=82=D0=B0=D0=BF=203.=20=D0=98?= =?UTF-8?q?=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=84=D0=BE?= =?UTF-8?q?=D1=80=D0=BC=D1=8B.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FormMapWithSetAirplanes.Designer.cs | 119 +++++++++++++---- .../FormMapWithSetAirplanes.cs | 125 +++++++++++++----- .../MapWithSetAirplanesGeneric.cs | 15 ++- 3 files changed, 193 insertions(+), 66 deletions(-) diff --git a/AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplanes.Designer.cs b/AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplanes.Designer.cs index 23df6e0..49520fa 100644 --- a/AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplanes.Designer.cs +++ b/AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplanes.Designer.cs @@ -29,6 +29,12 @@ private void InitializeComponent() { this.groupBox = 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.buttonRight = new System.Windows.Forms.Button(); this.buttonDown = new System.Windows.Forms.Button(); this.buttonLeft = new System.Windows.Forms.Button(); @@ -38,14 +44,15 @@ this.buttonRemoveAirplane = new System.Windows.Forms.Button(); this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox(); this.buttonAddAirplane = new System.Windows.Forms.Button(); - this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox(); this.pictureBox = new System.Windows.Forms.PictureBox(); this.groupBox.SuspendLayout(); + this.groupBoxMaps.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit(); this.SuspendLayout(); // // groupBox // + this.groupBox.Controls.Add(this.groupBoxMaps); this.groupBox.Controls.Add(this.buttonRight); this.groupBox.Controls.Add(this.buttonDown); this.groupBox.Controls.Add(this.buttonLeft); @@ -55,20 +62,82 @@ this.groupBox.Controls.Add(this.buttonRemoveAirplane); this.groupBox.Controls.Add(this.maskedTextBoxPosition); this.groupBox.Controls.Add(this.buttonAddAirplane); - this.groupBox.Controls.Add(this.comboBoxSelectorMap); this.groupBox.Dock = System.Windows.Forms.DockStyle.Right; - this.groupBox.Location = new System.Drawing.Point(723, 0); + this.groupBox.Location = new System.Drawing.Point(896, 0); this.groupBox.Name = "groupBox"; - this.groupBox.Size = new System.Drawing.Size(257, 526); + this.groupBox.Size = new System.Drawing.Size(257, 754); this.groupBox.TabIndex = 0; this.groupBox.TabStop = false; this.groupBox.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, 30); + this.groupBoxMaps.Name = "groupBoxMaps"; + this.groupBoxMaps.Size = new System.Drawing.Size(245, 348); + this.groupBoxMaps.TabIndex = 11; + this.groupBoxMaps.TabStop = false; + this.groupBoxMaps.Text = "Карты"; + // + // buttonDeleteMap + // + this.buttonDeleteMap.Location = new System.Drawing.Point(17, 298); + this.buttonDeleteMap.Name = "buttonDeleteMap"; + this.buttonDeleteMap.Size = new System.Drawing.Size(222, 34); + this.buttonDeleteMap.TabIndex = 4; + this.buttonDeleteMap.Text = "Удалить карту"; + this.buttonDeleteMap.UseVisualStyleBackColor = true; + this.buttonDeleteMap.Click += new System.EventHandler(this.ButtonDeleteMap_Click); + // + // listBoxMaps + // + this.listBoxMaps.FormattingEnabled = true; + this.listBoxMaps.ItemHeight = 25; + this.listBoxMaps.Location = new System.Drawing.Point(17, 156); + this.listBoxMaps.Name = "listBoxMaps"; + this.listBoxMaps.Size = new System.Drawing.Size(222, 129); + this.listBoxMaps.TabIndex = 3; + this.listBoxMaps.SelectedIndexChanged += new System.EventHandler(this.ListBoxMaps_SelectedIndexChanged); + // + // buttonAddMap + // + this.buttonAddMap.Location = new System.Drawing.Point(17, 104); + this.buttonAddMap.Name = "buttonAddMap"; + this.buttonAddMap.Size = new System.Drawing.Size(222, 34); + this.buttonAddMap.TabIndex = 2; + this.buttonAddMap.Text = "Добавить карту"; + this.buttonAddMap.UseVisualStyleBackColor = true; + this.buttonAddMap.Click += new System.EventHandler(this.ButtonAddMap_Click); + // + // textBoxNewMapName + // + this.textBoxNewMapName.Location = new System.Drawing.Point(17, 28); + this.textBoxNewMapName.Name = "textBoxNewMapName"; + this.textBoxNewMapName.Size = new System.Drawing.Size(222, 31); + this.textBoxNewMapName.TabIndex = 1; + // + // comboBoxSelectorMap + // + this.comboBoxSelectorMap.FormattingEnabled = true; + this.comboBoxSelectorMap.Items.AddRange(new object[] { + "Простая карта", + "Карта с линиями", + "Карта с блоками"}); + this.comboBoxSelectorMap.Location = new System.Drawing.Point(17, 65); + this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; + this.comboBoxSelectorMap.Size = new System.Drawing.Size(222, 33); + this.comboBoxSelectorMap.TabIndex = 0; + // // buttonRight // this.buttonRight.BackgroundImage = global::AirplaneWithRadar.Properties.Resources.right; this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonRight.Location = new System.Drawing.Point(160, 433); + this.buttonRight.Location = new System.Drawing.Point(153, 701); this.buttonRight.Name = "buttonRight"; this.buttonRight.Size = new System.Drawing.Size(30, 30); this.buttonRight.TabIndex = 10; @@ -79,7 +148,7 @@ // this.buttonDown.BackgroundImage = global::AirplaneWithRadar.Properties.Resources.down; this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonDown.Location = new System.Drawing.Point(124, 433); + this.buttonDown.Location = new System.Drawing.Point(117, 701); this.buttonDown.Name = "buttonDown"; this.buttonDown.Size = new System.Drawing.Size(30, 30); this.buttonDown.TabIndex = 9; @@ -90,7 +159,7 @@ // this.buttonLeft.BackgroundImage = global::AirplaneWithRadar.Properties.Resources.left; this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonLeft.Location = new System.Drawing.Point(88, 433); + this.buttonLeft.Location = new System.Drawing.Point(81, 701); this.buttonLeft.Name = "buttonLeft"; this.buttonLeft.Size = new System.Drawing.Size(30, 30); this.buttonLeft.TabIndex = 8; @@ -101,7 +170,7 @@ // this.buttonUp.BackgroundImage = global::AirplaneWithRadar.Properties.Resources.up; this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonUp.Location = new System.Drawing.Point(124, 397); + this.buttonUp.Location = new System.Drawing.Point(117, 665); this.buttonUp.Name = "buttonUp"; this.buttonUp.Size = new System.Drawing.Size(30, 30); this.buttonUp.TabIndex = 7; @@ -110,7 +179,7 @@ // // buttonShowOnMap // - this.buttonShowOnMap.Location = new System.Drawing.Point(23, 319); + this.buttonShowOnMap.Location = new System.Drawing.Point(23, 603); this.buttonShowOnMap.Name = "buttonShowOnMap"; this.buttonShowOnMap.Size = new System.Drawing.Size(222, 34); this.buttonShowOnMap.TabIndex = 6; @@ -120,7 +189,7 @@ // // buttonShowStorage // - this.buttonShowStorage.Location = new System.Drawing.Point(23, 251); + this.buttonShowStorage.Location = new System.Drawing.Point(23, 549); this.buttonShowStorage.Name = "buttonShowStorage"; this.buttonShowStorage.Size = new System.Drawing.Size(222, 37); this.buttonShowStorage.TabIndex = 5; @@ -130,7 +199,7 @@ // // buttonRemoveAirplane // - this.buttonRemoveAirplane.Location = new System.Drawing.Point(23, 186); + this.buttonRemoveAirplane.Location = new System.Drawing.Point(23, 497); this.buttonRemoveAirplane.Name = "buttonRemoveAirplane"; this.buttonRemoveAirplane.Size = new System.Drawing.Size(222, 34); this.buttonRemoveAirplane.TabIndex = 4; @@ -140,7 +209,7 @@ // // maskedTextBoxPosition // - this.maskedTextBoxPosition.Location = new System.Drawing.Point(23, 149); + this.maskedTextBoxPosition.Location = new System.Drawing.Point(23, 460); this.maskedTextBoxPosition.Mask = "00"; this.maskedTextBoxPosition.Name = "maskedTextBoxPosition"; this.maskedTextBoxPosition.Size = new System.Drawing.Size(222, 31); @@ -148,7 +217,7 @@ // // buttonAddAirplane // - this.buttonAddAirplane.Location = new System.Drawing.Point(23, 94); + this.buttonAddAirplane.Location = new System.Drawing.Point(23, 406); this.buttonAddAirplane.Name = "buttonAddAirplane"; this.buttonAddAirplane.Size = new System.Drawing.Size(222, 34); this.buttonAddAirplane.TabIndex = 2; @@ -156,25 +225,12 @@ this.buttonAddAirplane.UseVisualStyleBackColor = true; this.buttonAddAirplane.Click += new System.EventHandler(this.ButtonAddAirplane_Click); // - // comboBoxSelectorMap - // - this.comboBoxSelectorMap.FormattingEnabled = true; - this.comboBoxSelectorMap.Items.AddRange(new object[] { - "Простая карта", - "Карта с линиями", - "Карта с блоками"}); - this.comboBoxSelectorMap.Location = new System.Drawing.Point(23, 44); - this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; - this.comboBoxSelectorMap.Size = new System.Drawing.Size(222, 33); - this.comboBoxSelectorMap.TabIndex = 0; - this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged); - // // pictureBox // this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill; this.pictureBox.Location = new System.Drawing.Point(0, 0); this.pictureBox.Name = "pictureBox"; - this.pictureBox.Size = new System.Drawing.Size(723, 526); + this.pictureBox.Size = new System.Drawing.Size(896, 754); this.pictureBox.TabIndex = 1; this.pictureBox.TabStop = false; // @@ -182,13 +238,15 @@ // this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(980, 526); + this.ClientSize = new System.Drawing.Size(1153, 754); this.Controls.Add(this.pictureBox); this.Controls.Add(this.groupBox); this.Name = "FormMapWithSetAirplanes"; this.Text = "FormMapWithSetAirplanes"; this.groupBox.ResumeLayout(false); this.groupBox.PerformLayout(); + this.groupBoxMaps.ResumeLayout(false); + this.groupBoxMaps.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit(); this.ResumeLayout(false); @@ -208,5 +266,10 @@ private Button buttonAddAirplane; 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/AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplanes.cs b/AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplanes.cs index 5c2c226..6dd4f47 100644 --- a/AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplanes.cs +++ b/AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplanes.cs @@ -1,45 +1,99 @@ -namespace AirplaneWithRadar +using static System.Windows.Forms.DataFormats; + +namespace AirplaneWithRadar { public partial class FormMapWithSetAirplanes : Form { /// - /// Объект от класса карты с набором объектов + /// Словарь для выпадающего списка /// - private MapWithSetAirplanesGeneric _mapAirplanesCollectionGeneric; + private readonly Dictionary _mapsDict = new() + { + { "Простая карта", new SimpleMap() }, + { "Карта с блоками", new BlockMap() }, + { "Карта с линиями", new LineMap() } + }; + /// + /// Объект от коллекции карт + /// + private readonly MapsCollection _mapsCollection; /// /// Конструктор /// public FormMapWithSetAirplanes() { 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(object sender, EventArgs e) + private void ListBoxMaps_SelectedIndexChanged(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 LineMap(); - break; - case "Карта с блоками": - map = new BlockMap(); - break; + return; } - if (map != null) + if (MessageBox.Show($"Удалить карту {listBoxMaps.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { - _mapAirplanesCollectionGeneric = new MapWithSetAirplanesGeneric(pictureBox.Width, pictureBox.Height, map); - } - else - { - _mapAirplanesCollectionGeneric = null; + _mapsCollection.DelMap(listBoxMaps.SelectedItem?.ToString() ?? string.Empty); + ReloadMaps(); } } /// @@ -49,7 +103,7 @@ /// private void ButtonAddAirplane_Click(object sender, EventArgs e) { - if (_mapAirplanesCollectionGeneric == null) + if (listBoxMaps.SelectedIndex == -1) { return; } @@ -57,10 +111,10 @@ if (form.ShowDialog() == DialogResult.OK) { DrawingObjectAirplane airplane = new(form.SelectedAirplane); - if (_mapAirplanesCollectionGeneric + airplane != -1) + if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + airplane != -1) { MessageBox.Show("Объект добавлен"); - pictureBox.Image = _mapAirplanesCollectionGeneric.ShowSet(); + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); } else { @@ -75,19 +129,23 @@ /// private void ButtonRemoveAirplane_Click(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 (_mapAirplanesCollectionGeneric - pos != null) + if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null) { MessageBox.Show("Объект удален"); - pictureBox.Image = _mapAirplanesCollectionGeneric.ShowSet(); + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); } else { @@ -101,11 +159,11 @@ /// private void ButtonShowStorage_Click(object sender, EventArgs e) { - if (_mapAirplanesCollectionGeneric == null) + if (listBoxMaps.SelectedIndex == -1) { return; } - pictureBox.Image = _mapAirplanesCollectionGeneric.ShowSet(); + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); } /// /// Вывод карты @@ -114,11 +172,11 @@ /// private void ButtonShowOnMap_Click(object sender, EventArgs e) { - if (_mapAirplanesCollectionGeneric == null) + if (listBoxMaps.SelectedIndex == -1) { return; } - pictureBox.Image = _mapAirplanesCollectionGeneric.ShowOnMap(); + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowOnMap(); } /// /// Перемещение @@ -127,10 +185,11 @@ /// private void ButtonMove_Click(object sender, EventArgs e) { - if (_mapAirplanesCollectionGeneric == null) + if (listBoxMaps.SelectedIndex == -1) { return; } + //получаем имя кнопки string name = ((Button)sender)?.Name ?? string.Empty; Direction dir = Direction.None; switch (name) @@ -148,7 +207,7 @@ dir = Direction.Right; break; } - pictureBox.Image = _mapAirplanesCollectionGeneric.MoveObject(dir); + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].MoveObject(dir); } } } diff --git a/AirplaneWithRadar/AirplaneWithRadar/MapWithSetAirplanesGeneric.cs b/AirplaneWithRadar/AirplaneWithRadar/MapWithSetAirplanesGeneric.cs index 70af78c..82e92ae 100644 --- a/AirplaneWithRadar/AirplaneWithRadar/MapWithSetAirplanesGeneric.cs +++ b/AirplaneWithRadar/AirplaneWithRadar/MapWithSetAirplanesGeneric.cs @@ -163,7 +163,7 @@ namespace AirplaneWithRadar { for (int j = 0; j < _pictureHeight / _placeSizeHeight; j++) { - g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth * 4/5, j * _placeSizeHeight); + g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth * 4 / 5, j * _placeSizeHeight); } g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, (_pictureHeight / _placeSizeHeight) * _placeSizeHeight); } @@ -174,12 +174,17 @@ namespace AirplaneWithRadar /// private void DrawAirplanes(Graphics g) { - foreach (var airplane in _setAirplanes.GetAirplanes()) + // TODO установка позиции + int numObjectsInRow = _pictureWidth / _placeSizeWidth; + int maxLeft = (numObjectsInRow - 1) * _placeSizeWidth; + for (int i = 0; i < _setAirplanes.Count; i++) { - // TODO установка позиции - airplane.DrawingObject(g); + var airplane = _setAirplanes[i]; + airplane?.SetObject(maxLeft - i % numObjectsInRow * _placeSizeWidth + 5, i / numObjectsInRow * _placeSizeHeight + 15, _pictureWidth, _pictureHeight); + airplane?.DrawingObject(g); } } - } + } + -- 2.25.1 From 384dd9b1ff7661af0debc5b438ca6cf2b5e59078 Mon Sep 17 00:00:00 2001 From: Anastasia Date: Tue, 15 Nov 2022 12:47:43 +0400 Subject: [PATCH 4/6] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=D0=B0=20=D0=BF?= =?UTF-8?q?=D1=80=D0=BE=D1=80=D0=B8=D1=81=D0=BE=D0=B2=D0=BA=D0=B8=20=D0=BE?= =?UTF-8?q?=D0=B1=D1=8A=D0=B5=D0=BA=D1=82=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MapWithSetAirplanesGeneric.cs | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/AirplaneWithRadar/AirplaneWithRadar/MapWithSetAirplanesGeneric.cs b/AirplaneWithRadar/AirplaneWithRadar/MapWithSetAirplanesGeneric.cs index 82e92ae..9d064b9 100644 --- a/AirplaneWithRadar/AirplaneWithRadar/MapWithSetAirplanesGeneric.cs +++ b/AirplaneWithRadar/AirplaneWithRadar/MapWithSetAirplanesGeneric.cs @@ -144,17 +144,6 @@ namespace AirplaneWithRadar /// Метод отрисовки фона /// /// - private void DrawHangar(Graphics g, int x, int y, int width, int height) - { - Pen pen = new(Color.Black, 3); - g.DrawLine(pen, x, y, x + width, y); - g.DrawLine(pen, x, y, x, y + height + 20); - g.DrawLine(pen, x, y + height + 20, x + width, y + height + 20); - } - /// - /// Метод отрисовки фона - /// - /// private void DrawBackground(Graphics g) { Pen pen = new(Color.White, 5); @@ -177,11 +166,12 @@ namespace AirplaneWithRadar // TODO установка позиции int numObjectsInRow = _pictureWidth / _placeSizeWidth; int maxLeft = (numObjectsInRow - 1) * _placeSizeWidth; - for (int i = 0; i < _setAirplanes.Count; i++) + int curr = 0; + foreach (var airplane in _setAirplanes.GetAirplanes()) { - var airplane = _setAirplanes[i]; - airplane?.SetObject(maxLeft - i % numObjectsInRow * _placeSizeWidth + 5, i / numObjectsInRow * _placeSizeHeight + 15, _pictureWidth, _pictureHeight); + airplane?.SetObject(maxLeft - curr % numObjectsInRow * _placeSizeWidth + 5, curr / numObjectsInRow * _placeSizeHeight + 15, _pictureWidth, _pictureHeight); airplane?.DrawingObject(g); + curr++; } } } -- 2.25.1 From c1fd43d87663cafd214dddc7ef21a8f00a6fd434 Mon Sep 17 00:00:00 2001 From: Anastasia Date: Sat, 17 Dec 2022 15:36:11 +0400 Subject: [PATCH 5/6] =?UTF-8?q?=D0=93=D0=BE=D1=82=D0=BE=D0=B2=D0=B0=D1=8F?= =?UTF-8?q?=20=D1=87=D0=B5=D1=82=D0=B2=D0=B5=D1=80=D1=82=D0=B0=D1=8F=20?= =?UTF-8?q?=D0=BB=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82=D0=BE=D1=80=D0=BD?= =?UTF-8?q?=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirplaneWithRadar/AirplaneWithRadar/BlockMap.cs | 1 - AirplaneWithRadar/AirplaneWithRadar/DrawingAirplane.cs | 3 +-- .../AirplaneWithRadar/FormAirplaneWithRadar.cs | 6 +++++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/AirplaneWithRadar/AirplaneWithRadar/BlockMap.cs b/AirplaneWithRadar/AirplaneWithRadar/BlockMap.cs index a845946..b601672 100644 --- a/AirplaneWithRadar/AirplaneWithRadar/BlockMap.cs +++ b/AirplaneWithRadar/AirplaneWithRadar/BlockMap.cs @@ -27,7 +27,6 @@ namespace AirplaneWithRadar { g.FillRectangle(roadColor, i * _size_x, j * _size_y, (i + 1) * (_size_x + 1), (j + 1) * (_size_y + 1)); } - protected override void GenerateMap() { _map = new int[100, 100]; diff --git a/AirplaneWithRadar/AirplaneWithRadar/DrawingAirplane.cs b/AirplaneWithRadar/AirplaneWithRadar/DrawingAirplane.cs index c82432b..3f30e8c 100644 --- a/AirplaneWithRadar/AirplaneWithRadar/DrawingAirplane.cs +++ b/AirplaneWithRadar/AirplaneWithRadar/DrawingAirplane.cs @@ -57,8 +57,7 @@ namespace AirplaneWithRadar /// Цвет кузова /// Ширина отрисовки самолета /// Высота отрисовки самолета - protected DrawingAirplane(int speed, float weight, Color bodyColor, int airplaneWidth, int airplaneHeight) : - this(speed, weight, bodyColor) + protected DrawingAirplane(int speed, float weight, Color bodyColor, int airplaneWidth, int airplaneHeight) : this(speed, weight, bodyColor) { _airplaneWidth = airplaneWidth; _airplaneHeight = airplaneHeight; diff --git a/AirplaneWithRadar/AirplaneWithRadar/FormAirplaneWithRadar.cs b/AirplaneWithRadar/AirplaneWithRadar/FormAirplaneWithRadar.cs index 21d57ce..7a8ffa8 100644 --- a/AirplaneWithRadar/AirplaneWithRadar/FormAirplaneWithRadar.cs +++ b/AirplaneWithRadar/AirplaneWithRadar/FormAirplaneWithRadar.cs @@ -48,7 +48,11 @@ namespace AirplaneWithRadar SetData(); Draw(); } - + /// + /// + /// + /// + /// private void ButtonMove_Click(object sender, EventArgs e) { string name = ((Button)sender)?.Name ?? string.Empty; -- 2.25.1 From b1cdcca4f41014389a3ab478ff04d9490703ff8a Mon Sep 17 00:00:00 2001 From: Anastasia Date: Sun, 18 Dec 2022 11:52:17 +0400 Subject: [PATCH 6/6] =?UTF-8?q?=D0=A3=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=BF=D1=83=D1=81=D1=82=D0=BE=D0=B3=D0=BE=20=D0=BA?= =?UTF-8?q?=D0=BB=D0=B0=D1=81=D1=81=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirplaneWithRadar/EntityAirplaneWithRadar.cs | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 AirplaneWithRadar/EntityAirplaneWithRadar.cs diff --git a/AirplaneWithRadar/EntityAirplaneWithRadar.cs b/AirplaneWithRadar/EntityAirplaneWithRadar.cs deleted file mode 100644 index d555ecb..0000000 --- a/AirplaneWithRadar/EntityAirplaneWithRadar.cs +++ /dev/null @@ -1,8 +0,0 @@ -using System; - -public class Class1 -{ - public Class1() - { - } -} -- 2.25.1