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); + } } }