diff --git a/AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplanes.Designer.cs b/AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplanes.Designer.cs
index 00a8300..7622575 100644
--- a/AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplanes.Designer.cs
+++ b/AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplanes.Designer.cs
@@ -29,6 +29,11 @@
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.textBoxNewMapName = new System.Windows.Forms.TextBox();
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
this.buttonRight = new System.Windows.Forms.Button();
@@ -41,12 +46,13 @@
this.buttonAddAirplane = new System.Windows.Forms.Button();
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.comboBoxSelectorMap);
+ this.groupBoxTools.Controls.Add(this.groupBoxMaps);
this.groupBoxTools.Controls.Add(this.maskedTextBoxPosition);
this.groupBoxTools.Controls.Add(this.buttonRight);
this.groupBoxTools.Controls.Add(this.buttonLeft);
@@ -57,31 +63,81 @@
this.groupBoxTools.Controls.Add(this.buttonRemoveAirplane);
this.groupBoxTools.Controls.Add(this.buttonAddAirplane);
this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right;
- this.groupBoxTools.Location = new System.Drawing.Point(685, 0);
+ this.groupBoxTools.Location = new System.Drawing.Point(808, 0);
this.groupBoxTools.Name = "groupBoxTools";
- this.groupBoxTools.Size = new System.Drawing.Size(200, 620);
+ this.groupBoxTools.Size = new System.Drawing.Size(200, 604);
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.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, 259);
+ this.groupBoxMaps.TabIndex = 11;
+ this.groupBoxMaps.TabStop = false;
+ this.groupBoxMaps.Text = "Карты";
+ //
+ // buttonDeleteMap
+ //
+ this.buttonDeleteMap.Location = new System.Drawing.Point(7, 221);
+ this.buttonDeleteMap.Name = "buttonDeleteMap";
+ this.buttonDeleteMap.Size = new System.Drawing.Size(176, 31);
+ this.buttonDeleteMap.TabIndex = 13;
+ this.buttonDeleteMap.Text = "Удалить карту";
+ this.buttonDeleteMap.UseVisualStyleBackColor = true;
+ this.buttonDeleteMap.Click += new System.EventHandler(this.ButtonDeleteMap_Click);
+ //
+ // listBoxMaps
+ //
+ this.listBoxMaps.FormattingEnabled = true;
+ this.listBoxMaps.ItemHeight = 15;
+ this.listBoxMaps.Location = new System.Drawing.Point(7, 121);
+ this.listBoxMaps.Name = "listBoxMaps";
+ this.listBoxMaps.Size = new System.Drawing.Size(175, 94);
+ this.listBoxMaps.TabIndex = 12;
+ this.listBoxMaps.SelectedIndexChanged += new System.EventHandler(this.ListBoxMaps_SelectedIndexChanged);
+ //
+ // buttonAddMap
+ //
+ this.buttonAddMap.Location = new System.Drawing.Point(6, 84);
+ this.buttonAddMap.Name = "buttonAddMap";
+ this.buttonAddMap.Size = new System.Drawing.Size(176, 31);
+ this.buttonAddMap.TabIndex = 11;
+ this.buttonAddMap.Text = "Добавить Карту";
+ this.buttonAddMap.UseVisualStyleBackColor = true;
+ this.buttonAddMap.Click += new System.EventHandler(this.ButtonAddMap_Click);
+ //
+ // textBoxNewMapName
+ //
+ this.textBoxNewMapName.Location = new System.Drawing.Point(8, 22);
+ this.textBoxNewMapName.Name = "textBoxNewMapName";
+ this.textBoxNewMapName.Size = new System.Drawing.Size(174, 23);
+ this.textBoxNewMapName.TabIndex = 0;
+ //
// comboBoxSelectorMap
//
this.comboBoxSelectorMap.FormattingEnabled = true;
this.comboBoxSelectorMap.Items.AddRange(new object[] {
"Простая карта",
"Моя карта"});
- this.comboBoxSelectorMap.Location = new System.Drawing.Point(6, 46);
+ this.comboBoxSelectorMap.Location = new System.Drawing.Point(8, 51);
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
- this.comboBoxSelectorMap.Size = new System.Drawing.Size(163, 23);
+ this.comboBoxSelectorMap.Size = new System.Drawing.Size(174, 23);
this.comboBoxSelectorMap.TabIndex = 10;
- this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);
//
// maskedTextBoxPosition
//
- this.maskedTextBoxPosition.Location = new System.Drawing.Point(6, 169);
+ this.maskedTextBoxPosition.Location = new System.Drawing.Point(14, 337);
this.maskedTextBoxPosition.Mask = "00";
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
- this.maskedTextBoxPosition.Size = new System.Drawing.Size(163, 23);
+ this.maskedTextBoxPosition.Size = new System.Drawing.Size(174, 23);
this.maskedTextBoxPosition.TabIndex = 9;
//
// buttonRight
@@ -89,7 +145,7 @@
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonRight.BackgroundImage = global::AirplaneWithRadar.Properties.Resources.arrRight;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
- this.buttonRight.Location = new System.Drawing.Point(119, 574);
+ this.buttonRight.Location = new System.Drawing.Point(119, 558);
this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(30, 30);
this.buttonRight.TabIndex = 8;
@@ -101,7 +157,7 @@
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonLeft.BackgroundImage = global::AirplaneWithRadar.Properties.Resources.arrLeft;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
- this.buttonLeft.Location = new System.Drawing.Point(47, 574);
+ this.buttonLeft.Location = new System.Drawing.Point(47, 558);
this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
this.buttonLeft.TabIndex = 7;
@@ -113,7 +169,7 @@
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonDown.BackgroundImage = global::AirplaneWithRadar.Properties.Resources.arrDown;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
- this.buttonDown.Location = new System.Drawing.Point(83, 574);
+ this.buttonDown.Location = new System.Drawing.Point(83, 558);
this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(30, 30);
this.buttonDown.TabIndex = 6;
@@ -125,7 +181,7 @@
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonUp.BackgroundImage = global::AirplaneWithRadar.Properties.Resources.arrUp;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
- this.buttonUp.Location = new System.Drawing.Point(83, 538);
+ this.buttonUp.Location = new System.Drawing.Point(83, 522);
this.buttonUp.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(30, 30);
this.buttonUp.TabIndex = 5;
@@ -134,9 +190,9 @@
//
// buttonShowOnMap
//
- this.buttonShowOnMap.Location = new System.Drawing.Point(6, 301);
+ this.buttonShowOnMap.Location = new System.Drawing.Point(14, 440);
this.buttonShowOnMap.Name = "buttonShowOnMap";
- this.buttonShowOnMap.Size = new System.Drawing.Size(164, 34);
+ this.buttonShowOnMap.Size = new System.Drawing.Size(174, 34);
this.buttonShowOnMap.TabIndex = 4;
this.buttonShowOnMap.Text = "Посмотреть карту";
this.buttonShowOnMap.UseVisualStyleBackColor = true;
@@ -144,9 +200,9 @@
//
// buttonShowStorage
//
- this.buttonShowStorage.Location = new System.Drawing.Point(6, 257);
+ this.buttonShowStorage.Location = new System.Drawing.Point(14, 402);
this.buttonShowStorage.Name = "buttonShowStorage";
- this.buttonShowStorage.Size = new System.Drawing.Size(163, 38);
+ this.buttonShowStorage.Size = new System.Drawing.Size(174, 32);
this.buttonShowStorage.TabIndex = 3;
this.buttonShowStorage.Text = "Посмотреть хранилище";
this.buttonShowStorage.UseVisualStyleBackColor = true;
@@ -154,9 +210,9 @@
//
// buttonRemoveAirplane
//
- this.buttonRemoveAirplane.Location = new System.Drawing.Point(6, 221);
+ this.buttonRemoveAirplane.Location = new System.Drawing.Point(14, 366);
this.buttonRemoveAirplane.Name = "buttonRemoveAirplane";
- this.buttonRemoveAirplane.Size = new System.Drawing.Size(164, 30);
+ this.buttonRemoveAirplane.Size = new System.Drawing.Size(174, 30);
this.buttonRemoveAirplane.TabIndex = 2;
this.buttonRemoveAirplane.Text = "Удалить самолёт";
this.buttonRemoveAirplane.UseVisualStyleBackColor = true;
@@ -164,9 +220,9 @@
//
// buttonAddAirplane
//
- this.buttonAddAirplane.Location = new System.Drawing.Point(6, 109);
+ this.buttonAddAirplane.Location = new System.Drawing.Point(14, 298);
this.buttonAddAirplane.Name = "buttonAddAirplane";
- this.buttonAddAirplane.Size = new System.Drawing.Size(164, 33);
+ this.buttonAddAirplane.Size = new System.Drawing.Size(175, 33);
this.buttonAddAirplane.TabIndex = 1;
this.buttonAddAirplane.Text = "Добавить самолёт";
this.buttonAddAirplane.UseVisualStyleBackColor = true;
@@ -177,7 +233,7 @@
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(685, 620);
+ this.pictureBox.Size = new System.Drawing.Size(808, 604);
this.pictureBox.TabIndex = 1;
this.pictureBox.TabStop = false;
//
@@ -185,13 +241,15 @@
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(885, 620);
+ this.ClientSize = new System.Drawing.Size(1008, 604);
this.Controls.Add(this.pictureBox);
this.Controls.Add(this.groupBoxTools);
this.Name = "FormMapWithSetAirplanes";
this.Text = "FormMapWithSetAirplanes";
this.groupBoxTools.ResumeLayout(false);
this.groupBoxTools.PerformLayout();
+ this.groupBoxMaps.ResumeLayout(false);
+ this.groupBoxMaps.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
this.ResumeLayout(false);
@@ -211,5 +269,10 @@
private Button buttonAddAirplane;
private PictureBox pictureBox;
private ComboBox comboBoxSelectorMap;
+ 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 20de891..d4bd618 100644
--- a/AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplanes.cs
+++ b/AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplanes.cs
@@ -3,43 +3,102 @@
public partial class FormMapWithSetAirplanes : Form
{
///
- /// Объект от класса карты с набором объектов
+ /// Словарь для выпадающего списка
///
- private MapWithSetAirplanesGeneric _mapAirplanesCollectionGeneric;
+ private readonly Dictionary _mapsDict = new()
+ {
+ { "Простая карта", new SimpleMap() },
+ { "Моя карта", new MyMap() },
+ };
+ ///
+ /// Объект от коллекции карт
+ ///
+ 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 MyMap();
- 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();
}
}
+
+
///
/// Добавление объекта
///
@@ -47,7 +106,7 @@
///
private void ButtonAddAirplane_Click(object sender, EventArgs e)
{
- if (_mapAirplanesCollectionGeneric == null)
+ if (listBoxMaps.SelectedIndex == -1)
{
return;
}
@@ -55,15 +114,14 @@
if (form.ShowDialog() == DialogResult.OK)
{
DrawningObjectAirplane airplane = new(form.SelectedAirplane);
- if (form.SelectedAirplane == null || (_mapAirplanesCollectionGeneric + airplane) == -1)
+ if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + airplane != -1)
{
- MessageBox.Show("Не удалось добавить объект");
-
+ MessageBox.Show("Объект добавлен");
+ pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
else
{
- MessageBox.Show("Объект добавлен");
- pictureBox.Image = _mapAirplanesCollectionGeneric.ShowSet();
+ MessageBox.Show("Не удалось добавить объект");
}
}
}
@@ -74,19 +132,16 @@
///
private void ButtonRemoveAirplane_Click(object sender, EventArgs e)
{
- if (string.IsNullOrEmpty(maskedTextBoxPosition.Text))
- {
- return;
- }
- if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
+ if (listBoxMaps.SelectedIndex == -1 || string.IsNullOrEmpty(maskedTextBoxPosition.Text) ||
+ 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
{
@@ -100,12 +155,13 @@
///
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();
}
+
///
/// Вывод карты
///
@@ -113,11 +169,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();
}
///
/// Перемещение
@@ -126,7 +182,7 @@
///
private void ButtonMove_Click(object sender, EventArgs e)
{
- if (_mapAirplanesCollectionGeneric == null)
+ if (listBoxMaps.SelectedIndex == -1)
{
return;
}
@@ -148,7 +204,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 4c11f47..78c48d8 100644
--- a/AirplaneWithRadar/AirplaneWithRadar/MapWithSetAirplanesGeneric.cs
+++ b/AirplaneWithRadar/AirplaneWithRadar/MapWithSetAirplanesGeneric.cs
@@ -89,7 +89,7 @@
Shaking();
for (int i = 0; i < _setAirplanes.Count; i++)
{
- var airplane = _setAirplanes.Get(i);
+ var airplane = _setAirplanes[i];
if (airplane != null)
{
return _map.CreateMap(_pictureWidth, _pictureHeight, airplane);
@@ -118,11 +118,11 @@
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);
@@ -169,7 +169,7 @@
int maxLeft = (countInLine - 1) * _placeSizeWidth;
for (int i = 0; i < _setAirplanes.Count; i++)
{
- var airplane = _setAirplanes.Get(i);
+ var airplane = _setAirplanes[i];
airplane?.SetObject(maxLeft - i % countInLine * _placeSizeWidth + 5, i / countInLine * _placeSizeHeight + 15 , _pictureWidth, _pictureHeight);
airplane?.DrawningObject(g);
}
diff --git a/AirplaneWithRadar/AirplaneWithRadar/MapsCollection.cs b/AirplaneWithRadar/AirplaneWithRadar/MapsCollection.cs
new file mode 100644
index 0000000..4bd572c
--- /dev/null
+++ b/AirplaneWithRadar/AirplaneWithRadar/MapsCollection.cs
@@ -0,0 +1,64 @@
+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)
+ {
+ _mapStorages.Add(name, new(_pictureWidth, _pictureHeight, map));
+ }
+ ///
+ /// Удаление карты
+ ///
+ /// Название карты
+ public void DelMap(string name)
+ {
+ _mapStorages.Remove(name);
+ }
+ ///
+ /// Доступ к парковке
+ ///
+ ///
+ ///
+ public MapWithSetAirplanesGeneric this[string ind]
+ {
+ get
+ {
+ _mapStorages.TryGetValue(ind, out var mapWithSetAirplanesGeneric);
+ return mapWithSetAirplanesGeneric;
+ }
+ }
+
+ }
+}
diff --git a/AirplaneWithRadar/AirplaneWithRadar/SetAirplanesGeneric.cs b/AirplaneWithRadar/AirplaneWithRadar/SetAirplanesGeneric.cs
index 7a3b185..5b0396c 100644
--- a/AirplaneWithRadar/AirplaneWithRadar/SetAirplanesGeneric.cs
+++ b/AirplaneWithRadar/AirplaneWithRadar/SetAirplanesGeneric.cs
@@ -8,20 +8,23 @@
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();
}
///
/// Добавление объекта в набор
@@ -32,9 +35,10 @@
{
return Insert(airplane, 0);
}
+
private bool isCorrectPosition(int position)
{
- return 0 <= position && position < Count;
+ return 0 <= position && position < _maxCount;
}
///
/// Добавление объекта в набор на конкретную позицию
@@ -44,21 +48,11 @@
///
public int Insert(T airplane, int position)
{
- int positionNullElement = position;
- while (Get(positionNullElement) != null)
- {
- positionNullElement++;
- }
- if (!isCorrectPosition(positionNullElement))
+ if (!isCorrectPosition(position))
{
return -1;
}
- while (positionNullElement != position) // Смещение вправо
- {
- _places[positionNullElement] = _places[positionNullElement - 1];
- positionNullElement--;
- }
- _places[position] = airplane;
+ _places.Insert(position, airplane);
return position;
}
///
@@ -70,18 +64,40 @@
{
if (!isCorrectPosition(position)) return null;
var result = _places[position];
- _places[position] = null;
+ _places.RemoveAt(position);
return result;
}
///
- /// Получение объекта из набора по позиции
- ///
- ///
- ///
- public T Get(int position)
+ /// Получение объекта из набора по позиции
+ ///
+ ///
+ ///
+ public T this[int position]
{
- if (isCorrectPosition(position)) { return _places[position]; }
- else { return null; }
+ get
+ {
+ return isCorrectPosition(position) && position < Count ? _places[position] : null;
+ }
+ set
+ {
+ Insert(value, position);
+ }
+ }
+
+ public IEnumerable GetAirplanes()
+ {
+ foreach (var airplane in _places)
+ {
+ if (airplane != null)
+ {
+ yield return airplane;
+ }
+ else
+ {
+ yield break;
+ }
+ }
+
}
}
}