From b091beba51df16f0c9ab375b852738d0bbd45059 Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Tue, 11 Oct 2022 10:15:58 +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=BE=D0=BA.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Airbus/Airbus/MapWithSetPlanesGeneric.cs | 26 +++++----- Airbus/Airbus/SetPlanesGeneric.cs | 61 ++++++++++++++++++------ 2 files changed, 60 insertions(+), 27 deletions(-) diff --git a/Airbus/Airbus/MapWithSetPlanesGeneric.cs b/Airbus/Airbus/MapWithSetPlanesGeneric.cs index 9b3ea1f..deb007c 100644 --- a/Airbus/Airbus/MapWithSetPlanesGeneric.cs +++ b/Airbus/Airbus/MapWithSetPlanesGeneric.cs @@ -69,14 +69,9 @@ namespace Airbus { Shaking(); - for(int i = 0; i < _setPlanes.Count; i++) + foreach(var plane in _setPlanes.GetAirbus()) { - var plane = _setPlanes.Get(i); - - if(plane != null) - { - return _map.CreateMap(_pictureWidth, _pictureHeight, plane); - } + return _map.CreateMap(_pictureWidth, _pictureHeight, plane); } return new(_pictureWidth, _pictureHeight); @@ -100,11 +95,11 @@ namespace Airbus 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) { @@ -186,13 +181,20 @@ namespace Airbus public void DrawPlanes(Graphics g) { int position = 0; + int index = 0; int currentWidth = 1; int currentHeight = 5; - for (int i = 0; i < _setPlanes.Count; i++) + // for (int i = 0; i < _setPlanes.Count; i++) + + //_setPlanes[index]?.SetObject(currentWidth * _placeSizeWidth + 20, currentHeight * _placeSizeHeight + 20, _pictureWidth, _pictureHeight); + //_setPlanes[index]?.DrawningObject(g); + + foreach (var plane in _setPlanes.GetAirbus()) { - _setPlanes.Get(i)?.SetObject(currentWidth * _placeSizeWidth + 20, currentHeight * _placeSizeHeight + 20, _pictureWidth, _pictureHeight); - _setPlanes.Get(i)?.DrawningObject(g); + plane.SetObject(currentWidth * _placeSizeWidth + 20, currentHeight * _placeSizeHeight + 20, _pictureWidth, _pictureHeight); + plane.DrawningObject(g); + index++; if(position % 2 == 0) { diff --git a/Airbus/Airbus/SetPlanesGeneric.cs b/Airbus/Airbus/SetPlanesGeneric.cs index 9c9a974..f6a01be 100644 --- a/Airbus/Airbus/SetPlanesGeneric.cs +++ b/Airbus/Airbus/SetPlanesGeneric.cs @@ -9,21 +9,28 @@ namespace Airbus internal class SetPlanesGeneric 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) { + //вставка в начало набора + //проверка на максим. кол-во//////////////////////////////////////////////////////////// + return Insert(plane, 0); } @@ -31,7 +38,7 @@ namespace Airbus public int Insert(T plane, int position) { // проверка позиции - if (position >= _places.Length || position < 0) + if (position >= _places.Count || position < 0) { return -1; } @@ -76,7 +83,7 @@ namespace Airbus public T Remove(int position) { // проверка позиции - if (position >= _places.Length || position < 0) + if (position >= _places.Count || position < 0) { return null; } @@ -89,18 +96,42 @@ namespace Airbus } //получение объекта из набора по позиции - public T Get(int position) + public T this[int position] { - if (position >= _places.Length || position < 0) + get { - return null; - } - else if (_places[position] == null) - { - return null; - } + if (position >= _places.Count || position < 0) + { + return null; + } + else if (_places[position] == null) + { + return null; + } - return _places[position]; + return _places[position]; + } + set + { + //TODO проверка позиции + //TODO вставка в список по позиции + } + } + + //проход по набору до первого пустого + public IEnumerable GetAirbus() + { + foreach(var plane in _places) + { + if(plane != null) + { + yield return plane; + } + else + { + yield break; + } + } } } } -- 2.25.1 From 14d9a9c2ff9adf7b752439f6a232151ea0de807e Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Tue, 11 Oct 2022 10:26:25 +0400 Subject: [PATCH 2/5] =?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 --- Airbus/Airbus/MapsCollection.cs | 54 +++++++++++++++++++++++++++++++++ 1 file changed, 54 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..7b3899b --- /dev/null +++ b/Airbus/Airbus/MapsCollection.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Airbus +{ + //класс для хранения коллекции карт + internal class MapsCollection + { + //словарь (хранилище) с картами + readonly Dictionary> _mapStorage; + + //возвращение списка названий карт + public List Keys => _mapStorage.Keys.ToList(); + + //ширина окна отрисовки + private readonly int _pictureWidth; + + //высота окна отрисовки + private readonly int _pictureHeight; + + //конструктор + public MapsCollection(int pictureWidth, int pictureHeight) + { + _mapStorage = new Dictionary> ; + _pictureWidth = pictureWidth; + _pictureHeight = pictureHeight; + } + + //добавление карты + public void AddMap(string name, AbstractMap map) + { + //ТОDO прописать логику для добавления + } + + //удаление карты + public void DelMap(string name) + { + //ТОDO прописать логику для удаления + } + + //Доступ к аэродрому + public MapWithSetPlanesGeneric this[string ind] + { + get + { + //TODO продумать логику получения объекта + return null; + } + } + } +} -- 2.25.1 From 658b34011d5f5aff7a0d08ebec4900b7cb75c1fc Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Tue, 11 Oct 2022 11:25:31 +0400 Subject: [PATCH 3/5] =?UTF-8?q?=D0=98=D1=82=D0=BE=D0=B3=D0=BE=D0=B2=D0=B0?= =?UTF-8?q?=D1=8F=20=D0=B4=D0=BE=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=BA=D0=B0?= =?UTF-8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Airbus/FormMapWithSetPlanes.Designer.cs | 123 ++++++++++++++---- Airbus/Airbus/FormMapWithSetPlanes.cs | 116 ++++++++++++----- Airbus/Airbus/MapWithSetPlanesGeneric.cs | 26 ++-- Airbus/Airbus/MapsCollection.cs | 30 ++++- Airbus/Airbus/SetPlanesGeneric.cs | 68 +++------- 5 files changed, 240 insertions(+), 123 deletions(-) diff --git a/Airbus/Airbus/FormMapWithSetPlanes.Designer.cs b/Airbus/Airbus/FormMapWithSetPlanes.Designer.cs index cd80382..ac26e14 100644 --- a/Airbus/Airbus/FormMapWithSetPlanes.Designer.cs +++ b/Airbus/Airbus/FormMapWithSetPlanes.Designer.cs @@ -29,6 +29,12 @@ private void InitializeComponent() { this.groupBoxTools = 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.comboBoxSelectorMap = new System.Windows.Forms.ComboBox(); + this.textBoxNewMapName = new System.Windows.Forms.TextBox(); 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.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.groupBoxTools.SuspendLayout(); + this.groupBoxMaps.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit(); this.SuspendLayout(); // // groupBoxTools // + this.groupBoxTools.Controls.Add(this.groupBoxMaps); this.groupBoxTools.Controls.Add(this.buttonRight); this.groupBoxTools.Controls.Add(this.buttonDown); this.groupBoxTools.Controls.Add(this.buttonLeft); @@ -55,20 +62,83 @@ this.groupBoxTools.Controls.Add(this.buttonRemovePlane); this.groupBoxTools.Controls.Add(this.maskedTextBoxPosition); this.groupBoxTools.Controls.Add(this.buttonAddPlane); - this.groupBoxTools.Controls.Add(this.comboBoxSelectorMap); this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right; - this.groupBoxTools.Location = new System.Drawing.Point(729, 0); + this.groupBoxTools.Location = new System.Drawing.Point(843, 0); this.groupBoxTools.Name = "groupBoxTools"; - this.groupBoxTools.Size = new System.Drawing.Size(250, 549); + this.groupBoxTools.Size = new System.Drawing.Size(250, 722); this.groupBoxTools.TabIndex = 0; this.groupBoxTools.TabStop = false; this.groupBoxTools.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.comboBoxSelectorMap); + this.groupBoxMaps.Controls.Add(this.textBoxNewMapName); + this.groupBoxMaps.Location = new System.Drawing.Point(12, 26); + this.groupBoxMaps.Name = "groupBoxMaps"; + this.groupBoxMaps.Size = new System.Drawing.Size(232, 335); + this.groupBoxMaps.TabIndex = 10; + this.groupBoxMaps.TabStop = false; + this.groupBoxMaps.Text = "Карты"; + // + // buttonDeleteMap + // + this.buttonDeleteMap.Location = new System.Drawing.Point(8, 278); + this.buttonDeleteMap.Name = "buttonDeleteMap"; + this.buttonDeleteMap.Size = new System.Drawing.Size(218, 29); + this.buttonDeleteMap.TabIndex = 3; + this.buttonDeleteMap.Text = "Удалить карту"; + this.buttonDeleteMap.UseVisualStyleBackColor = true; + this.buttonDeleteMap.Click += new System.EventHandler(this.buttonDeleteMap_Click); + // + // listBoxMaps + // + this.listBoxMaps.FormattingEnabled = true; + this.listBoxMaps.ItemHeight = 20; + this.listBoxMaps.Location = new System.Drawing.Point(8, 128); + this.listBoxMaps.Name = "listBoxMaps"; + this.listBoxMaps.Size = new System.Drawing.Size(218, 144); + this.listBoxMaps.TabIndex = 2; + this.listBoxMaps.SelectedIndexChanged += new System.EventHandler(this.ListBoxMaps_SelectedIndexChanged); + // + // buttonAddMap + // + this.buttonAddMap.Location = new System.Drawing.Point(8, 93); + this.buttonAddMap.Name = "buttonAddMap"; + this.buttonAddMap.Size = new System.Drawing.Size(218, 29); + this.buttonAddMap.TabIndex = 1; + this.buttonAddMap.Text = "Добавить карту"; + this.buttonAddMap.UseVisualStyleBackColor = true; + this.buttonAddMap.Click += new System.EventHandler(this.ButtonAddMap_Click_1); + // + // comboBoxSelectorMap + // + this.comboBoxSelectorMap.FormattingEnabled = true; + this.comboBoxSelectorMap.Items.AddRange(new object[] { + "Простая карта", + "Буря в пустыне", + "Звёздные войны"}); + this.comboBoxSelectorMap.Location = new System.Drawing.Point(8, 59); + this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; + this.comboBoxSelectorMap.Size = new System.Drawing.Size(218, 28); + this.comboBoxSelectorMap.TabIndex = 0; + // + // textBoxNewMapName + // + this.textBoxNewMapName.Location = new System.Drawing.Point(8, 26); + this.textBoxNewMapName.Name = "textBoxNewMapName"; + this.textBoxNewMapName.Size = new System.Drawing.Size(218, 27); + this.textBoxNewMapName.TabIndex = 0; + // // buttonRight // + this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonRight.BackgroundImage = global::Airbus.Properties.Resources.Right; this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; - this.buttonRight.Location = new System.Drawing.Point(158, 484); + this.buttonRight.Location = new System.Drawing.Point(158, 657); this.buttonRight.Name = "buttonRight"; this.buttonRight.Size = new System.Drawing.Size(45, 45); this.buttonRight.TabIndex = 9; @@ -77,9 +147,10 @@ // // buttonDown // + this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonDown.BackgroundImage = global::Airbus.Properties.Resources.Down; this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; - this.buttonDown.Location = new System.Drawing.Point(107, 484); + this.buttonDown.Location = new System.Drawing.Point(107, 657); this.buttonDown.Name = "buttonDown"; this.buttonDown.Size = new System.Drawing.Size(45, 45); this.buttonDown.TabIndex = 8; @@ -88,9 +159,10 @@ // // buttonLeft // + this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonLeft.BackgroundImage = global::Airbus.Properties.Resources.Left; this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; - this.buttonLeft.Location = new System.Drawing.Point(56, 484); + this.buttonLeft.Location = new System.Drawing.Point(56, 657); this.buttonLeft.Name = "buttonLeft"; this.buttonLeft.Size = new System.Drawing.Size(45, 45); this.buttonLeft.TabIndex = 7; @@ -99,9 +171,10 @@ // // buttonUp // + this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonUp.BackgroundImage = global::Airbus.Properties.Resources.Up; this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; - this.buttonUp.Location = new System.Drawing.Point(107, 433); + this.buttonUp.Location = new System.Drawing.Point(107, 606); this.buttonUp.Name = "buttonUp"; this.buttonUp.Size = new System.Drawing.Size(45, 45); this.buttonUp.TabIndex = 6; @@ -110,7 +183,7 @@ // // buttonShowOnMap // - this.buttonShowOnMap.Location = new System.Drawing.Point(20, 360); + this.buttonShowOnMap.Location = new System.Drawing.Point(20, 553); this.buttonShowOnMap.Name = "buttonShowOnMap"; this.buttonShowOnMap.Size = new System.Drawing.Size(218, 29); this.buttonShowOnMap.TabIndex = 5; @@ -120,7 +193,7 @@ // // buttonShowStorage // - this.buttonShowStorage.Location = new System.Drawing.Point(20, 287); + this.buttonShowStorage.Location = new System.Drawing.Point(20, 500); this.buttonShowStorage.Name = "buttonShowStorage"; this.buttonShowStorage.Size = new System.Drawing.Size(218, 29); this.buttonShowStorage.TabIndex = 4; @@ -130,7 +203,7 @@ // // buttonRemovePlane // - this.buttonRemovePlane.Location = new System.Drawing.Point(20, 211); + this.buttonRemovePlane.Location = new System.Drawing.Point(20, 446); this.buttonRemovePlane.Name = "buttonRemovePlane"; this.buttonRemovePlane.Size = new System.Drawing.Size(218, 29); this.buttonRemovePlane.TabIndex = 3; @@ -140,7 +213,7 @@ // // maskedTextBoxPosition // - this.maskedTextBoxPosition.Location = new System.Drawing.Point(20, 178); + this.maskedTextBoxPosition.Location = new System.Drawing.Point(20, 413); this.maskedTextBoxPosition.Mask = "00"; this.maskedTextBoxPosition.Name = "maskedTextBoxPosition"; this.maskedTextBoxPosition.Size = new System.Drawing.Size(218, 27); @@ -148,7 +221,7 @@ // // buttonAddPlane // - this.buttonAddPlane.Location = new System.Drawing.Point(20, 120); + this.buttonAddPlane.Location = new System.Drawing.Point(20, 378); this.buttonAddPlane.Name = "buttonAddPlane"; this.buttonAddPlane.Size = new System.Drawing.Size(218, 29); this.buttonAddPlane.TabIndex = 1; @@ -156,25 +229,12 @@ this.buttonAddPlane.UseVisualStyleBackColor = true; this.buttonAddPlane.Click += new System.EventHandler(this.ButtonAddPlane_Click); // - // comboBoxSelectorMap - // - this.comboBoxSelectorMap.FormattingEnabled = true; - this.comboBoxSelectorMap.Items.AddRange(new object[] { - "Простая карта", - "Буря в пустыне", - "Звёздные войны"}); - this.comboBoxSelectorMap.Location = new System.Drawing.Point(20, 37); - this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; - this.comboBoxSelectorMap.Size = new System.Drawing.Size(218, 28); - 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(729, 549); + this.pictureBox.Size = new System.Drawing.Size(843, 722); this.pictureBox.TabIndex = 1; this.pictureBox.TabStop = false; // @@ -182,13 +242,15 @@ // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(979, 549); + this.ClientSize = new System.Drawing.Size(1093, 722); this.Controls.Add(this.pictureBox); this.Controls.Add(this.groupBoxTools); this.Name = "FormMapWithSetPlanes"; this.Text = "FormMapWithSetPlanes"; this.groupBoxTools.ResumeLayout(false); this.groupBoxTools.PerformLayout(); + this.groupBoxMaps.ResumeLayout(false); + this.groupBoxMaps.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit(); this.ResumeLayout(false); @@ -208,5 +270,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 826e5a6..386f90f 100644 --- a/Airbus/Airbus/FormMapWithSetPlanes.cs +++ b/Airbus/Airbus/FormMapWithSetPlanes.cs @@ -4,6 +4,7 @@ using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; +using System.Reflection; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; @@ -12,47 +13,100 @@ namespace Airbus { public partial class FormMapWithSetPlanes : Form { - //объект от класса карты с набором объектов - private MapWithSetPlanesGeneric _mapPlanesCollectionGeneric; + //словарь для выпадающего списка + private readonly Dictionary _mapsDict = new() + { + {"Простая карта", new SimpleMap() }, + {"Буря в пустыне", new DesertStormMap() }, + {"Звёздные войны", new StarWarsMap() } + }; + + /*//объект от класса карты с набором объектов + private MapWithSetPlanesGeneric _mapPlanesCollectionGeneric;*/ + + //объект от коллекции карт + private readonly MapsCollection _mapsCollection; public FormMapWithSetPlanes() { InitializeComponent(); + _mapsCollection = new MapsCollection(pictureBox.Width, pictureBox.Height); + comboBoxSelectorMap.Items.Clear(); + foreach (var element in _mapsDict) + { + comboBoxSelectorMap.Items.Add(element.Key); + } } - //выбор карты - private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e) + //заполнение ListBoxMaps + private void ReloadMaps() { - AbstractMap map = null; + int index = listBoxMaps.SelectedIndex; - switch (comboBoxSelectorMap.Text) + listBoxMaps.Items.Clear(); + + for (int i = 0; i < _mapsCollection.Keys.Count; i++) { - case "Простая карта": - map = new SimpleMap(); - break; - case "Буря в пустыне": - map = new DesertStormMap(); - break; - case "Звёздные войны": - map = new StarWarsMap(); - break; + listBoxMaps.Items.Add(_mapsCollection.Keys[i]); } - if(map != null) + if (listBoxMaps.Items.Count > 0 && (index == -1 || index >= listBoxMaps.Items.Count)) { - _mapPlanesCollectionGeneric = new MapWithSetPlanesGeneric( - pictureBox.Width, pictureBox.Height, map); + listBoxMaps.SelectedIndex = 0; } - else + else if (listBoxMaps.Items.Count > 0 && index > -1 && index < listBoxMaps.Items.Count) { - _mapPlanesCollectionGeneric = null; + listBoxMaps.SelectedIndex = index; + } + } + + //добавление карты + private void ButtonAddMap_Click_1(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 ListBoxMaps_SelectedIndexChanged(object sender, EventArgs e) + { + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); + } + + // Удаление карты + private void buttonDeleteMap_Click(object sender, EventArgs e) + { + if (listBoxMaps.SelectedIndex == -1) + { + return; + } + if (MessageBox.Show($"Удалить карту {listBoxMaps.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + _mapsCollection.DelMap(listBoxMaps.SelectedItem?.ToString() ?? string.Empty); + + ReloadMaps(); } } //добавление объекта private void ButtonAddPlane_Click(object sender, EventArgs e) { - if(_mapPlanesCollectionGeneric == null) + if(_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? String.Empty] == null) { return; } @@ -63,10 +117,10 @@ namespace Airbus { DrawningObjectPlane plane = new(form.SelectedPlane); - if(_mapPlanesCollectionGeneric + plane != -1) + if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? String.Empty] + plane != -1) { MessageBox.Show("Объект добавлен"); - pictureBox.Image = _mapPlanesCollectionGeneric.ShowSet(); + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? String.Empty].ShowSet(); } else { @@ -91,10 +145,10 @@ namespace Airbus 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 { @@ -105,29 +159,29 @@ namespace Airbus //вывод набора private void ButtonShowStorage_Click(object sender, EventArgs e) { - if(_mapPlanesCollectionGeneric == null) + if(_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? String.Empty] == null) { return; } - pictureBox.Image = _mapPlanesCollectionGeneric.ShowSet(); + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? String.Empty].ShowSet(); } //вывод карты private void ButtonShowOnMap_Click(object sender, EventArgs e) { - if (_mapPlanesCollectionGeneric == null) + if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? String.Empty] == null) { return; } - pictureBox.Image = _mapPlanesCollectionGeneric.ShowOnMap(); + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? String.Empty].ShowOnMap(); } //перемещение private void ButtonMove_Click(object sender, EventArgs e) { - if(_mapPlanesCollectionGeneric == null) + if(_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? String.Empty] == null) { return; } @@ -152,7 +206,7 @@ namespace Airbus break; } - pictureBox.Image = _mapPlanesCollectionGeneric.MoveObject(dir); + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? String.Empty].MoveObject(dir); } } } diff --git a/Airbus/Airbus/MapWithSetPlanesGeneric.cs b/Airbus/Airbus/MapWithSetPlanesGeneric.cs index deb007c..1aca9f6 100644 --- a/Airbus/Airbus/MapWithSetPlanesGeneric.cs +++ b/Airbus/Airbus/MapWithSetPlanesGeneric.cs @@ -133,29 +133,29 @@ namespace Airbus { for(int j = 2; j < _pictureHeight / _placeSizeHeight + 1; ++j) {//линия разметки места - g.DrawLine(pen, i * _placeSizeWidth + 5, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2 + 5, j * _placeSizeHeight); + g.DrawLine(pen, i * _placeSizeWidth - 20, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2 + 5, j * _placeSizeHeight); } - g.DrawLine(pen, i * _placeSizeWidth + 5, _placeSizeHeight * 2, i * _placeSizeWidth + 5, (_pictureHeight / _placeSizeHeight) * _placeSizeHeight); + g.DrawLine(pen, i * _placeSizeWidth - 20, _placeSizeHeight * 2, i * _placeSizeWidth - 20, (_pictureHeight / _placeSizeHeight) * _placeSizeHeight); } //отрисовка разметки взлётной полосы - g.FillRectangle(marcupBrush, _placeSizeWidth * 2 + 30, 0, 185, _pictureHeight); - g.FillRectangle(asphaltBrush, _placeSizeWidth * 2 + 35, 0, 175, _pictureHeight); - g.DrawLine(marcupPen, _placeSizeWidth * 2 + 210, 0, _placeSizeWidth * 2 + 210, _pictureHeight); - g.DrawLine(marcupPen, _placeSizeWidth * 2 + 35, 0, _placeSizeWidth * 2 + 35, _pictureHeight); - g.DrawLine(marcupPen, _placeSizeWidth * 2 + 215, 0, _placeSizeWidth * 2 + 215, _pictureHeight); - g.DrawLine(marcupPen, _placeSizeWidth * 2 + 30, 0, _placeSizeWidth * 2 + 30, _pictureHeight); + g.FillRectangle(marcupBrush, _placeSizeWidth * 3 + 10, 0, 185, _pictureHeight); + g.FillRectangle(asphaltBrush, _placeSizeWidth * 3 + 15, 0, 175, _pictureHeight); + g.DrawLine(marcupPen, _placeSizeWidth * 3 + 190, 0, _placeSizeWidth * 3 + 190, _pictureHeight); + g.DrawLine(marcupPen, _placeSizeWidth * 3 + 15, 0, _placeSizeWidth * 3 + 15, _pictureHeight); + g.DrawLine(marcupPen, _placeSizeWidth * 3 + 195, 0, _placeSizeWidth * 3 + 195, _pictureHeight); + g.DrawLine(marcupPen, _placeSizeWidth * 3 + 10, 0, _placeSizeWidth * 3 + 10, _pictureHeight); for (int i = 0; i < _pictureHeight / _placeSizeHeight; ++i) { - g.DrawLine(marcupPen, _placeSizeWidth * 2 + 125, 20 + i * _placeSizeHeight, _placeSizeWidth * 2 + 125, (i + 1) * _placeSizeHeight - 20); + g.DrawLine(marcupPen, _placeSizeWidth * 3 + 105, 20 + i * _placeSizeHeight, _placeSizeWidth * 3 + 105, (i + 1) * _placeSizeHeight - 20); } for(int i = 0; i < _pictureHeight / 20; i++) { - g.DrawLine(signalFirePen, _placeSizeWidth * 2 + 15, 20 + i * _placeSizeHeight / 2, _placeSizeWidth * 2 + 15, (i + 1) * _placeSizeHeight / 2 - 20); - g.DrawLine(signalFirePen, _placeSizeWidth * 3 + 20, 20 + i * _placeSizeHeight / 2, _placeSizeWidth * 3 + 20, (i + 1) * _placeSizeHeight / 2 - 20); + g.DrawLine(signalFirePen, _placeSizeWidth * 3 - 5, 20 + i * _placeSizeHeight / 2, _placeSizeWidth * 3 - 5, (i + 1) * _placeSizeHeight / 2 - 20); + g.DrawLine(signalFirePen, _placeSizeWidth * 4, 20 + i * _placeSizeHeight / 2, _placeSizeWidth * 4, (i + 1) * _placeSizeHeight / 2 - 20); } //отрисовка сочков @@ -182,8 +182,8 @@ namespace Airbus { int position = 0; int index = 0; - int currentWidth = 1; - int currentHeight = 5; + int currentWidth = 2; + int currentHeight = 7; // for (int i = 0; i < _setPlanes.Count; i++) diff --git a/Airbus/Airbus/MapsCollection.cs b/Airbus/Airbus/MapsCollection.cs index 7b3899b..9648532 100644 --- a/Airbus/Airbus/MapsCollection.cs +++ b/Airbus/Airbus/MapsCollection.cs @@ -24,7 +24,7 @@ namespace Airbus //конструктор public MapsCollection(int pictureWidth, int pictureHeight) { - _mapStorage = new Dictionary> ; + _mapStorage = new Dictionary>(); _pictureWidth = pictureWidth; _pictureHeight = pictureHeight; } @@ -32,13 +32,31 @@ namespace Airbus //добавление карты public void AddMap(string name, AbstractMap map) { - //ТОDO прописать логику для добавления + if (Keys.Contains(name)) + { + MessageBox.Show("Такая карта уже есть"); + return; + } + else + { + var NewElem = new MapWithSetPlanesGeneric( + _pictureWidth, _pictureHeight, map); + _mapStorage.Add(name, NewElem); + } } //удаление карты public void DelMap(string name) { - //ТОDO прописать логику для удаления + if (Keys.Contains(name)) + { + _mapStorage.Remove(name); + } + else + { + MessageBox.Show("Такой карты нет"); + return; + } } //Доступ к аэродрому @@ -46,7 +64,11 @@ namespace Airbus { get { - //TODO продумать логику получения объекта + if (Keys.Contains(ind)) + { + return _mapStorage[ind]; + } + MessageBox.Show("Такой карты нет"); return null; } } diff --git a/Airbus/Airbus/SetPlanesGeneric.cs b/Airbus/Airbus/SetPlanesGeneric.cs index f6a01be..6a5e700 100644 --- a/Airbus/Airbus/SetPlanesGeneric.cs +++ b/Airbus/Airbus/SetPlanesGeneric.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Reflection.PortableExecutable; using System.Text; using System.Threading.Tasks; @@ -28,53 +29,19 @@ namespace Airbus //добавление объекта в набор public int Insert(T plane) { - //вставка в начало набора - //проверка на максим. кол-во//////////////////////////////////////////////////////////// - - return Insert(plane, 0); + if (Count + 1 <= _maxCount) return Insert(plane, 0); + else return -1; } //добавление объекта в набор на конкретную позицию public int Insert(T plane, int position) { - // проверка позиции - if (position >= _places.Count || position < 0) + if (position >= _maxCount && position < 0) { return -1; } - //проверка, что элемент массива по этой позиции пустой, если нет, то - if (_places[position] == null) - { - _places[position] = plane; - return position; - } - - //проверка, что после вставляемого элемента в массиве есть пустой элемент - int findEmptyPos = -1; - - for (int i = position + 1; i < Count; i++) - { - if (_places[i] == null) - { - findEmptyPos = i; - break; - } - } - - if (findEmptyPos < 0) - { - return -1; - } - - //сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента - for (int i = findEmptyPos; i > position; i--) - { - _places[i] = _places[i - 1]; - } - - // вставка по позиции - _places[position] = plane; + _places.Insert(position, plane); return position; } @@ -82,17 +49,22 @@ namespace Airbus //удаление объекта из набора с конкретной позиции public T Remove(int position) { - // проверка позиции - if (position >= _places.Count || position < 0) + if (position < _maxCount && position >= 0) { + + if (_places.ElementAt(position) != null) + { + T result = _places.ElementAt(position); + + _places.RemoveAt(position); + + return result; + } + return null; } - // удаление объекта из массива, присовив элементу массива значение null - T temp = _places[position]; - _places[position] = null; - - return temp; + return null; } //получение объекта из набора по позиции @@ -113,8 +85,10 @@ namespace Airbus } set { - //TODO проверка позиции - //TODO вставка в список по позиции + if (position < _maxCount && position >= 0) + { + Insert(this[position], position); + } } } -- 2.25.1 From f95c155755f5bd27cd20cbbc83024004849e32f0 Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Tue, 11 Oct 2022 11:26:33 +0400 Subject: [PATCH 4/5] =?UTF-8?q?=D0=A2=D0=BE=D1=87=D0=BD=D0=BE=20=D0=B8?= =?UTF-8?q?=D1=82=D0=BE=D0=B3=D0=BE=D0=B2=D0=B0=D1=8F=20=D0=B4=D0=BE=D1=80?= =?UTF-8?q?=D0=B0=D0=B1=D0=BE=D1=82=D0=BA=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Airbus/Airbus/FormMapWithSetPlanes.cs | 3 --- Airbus/Airbus/MapWithSetPlanesGeneric.cs | 5 ----- Airbus/Airbus/MapsCollection.cs | 1 + 3 files changed, 1 insertion(+), 8 deletions(-) diff --git a/Airbus/Airbus/FormMapWithSetPlanes.cs b/Airbus/Airbus/FormMapWithSetPlanes.cs index 386f90f..b411b67 100644 --- a/Airbus/Airbus/FormMapWithSetPlanes.cs +++ b/Airbus/Airbus/FormMapWithSetPlanes.cs @@ -21,9 +21,6 @@ namespace Airbus {"Звёздные войны", new StarWarsMap() } }; - /*//объект от класса карты с набором объектов - private MapWithSetPlanesGeneric _mapPlanesCollectionGeneric;*/ - //объект от коллекции карт private readonly MapsCollection _mapsCollection; diff --git a/Airbus/Airbus/MapWithSetPlanesGeneric.cs b/Airbus/Airbus/MapWithSetPlanesGeneric.cs index 1aca9f6..85ac38b 100644 --- a/Airbus/Airbus/MapWithSetPlanesGeneric.cs +++ b/Airbus/Airbus/MapWithSetPlanesGeneric.cs @@ -185,11 +185,6 @@ namespace Airbus int currentWidth = 2; int currentHeight = 7; - // for (int i = 0; i < _setPlanes.Count; i++) - - //_setPlanes[index]?.SetObject(currentWidth * _placeSizeWidth + 20, currentHeight * _placeSizeHeight + 20, _pictureWidth, _pictureHeight); - //_setPlanes[index]?.DrawningObject(g); - foreach (var plane in _setPlanes.GetAirbus()) { plane.SetObject(currentWidth * _placeSizeWidth + 20, currentHeight * _placeSizeHeight + 20, _pictureWidth, _pictureHeight); diff --git a/Airbus/Airbus/MapsCollection.cs b/Airbus/Airbus/MapsCollection.cs index 9648532..5ec8352 100644 --- a/Airbus/Airbus/MapsCollection.cs +++ b/Airbus/Airbus/MapsCollection.cs @@ -68,6 +68,7 @@ namespace Airbus { return _mapStorage[ind]; } + MessageBox.Show("Такой карты нет"); return null; } -- 2.25.1 From a4ff15a1136b224c0700f5e263c0f7d7a5d47181 Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Wed, 19 Oct 2022 22:13:36 +0400 Subject: [PATCH 5/5] =?UTF-8?q?=D0=A4=D0=B8=D0=BD=D0=B0=D0=BB=D1=8C=D0=BD?= =?UTF-8?q?=D1=8B=D0=B5=20=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Airbus/Airbus/MapWithSetPlanesGeneric.cs | 17 ++++++------- Airbus/Airbus/MapsCollection.cs | 32 ++++-------------------- Airbus/Airbus/SetPlanesGeneric.cs | 1 + 3 files changed, 13 insertions(+), 37 deletions(-) diff --git a/Airbus/Airbus/MapWithSetPlanesGeneric.cs b/Airbus/Airbus/MapWithSetPlanesGeneric.cs index 85ac38b..4681c30 100644 --- a/Airbus/Airbus/MapWithSetPlanesGeneric.cs +++ b/Airbus/Airbus/MapWithSetPlanesGeneric.cs @@ -127,12 +127,14 @@ namespace Airbus Brush asphaltBrush = new SolidBrush(Color.DarkGray); Brush marcupBrush = new SolidBrush(Color.White); - g.FillRectangle(concreteBrush, 0, 0, _pictureWidth, _pictureHeight); //заливаем область в цвет бетона + //заливаем область в цвет бетона + g.FillRectangle(concreteBrush, 0, 0, _pictureWidth, _pictureHeight); for(int i = 0; i < _pictureWidth / _placeSizeWidth - 1; i++) { - for(int j = 2; j < _pictureHeight / _placeSizeHeight + 1; ++j) - {//линия разметки места + //линия разметки места + for (int j = 2; j < _pictureHeight / _placeSizeHeight + 1; ++j) + { g.DrawLine(pen, i * _placeSizeWidth - 20, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2 + 5, j * _placeSizeHeight); } @@ -180,8 +182,6 @@ namespace Airbus //метод прорисовки объеков public void DrawPlanes(Graphics g) { - int position = 0; - int index = 0; int currentWidth = 2; int currentHeight = 7; @@ -189,17 +189,14 @@ namespace Airbus { plane.SetObject(currentWidth * _placeSizeWidth + 20, currentHeight * _placeSizeHeight + 20, _pictureWidth, _pictureHeight); plane.DrawningObject(g); - index++; - if(position % 2 == 0) + if(currentWidth != 0) { - position++; currentWidth--; } else { - position = 0; - currentWidth = 1; + currentWidth = 2; currentHeight--; } } diff --git a/Airbus/Airbus/MapsCollection.cs b/Airbus/Airbus/MapsCollection.cs index 5ec8352..b432cea 100644 --- a/Airbus/Airbus/MapsCollection.cs +++ b/Airbus/Airbus/MapsCollection.cs @@ -32,31 +32,15 @@ namespace Airbus //добавление карты public void AddMap(string name, AbstractMap map) { - if (Keys.Contains(name)) - { - MessageBox.Show("Такая карта уже есть"); - return; - } - else - { - var NewElem = new MapWithSetPlanesGeneric( - _pictureWidth, _pictureHeight, map); - _mapStorage.Add(name, NewElem); - } + var NewElem = new MapWithSetPlanesGeneric( + _pictureWidth, _pictureHeight, map); + _mapStorage.Add(name, NewElem); } //удаление карты public void DelMap(string name) { - if (Keys.Contains(name)) - { - _mapStorage.Remove(name); - } - else - { - MessageBox.Show("Такой карты нет"); - return; - } + _mapStorage.Remove(name); } //Доступ к аэродрому @@ -64,13 +48,7 @@ namespace Airbus { get { - if (Keys.Contains(ind)) - { - return _mapStorage[ind]; - } - - MessageBox.Show("Такой карты нет"); - return null; + return _mapStorage[ind]; } } } diff --git a/Airbus/Airbus/SetPlanesGeneric.cs b/Airbus/Airbus/SetPlanesGeneric.cs index 6a5e700..aa457ec 100644 --- a/Airbus/Airbus/SetPlanesGeneric.cs +++ b/Airbus/Airbus/SetPlanesGeneric.cs @@ -83,6 +83,7 @@ namespace Airbus return _places[position]; } + set { if (position < _maxCount && position >= 0) -- 2.25.1