diff --git a/Airbus/Airbus/FormMapWithSetPlanes.Designer.cs b/Airbus/Airbus/FormMapWithSetPlanes.Designer.cs
index 159ed8c..1ed23c2 100644
--- a/Airbus/Airbus/FormMapWithSetPlanes.Designer.cs
+++ b/Airbus/Airbus/FormMapWithSetPlanes.Designer.cs
@@ -29,6 +29,12 @@
private void InitializeComponent()
{
this.groupBox1 = new System.Windows.Forms.GroupBox();
+ this.groupBoxMaps = new System.Windows.Forms.GroupBox();
+ this.buttonDeleteMap = new System.Windows.Forms.Button();
+ this.listBoxMaps = new System.Windows.Forms.ListBox();
+ this.buttonAddMap = new System.Windows.Forms.Button();
+ this.textBoxNewMapName = new System.Windows.Forms.TextBox();
+ this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
this.buttonLeft = new System.Windows.Forms.Button();
this.buttonRight = new System.Windows.Forms.Button();
this.buttonDown = new System.Windows.Forms.Button();
@@ -38,14 +44,15 @@
this.buttonRemovePlane = new System.Windows.Forms.Button();
this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
this.buttonAddPlane = new System.Windows.Forms.Button();
- this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
this.pictureBox = new System.Windows.Forms.PictureBox();
this.groupBox1.SuspendLayout();
+ this.groupBoxMaps.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
this.SuspendLayout();
//
// groupBox1
//
+ this.groupBox1.Controls.Add(this.groupBoxMaps);
this.groupBox1.Controls.Add(this.buttonLeft);
this.groupBox1.Controls.Add(this.buttonRight);
this.groupBox1.Controls.Add(this.buttonDown);
@@ -55,25 +62,83 @@
this.groupBox1.Controls.Add(this.buttonRemovePlane);
this.groupBox1.Controls.Add(this.maskedTextBoxPosition);
this.groupBox1.Controls.Add(this.buttonAddPlane);
- this.groupBox1.Controls.Add(this.comboBoxSelectorMap);
this.groupBox1.Dock = System.Windows.Forms.DockStyle.Right;
- this.groupBox1.Location = new System.Drawing.Point(685, 0);
- this.groupBox1.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.groupBox1.Location = new System.Drawing.Point(657, 0);
this.groupBox1.Name = "groupBox1";
- this.groupBox1.Padding = new System.Windows.Forms.Padding(3, 4, 3, 4);
- this.groupBox1.Size = new System.Drawing.Size(229, 600);
+ this.groupBox1.Size = new System.Drawing.Size(200, 614);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Инструменты";
//
+ // groupBoxMaps
+ //
+ this.groupBoxMaps.Controls.Add(this.buttonDeleteMap);
+ this.groupBoxMaps.Controls.Add(this.listBoxMaps);
+ this.groupBoxMaps.Controls.Add(this.buttonAddMap);
+ this.groupBoxMaps.Controls.Add(this.textBoxNewMapName);
+ this.groupBoxMaps.Controls.Add(this.comboBoxSelectorMap);
+ this.groupBoxMaps.Location = new System.Drawing.Point(6, 22);
+ this.groupBoxMaps.Name = "groupBoxMaps";
+ this.groupBoxMaps.Size = new System.Drawing.Size(188, 263);
+ this.groupBoxMaps.TabIndex = 10;
+ this.groupBoxMaps.TabStop = false;
+ this.groupBoxMaps.Text = "Карты";
+ //
+ // buttonDeleteMap
+ //
+ this.buttonDeleteMap.Location = new System.Drawing.Point(11, 218);
+ this.buttonDeleteMap.Name = "buttonDeleteMap";
+ this.buttonDeleteMap.Size = new System.Drawing.Size(171, 34);
+ this.buttonDeleteMap.TabIndex = 4;
+ this.buttonDeleteMap.Text = "Удалить карту";
+ this.buttonDeleteMap.UseVisualStyleBackColor = true;
+ this.buttonDeleteMap.Click += new System.EventHandler(this.buttonDeleteMap_Click_1);
+ //
+ // listBoxMaps
+ //
+ this.listBoxMaps.FormattingEnabled = true;
+ this.listBoxMaps.ItemHeight = 15;
+ this.listBoxMaps.Location = new System.Drawing.Point(11, 118);
+ this.listBoxMaps.Name = "listBoxMaps";
+ this.listBoxMaps.Size = new System.Drawing.Size(171, 94);
+ this.listBoxMaps.TabIndex = 3;
+ this.listBoxMaps.SelectedIndexChanged += new System.EventHandler(this.listBoxMaps_SelectedIndexChanged_1);
+ //
+ // buttonAddMap
+ //
+ this.buttonAddMap.Location = new System.Drawing.Point(11, 80);
+ this.buttonAddMap.Name = "buttonAddMap";
+ this.buttonAddMap.Size = new System.Drawing.Size(171, 32);
+ this.buttonAddMap.TabIndex = 2;
+ this.buttonAddMap.Text = "Добавить карту";
+ this.buttonAddMap.UseVisualStyleBackColor = true;
+ this.buttonAddMap.Click += new System.EventHandler(this.buttonAddMap_Click_1);
+ //
+ // textBoxNewMapName
+ //
+ this.textBoxNewMapName.Location = new System.Drawing.Point(11, 22);
+ this.textBoxNewMapName.Name = "textBoxNewMapName";
+ this.textBoxNewMapName.Size = new System.Drawing.Size(171, 23);
+ this.textBoxNewMapName.TabIndex = 0;
+ //
+ // comboBoxSelectorMap
+ //
+ this.comboBoxSelectorMap.FormattingEnabled = true;
+ this.comboBoxSelectorMap.Items.AddRange(new object[] {
+ "Простая карта",
+ "Вторая карта"});
+ this.comboBoxSelectorMap.Location = new System.Drawing.Point(11, 51);
+ this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
+ this.comboBoxSelectorMap.Size = new System.Drawing.Size(171, 23);
+ this.comboBoxSelectorMap.TabIndex = 0;
+ //
// buttonLeft
//
this.buttonLeft.BackgroundImage = global::Airbus.Properties.Resources.arrowLeft;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
- this.buttonLeft.Location = new System.Drawing.Point(64, 541);
- this.buttonLeft.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.buttonLeft.Location = new System.Drawing.Point(56, 572);
this.buttonLeft.Name = "buttonLeft";
- this.buttonLeft.Size = new System.Drawing.Size(34, 40);
+ this.buttonLeft.Size = new System.Drawing.Size(30, 30);
this.buttonLeft.TabIndex = 9;
this.buttonLeft.UseVisualStyleBackColor = true;
this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
@@ -82,10 +147,9 @@
//
this.buttonRight.BackgroundImage = global::Airbus.Properties.Resources.arrowRight;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
- this.buttonRight.Location = new System.Drawing.Point(146, 541);
- this.buttonRight.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.buttonRight.Location = new System.Drawing.Point(128, 572);
this.buttonRight.Name = "buttonRight";
- this.buttonRight.Size = new System.Drawing.Size(34, 40);
+ this.buttonRight.Size = new System.Drawing.Size(30, 30);
this.buttonRight.TabIndex = 8;
this.buttonRight.UseVisualStyleBackColor = true;
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
@@ -94,10 +158,9 @@
//
this.buttonDown.BackgroundImage = global::Airbus.Properties.Resources.arrowDown;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
- this.buttonDown.Location = new System.Drawing.Point(105, 541);
- this.buttonDown.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.buttonDown.Location = new System.Drawing.Point(92, 572);
this.buttonDown.Name = "buttonDown";
- this.buttonDown.Size = new System.Drawing.Size(34, 40);
+ this.buttonDown.Size = new System.Drawing.Size(30, 30);
this.buttonDown.TabIndex = 7;
this.buttonDown.UseVisualStyleBackColor = true;
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
@@ -106,20 +169,18 @@
//
this.buttonUp.BackgroundImage = global::Airbus.Properties.Resources.arrowUp;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
- this.buttonUp.Location = new System.Drawing.Point(105, 493);
- this.buttonUp.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.buttonUp.Location = new System.Drawing.Point(92, 536);
this.buttonUp.Name = "buttonUp";
- this.buttonUp.Size = new System.Drawing.Size(34, 40);
+ this.buttonUp.Size = new System.Drawing.Size(30, 30);
this.buttonUp.TabIndex = 6;
this.buttonUp.UseVisualStyleBackColor = true;
this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonShowOnMap
//
- this.buttonShowOnMap.Location = new System.Drawing.Point(19, 411);
- this.buttonShowOnMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.buttonShowOnMap.Location = new System.Drawing.Point(17, 499);
this.buttonShowOnMap.Name = "buttonShowOnMap";
- this.buttonShowOnMap.Size = new System.Drawing.Size(195, 41);
+ this.buttonShowOnMap.Size = new System.Drawing.Size(171, 31);
this.buttonShowOnMap.TabIndex = 5;
this.buttonShowOnMap.Text = "Посмотреть карту";
this.buttonShowOnMap.UseVisualStyleBackColor = true;
@@ -127,10 +188,9 @@
//
// buttonShowStorage
//
- this.buttonShowStorage.Location = new System.Drawing.Point(19, 345);
- this.buttonShowStorage.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.buttonShowStorage.Location = new System.Drawing.Point(17, 459);
this.buttonShowStorage.Name = "buttonShowStorage";
- this.buttonShowStorage.Size = new System.Drawing.Size(195, 45);
+ this.buttonShowStorage.Size = new System.Drawing.Size(171, 34);
this.buttonShowStorage.TabIndex = 4;
this.buttonShowStorage.Text = "Посмотреть хранилище";
this.buttonShowStorage.UseVisualStyleBackColor = true;
@@ -138,10 +198,9 @@
//
// buttonRemovePlane
//
- this.buttonRemovePlane.Location = new System.Drawing.Point(19, 225);
- this.buttonRemovePlane.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.buttonRemovePlane.Location = new System.Drawing.Point(17, 400);
this.buttonRemovePlane.Name = "buttonRemovePlane";
- this.buttonRemovePlane.Size = new System.Drawing.Size(195, 41);
+ this.buttonRemovePlane.Size = new System.Drawing.Size(171, 31);
this.buttonRemovePlane.TabIndex = 3;
this.buttonRemovePlane.Text = "Удалить самолёт";
this.buttonRemovePlane.UseVisualStyleBackColor = true;
@@ -149,60 +208,45 @@
//
// maskedTextBoxPosition
//
- this.maskedTextBoxPosition.Location = new System.Drawing.Point(19, 168);
- this.maskedTextBoxPosition.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.maskedTextBoxPosition.Location = new System.Drawing.Point(17, 371);
this.maskedTextBoxPosition.Mask = "00";
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
- this.maskedTextBoxPosition.Size = new System.Drawing.Size(195, 27);
+ this.maskedTextBoxPosition.Size = new System.Drawing.Size(171, 23);
this.maskedTextBoxPosition.TabIndex = 2;
//
// buttonAddPlane
//
- this.buttonAddPlane.Location = new System.Drawing.Point(19, 85);
- this.buttonAddPlane.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.buttonAddPlane.Location = new System.Drawing.Point(17, 315);
this.buttonAddPlane.Name = "buttonAddPlane";
- this.buttonAddPlane.Size = new System.Drawing.Size(195, 41);
+ this.buttonAddPlane.Size = new System.Drawing.Size(171, 31);
this.buttonAddPlane.TabIndex = 1;
this.buttonAddPlane.Text = "Добавить самолёт";
this.buttonAddPlane.UseVisualStyleBackColor = true;
this.buttonAddPlane.Click += new System.EventHandler(this.buttonAddPlane_Click_1);
//
- // comboBoxSelectorMap
- //
- this.comboBoxSelectorMap.FormattingEnabled = true;
- this.comboBoxSelectorMap.Items.AddRange(new object[] {
- "Простая карта",
- "Вторая карта"});
- this.comboBoxSelectorMap.Location = new System.Drawing.Point(19, 29);
- this.comboBoxSelectorMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
- this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
- this.comboBoxSelectorMap.Size = new System.Drawing.Size(195, 28);
- this.comboBoxSelectorMap.TabIndex = 0;
- this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.comboBoxSelectorMap_SelectedIndexChanged_1);
- //
// pictureBox
//
this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBox.Location = new System.Drawing.Point(0, 0);
- this.pictureBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.pictureBox.Name = "pictureBox";
- this.pictureBox.Size = new System.Drawing.Size(685, 600);
+ this.pictureBox.Size = new System.Drawing.Size(657, 614);
this.pictureBox.TabIndex = 0;
this.pictureBox.TabStop = false;
//
// FormMapWithSetPlanes
//
- this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
+ this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(914, 600);
+ this.ClientSize = new System.Drawing.Size(857, 614);
this.Controls.Add(this.pictureBox);
this.Controls.Add(this.groupBox1);
- this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.Name = "FormMapWithSetPlanes";
- this.Text = "FormMapWithSetPlanes";
+ this.Text = "Карта с набором объектов";
this.Click += new System.EventHandler(this.ButtonMove_Click);
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
+ this.groupBoxMaps.ResumeLayout(false);
+ this.groupBoxMaps.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
this.ResumeLayout(false);
@@ -222,5 +266,10 @@
private Button buttonAddPlane;
private ComboBox comboBoxSelectorMap;
private PictureBox pictureBox;
+ private GroupBox groupBoxMaps;
+ private Button buttonDeleteMap;
+ private ListBox listBoxMaps;
+ private Button buttonAddMap;
+ private TextBox textBoxNewMapName;
}
}
\ No newline at end of file
diff --git a/Airbus/Airbus/FormMapWithSetPlanes.cs b/Airbus/Airbus/FormMapWithSetPlanes.cs
index d750449..2404f83 100644
--- a/Airbus/Airbus/FormMapWithSetPlanes.cs
+++ b/Airbus/Airbus/FormMapWithSetPlanes.cs
@@ -14,42 +14,95 @@ namespace Airbus
public partial class FormMapWithSetPlanes : Form
{
///
- /// Объект от класса карты с набором объектов
+ /// Словарь для выпадающего списка
///
- private MapWithSetPlanesGeneric _mapPlanesCollectionGeneric;
+ private readonly Dictionary _mapsDict = new()
+ {
+ { "Простая карта", new SimpleMap() },
+ { "Вторая карта", new MyMap() }
+ };
+ ///
+ /// Объект от коллекции карт
+ ///
+ private readonly MapsCollection _mapsCollection;
///
/// Конструктор
///
public FormMapWithSetPlanes()
{
InitializeComponent();
+ _mapsCollection = new MapsCollection(pictureBox.Width, pictureBox.Height);
+ comboBoxSelectorMap.Items.Clear();
+ foreach (var elem in _mapsDict)
+ {
+ comboBoxSelectorMap.Items.Add(elem.Key);
+ }
+ }
+ ///
+ /// Заполнение listBoxMaps
+ ///
+ private void ReloadMaps()
+ {
+ int index = listBoxMaps.SelectedIndex;
+ listBoxMaps.Items.Clear();
+ for (int i = 0; i < _mapsCollection.Keys.Count; i++)
+ {
+ listBoxMaps.Items.Add(_mapsCollection.Keys[i]);
+ }
+ if (listBoxMaps.Items.Count > 0 && (index == -1 || index >= listBoxMaps.Items.Count))
+ {
+ listBoxMaps.SelectedIndex = 0;
+ }
+ else if (listBoxMaps.Items.Count > 0 && index > -1 && index < listBoxMaps.Items.Count)
+ {
+ listBoxMaps.SelectedIndex = index;
+ }
+ }
+ ///
+ /// Добавление карты
+ ///
+ ///
+ ///
+ private void buttonAddMap_Click_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 comboBoxSelectorMap_SelectedIndexChanged_1(object sender, EventArgs e)
+ private void listBoxMaps_SelectedIndexChanged_1(object sender, EventArgs e)
{
- AbstractMap map = null;
- switch (comboBoxSelectorMap.Text)
+ pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
+ }
+ ///
+ /// Удаление карты
+ ///
+ ///
+ ///
+ private void buttonDeleteMap_Click_1(object sender, EventArgs e)
+ {
+ if (listBoxMaps.SelectedIndex == -1)
{
- case "Простая карта":
- map = new SimpleMap();
- break;
- case "Вторая карта":
- map = new MyMap();
- break;
-
+ return;
}
- if (map != null)
+ if (MessageBox.Show($"Удалить карту {listBoxMaps.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
- _mapPlanesCollectionGeneric = new
- MapWithSetPlanesGeneric(pictureBox.Width, pictureBox.Height, map);
- }
- else
- {
- _mapPlanesCollectionGeneric = null;
+ _mapsCollection.DelMap(listBoxMaps.SelectedItem?.ToString() ?? string.Empty);
+ ReloadMaps();
}
}
///
@@ -59,7 +112,7 @@ namespace Airbus
///
private void buttonAddPlane_Click_1(object sender, EventArgs e)
{
- if (_mapPlanesCollectionGeneric == null)
+ if (listBoxMaps.SelectedIndex == -1)
{
return;
}
@@ -67,10 +120,10 @@ namespace Airbus
if (form.ShowDialog() == DialogResult.OK)
{
DrawningObjectPlane plane = new(form.SelectedPlane);
- if (_mapPlanesCollectionGeneric + plane != -1)
+ if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + plane >= 0)
{
MessageBox.Show("Объект добавлен");
- pictureBox.Image = _mapPlanesCollectionGeneric.ShowSet();
+ pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
else
{
@@ -85,6 +138,10 @@ namespace Airbus
///
private void buttonRemovePlane_Click_1(object sender, EventArgs e)
{
+ if (listBoxMaps.SelectedIndex == -1)
+ {
+ return;
+ }
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text))
{
return;
@@ -94,10 +151,10 @@ namespace Airbus
return;
}
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
- if (_mapPlanesCollectionGeneric - pos != null)
+ if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null)
{
MessageBox.Show("Объект удален");
- pictureBox.Image = _mapPlanesCollectionGeneric.ShowSet();
+ pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
else
{
@@ -111,11 +168,12 @@ namespace Airbus
///
private void buttonShowStorage_Click_1(object sender, EventArgs e)
{
- if (_mapPlanesCollectionGeneric == null)
+ if (listBoxMaps.SelectedIndex == -1)
{
return;
}
- pictureBox.Image = _mapPlanesCollectionGeneric.ShowSet();
+ pictureBox.Image =
+ _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
///
/// Вывод карты
@@ -124,11 +182,12 @@ namespace Airbus
///
private void buttonShowOnMap_Click_1(object sender, EventArgs e)
{
- if (_mapPlanesCollectionGeneric == null)
+ if (listBoxMaps.SelectedIndex == -1)
{
return;
}
- pictureBox.Image = _mapPlanesCollectionGeneric.ShowOnMap();
+ pictureBox.Image =
+ _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowOnMap();
}
///
/// Перемещение
@@ -137,7 +196,7 @@ namespace Airbus
///
private void ButtonMove_Click(object sender, EventArgs e)
{
- if (_mapPlanesCollectionGeneric == null)
+ if (listBoxMaps.SelectedIndex == -1)
{
return;
}
@@ -159,9 +218,9 @@ namespace Airbus
dir = Direction.Right;
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 6b7dd53..99bd5ac 100644
--- a/Airbus/Airbus/MapWithSetPlanesGeneric.cs
+++ b/Airbus/Airbus/MapWithSetPlanesGeneric.cs
@@ -88,16 +88,13 @@ namespace Airbus
public Bitmap ShowOnMap()
{
Shaking();
- for (int i = 0; i < _setPlanes.Count; i++)
+ foreach (var plane in _setPlanes.GetPlanes())
{
- var plane = _setPlanes.Get(i);
- if (plane != null)
- {
- return _map.CreateMap(_pictureWidth, _pictureHeight, plane);
- }
+ return _map.CreateMap(_pictureWidth, _pictureHeight, plane);
}
return new(_pictureWidth, _pictureHeight);
}
+
///
/// Перемещение объекта по крате
///
@@ -119,11 +116,11 @@ namespace Airbus
int j = _setPlanes.Count - 1;
for (int i = 0; i < _setPlanes.Count; i++)
{
- if (_setPlanes.Get(i) == null)
+ if (_setPlanes[i] == null)
{
for (; j > i; j--)
{
- var plane = _setPlanes.Get(j);
+ var plane = _setPlanes[j];
if (plane != null)
{
_setPlanes.Insert(plane, i);
@@ -183,17 +180,16 @@ namespace Airbus
{
int width = _pictureWidth / _placeSizeWidth;
int height = _pictureHeight / _placeSizeHeight;
-
- for (int i = 0; i < _setPlanes.Count; i++)
+ int i = 0;
+ foreach (var plane in _setPlanes.GetPlanes())
{
// TODO установка позиции
- if(_setPlanes.Get(i) != null)
- {
- _setPlanes.Get(i).SetObject((width - i % width - 1) * _placeSizeWidth,(height - i / width - 1) * _placeSizeHeight, _pictureWidth, _pictureHeight);
- _setPlanes.Get(i)?.DrawningObject(g);
- }
+ plane.SetObject((width - i % width - 1) * _placeSizeWidth, (height - i / width - 1) * _placeSizeHeight, _pictureWidth, _pictureHeight);
+ plane.DrawningObject(g);
+ i++;
}
}
+
}
}
diff --git a/Airbus/Airbus/MapsCollection.cs b/Airbus/Airbus/MapsCollection.cs
new file mode 100644
index 0000000..34a6b36
--- /dev/null
+++ b/Airbus/Airbus/MapsCollection.cs
@@ -0,0 +1,79 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Airbus
+{
+ internal class MapsCollection
+ {
+ ///
+ /// Словарь (хранилище) с картами
+ ///
+ readonly Dictionary> _mapStorages;
+ ///
+ /// Возвращение списка названий карт
+ ///
+ public List Keys => _mapStorages.Keys.ToList();
+ ///
+ /// Ширина окна отрисовки
+ ///
+ private readonly int _pictureWidth;
+ ///
+ /// Высота окна отрисовки
+ ///
+ private readonly int _pictureHeight;
+ ///
+ /// Конструктор
+ ///
+ ///
+ ///
+ public MapsCollection(int pictureWidth, int pictureHeight)
+ {
+ _mapStorages = new Dictionary>();
+ _pictureWidth = pictureWidth;
+ _pictureHeight = pictureHeight;
+ }
+ ///
+ /// Добавление карты
+ ///
+ /// Название карты
+ /// Карта
+ public void AddMap(string name, AbstractMap map)
+ {
+ // TODO Прописать логику для добавления
+ if (_mapStorages.ContainsKey(name))
+ {
+ return;
+ }
+ _mapStorages.Add(name, new MapWithSetPlanesGeneric(_pictureWidth, _pictureHeight, map));
+ }
+ ///
+ /// Удаление карты
+ ///
+ /// Название карты
+ public void DelMap(string name)
+ {
+ // TODO Прописать логику для удаления
+ _mapStorages.Remove(name);
+ }
+ ///
+ /// Доступ к парковке
+ ///
+ ///
+ ///
+ public MapWithSetPlanesGeneric this[string ind]
+ {
+ get
+ {
+ // TODO Продумать логику получения объекта
+ if (_mapStorages.ContainsKey(ind))
+ {
+ return _mapStorages[ind];
+ }
+ return null;
+ }
+ }
+ }
+}
diff --git a/Airbus/Airbus/SetPlanesGeneric.cs b/Airbus/Airbus/SetPlanesGeneric.cs
index a7f7d3d..f1a02ba 100644
--- a/Airbus/Airbus/SetPlanesGeneric.cs
+++ b/Airbus/Airbus/SetPlanesGeneric.cs
@@ -10,75 +10,55 @@ namespace Airbus
where T : class
{
///
- /// Массив объектов, которые храним
+ /// Список объектов, которые храним
///
- private readonly T[] _places;
+ private readonly List _places;
///
- /// Количество объектов в массиве
+ /// Количество объектов в списке
///
- public int Count => _places.Length;
+ public int Count => _places.Count;
+ private readonly int _maxCount;
///
/// Конструктор
///
///
public SetPlanesGeneric(int count)
{
- _places = new T[count];
+ _maxCount = count;
+ _places = new List();
}
///
/// Добавление объекта в набор
///
- /// Добавляемый самолёт
+ /// Добавляемый автомобиль
///
public int Insert(T plane)
{
// TODO вставка в начало набора
- return Insert(plane, 0);
+ // TODO проверка на _maxCount
+ if (_places.Count + 1 >= _maxCount)
+ return -1;
+ _places.Insert(0, plane);
+ return 0;
}
-
///
/// Добавление объекта в набор на конкретную позицию
///
- /// Добавляемый самолёт
+ /// Добавляемый автомобиль
/// Позиция
///
public int Insert(T plane, int position)
{
// TODO проверка позиции
- // TODO проверка, что элемент массива по этой позиции пустой, если нет, то
- // проверка, что после вставляемого элемента в массиве есть пустой элемент
- // сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента
// TODO вставка по позиции
-
- if(_places[position] == null)
+ if (position >= _maxCount || position < 0)
{
- _places[position] = plane;
- return position;
- }
- else
- {
- int pos = -1;
- bool isFree = false;
- for (int i = 0; i < Count; i++)
- {
- if (_places[i] == null)
- {
- isFree = true;
- pos = i;
- break;
- }
- }
- if (isFree)
- {
- for (var i = pos; i > position; --i) _places[i] = _places[i - 1];
- _places[position] = plane;
- return position;
- }
- else
- {
- return -1;
- }
+ return -1;
}
+ if (_places.Count + 1 >= _maxCount)
+ return -1;
+ _places.Insert(position, plane);
+ return position;
}
///
/// Удаление объекта из набора с конкретной позиции
@@ -89,9 +69,12 @@ namespace Airbus
{
// TODO проверка позиции
// TODO удаление объекта из массива, присовив элементу массива значение null
- if (position < 0 || position >= Count || _places[position] == null) return null;
+ if (position >= _maxCount || position < 0)
+ {
+ return null;
+ }
T DeletePlane = _places[position];
- _places[position] = null;
+ _places.RemoveAt(position);
return DeletePlane;
}
///
@@ -99,15 +82,44 @@ namespace Airbus
///
///
///
- public T Get(int position)
+ public T this[int position]
{
- // TODO проверка позиции
- if (position < 0 || position >= Count)
+ get
{
- return null;
+ // TODO проверка позиции
+ if (position < 0 || position >= _maxCount)
+ {
+ return null;
+ }
+ return _places[position];
+ }
+ set
+ {
+ // TODO проверка позиции
+ // TODO вставка в список по позиции
+ if (position < 0 || position >= _maxCount)
+ {
+ Insert(value, position);
+ }
+ }
+ }
+ ///
+ /// Проход по набору до первого пустого
+ ///
+ ///
+ public IEnumerable GetPlanes()
+ {
+ foreach (var plane in _places)
+ {
+ if (plane != null)
+ {
+ yield return plane;
+ }
+ else
+ {
+ yield break;
+ }
}
- return _places[position];
}
}
-
}