Merge pull request 'Emelyanov A.S. LabWork04' (#8) from LabWork04 into LabWork03

Reviewed-on: http://student.git.athene.tech/Emelyanov535/Pibd-22_Emelyanov_A.S._Airbus._Base/pulls/8
This commit is contained in:
Евгений Эгов 2022-11-07 12:38:38 +04:00
commit b2b1becdc7
5 changed files with 342 additions and 147 deletions

View File

@ -29,6 +29,12 @@
private void InitializeComponent() private void InitializeComponent()
{ {
this.groupBox1 = new System.Windows.Forms.GroupBox(); 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.buttonLeft = new System.Windows.Forms.Button();
this.buttonRight = new System.Windows.Forms.Button(); this.buttonRight = new System.Windows.Forms.Button();
this.buttonDown = new System.Windows.Forms.Button(); this.buttonDown = new System.Windows.Forms.Button();
@ -38,14 +44,15 @@
this.buttonRemovePlane = new System.Windows.Forms.Button(); this.buttonRemovePlane = new System.Windows.Forms.Button();
this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox(); this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
this.buttonAddPlane = new System.Windows.Forms.Button(); this.buttonAddPlane = new System.Windows.Forms.Button();
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
this.pictureBox = new System.Windows.Forms.PictureBox(); this.pictureBox = new System.Windows.Forms.PictureBox();
this.groupBox1.SuspendLayout(); this.groupBox1.SuspendLayout();
this.groupBoxMaps.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
this.SuspendLayout(); this.SuspendLayout();
// //
// groupBox1 // groupBox1
// //
this.groupBox1.Controls.Add(this.groupBoxMaps);
this.groupBox1.Controls.Add(this.buttonLeft); this.groupBox1.Controls.Add(this.buttonLeft);
this.groupBox1.Controls.Add(this.buttonRight); this.groupBox1.Controls.Add(this.buttonRight);
this.groupBox1.Controls.Add(this.buttonDown); this.groupBox1.Controls.Add(this.buttonDown);
@ -55,25 +62,83 @@
this.groupBox1.Controls.Add(this.buttonRemovePlane); this.groupBox1.Controls.Add(this.buttonRemovePlane);
this.groupBox1.Controls.Add(this.maskedTextBoxPosition); this.groupBox1.Controls.Add(this.maskedTextBoxPosition);
this.groupBox1.Controls.Add(this.buttonAddPlane); this.groupBox1.Controls.Add(this.buttonAddPlane);
this.groupBox1.Controls.Add(this.comboBoxSelectorMap);
this.groupBox1.Dock = System.Windows.Forms.DockStyle.Right; this.groupBox1.Dock = System.Windows.Forms.DockStyle.Right;
this.groupBox1.Location = new System.Drawing.Point(685, 0); this.groupBox1.Location = new System.Drawing.Point(657, 0);
this.groupBox1.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.groupBox1.Name = "groupBox1"; this.groupBox1.Name = "groupBox1";
this.groupBox1.Padding = new System.Windows.Forms.Padding(3, 4, 3, 4); this.groupBox1.Size = new System.Drawing.Size(200, 614);
this.groupBox1.Size = new System.Drawing.Size(229, 600);
this.groupBox1.TabIndex = 0; this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false; this.groupBox1.TabStop = false;
this.groupBox1.Text = "Инструменты"; 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 // buttonLeft
// //
this.buttonLeft.BackgroundImage = global::Airbus.Properties.Resources.arrowLeft; this.buttonLeft.BackgroundImage = global::Airbus.Properties.Resources.arrowLeft;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonLeft.Location = new System.Drawing.Point(64, 541); this.buttonLeft.Location = new System.Drawing.Point(56, 572);
this.buttonLeft.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonLeft.Name = "buttonLeft"; 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.TabIndex = 9;
this.buttonLeft.UseVisualStyleBackColor = true; this.buttonLeft.UseVisualStyleBackColor = true;
this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click); this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
@ -82,10 +147,9 @@
// //
this.buttonRight.BackgroundImage = global::Airbus.Properties.Resources.arrowRight; this.buttonRight.BackgroundImage = global::Airbus.Properties.Resources.arrowRight;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonRight.Location = new System.Drawing.Point(146, 541); this.buttonRight.Location = new System.Drawing.Point(128, 572);
this.buttonRight.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonRight.Name = "buttonRight"; 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.TabIndex = 8;
this.buttonRight.UseVisualStyleBackColor = true; this.buttonRight.UseVisualStyleBackColor = true;
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click); this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
@ -94,10 +158,9 @@
// //
this.buttonDown.BackgroundImage = global::Airbus.Properties.Resources.arrowDown; this.buttonDown.BackgroundImage = global::Airbus.Properties.Resources.arrowDown;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonDown.Location = new System.Drawing.Point(105, 541); this.buttonDown.Location = new System.Drawing.Point(92, 572);
this.buttonDown.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonDown.Name = "buttonDown"; 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.TabIndex = 7;
this.buttonDown.UseVisualStyleBackColor = true; this.buttonDown.UseVisualStyleBackColor = true;
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click); this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
@ -106,20 +169,18 @@
// //
this.buttonUp.BackgroundImage = global::Airbus.Properties.Resources.arrowUp; this.buttonUp.BackgroundImage = global::Airbus.Properties.Resources.arrowUp;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonUp.Location = new System.Drawing.Point(105, 493); this.buttonUp.Location = new System.Drawing.Point(92, 536);
this.buttonUp.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonUp.Name = "buttonUp"; 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.TabIndex = 6;
this.buttonUp.UseVisualStyleBackColor = true; this.buttonUp.UseVisualStyleBackColor = true;
this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click); this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
// //
// buttonShowOnMap // buttonShowOnMap
// //
this.buttonShowOnMap.Location = new System.Drawing.Point(19, 411); this.buttonShowOnMap.Location = new System.Drawing.Point(17, 499);
this.buttonShowOnMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonShowOnMap.Name = "buttonShowOnMap"; 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.TabIndex = 5;
this.buttonShowOnMap.Text = "Посмотреть карту"; this.buttonShowOnMap.Text = "Посмотреть карту";
this.buttonShowOnMap.UseVisualStyleBackColor = true; this.buttonShowOnMap.UseVisualStyleBackColor = true;
@ -127,10 +188,9 @@
// //
// buttonShowStorage // buttonShowStorage
// //
this.buttonShowStorage.Location = new System.Drawing.Point(19, 345); this.buttonShowStorage.Location = new System.Drawing.Point(17, 459);
this.buttonShowStorage.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonShowStorage.Name = "buttonShowStorage"; 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.TabIndex = 4;
this.buttonShowStorage.Text = "Посмотреть хранилище"; this.buttonShowStorage.Text = "Посмотреть хранилище";
this.buttonShowStorage.UseVisualStyleBackColor = true; this.buttonShowStorage.UseVisualStyleBackColor = true;
@ -138,10 +198,9 @@
// //
// buttonRemovePlane // buttonRemovePlane
// //
this.buttonRemovePlane.Location = new System.Drawing.Point(19, 225); this.buttonRemovePlane.Location = new System.Drawing.Point(17, 400);
this.buttonRemovePlane.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonRemovePlane.Name = "buttonRemovePlane"; 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.TabIndex = 3;
this.buttonRemovePlane.Text = "Удалить самолёт"; this.buttonRemovePlane.Text = "Удалить самолёт";
this.buttonRemovePlane.UseVisualStyleBackColor = true; this.buttonRemovePlane.UseVisualStyleBackColor = true;
@ -149,60 +208,45 @@
// //
// maskedTextBoxPosition // maskedTextBoxPosition
// //
this.maskedTextBoxPosition.Location = new System.Drawing.Point(19, 168); this.maskedTextBoxPosition.Location = new System.Drawing.Point(17, 371);
this.maskedTextBoxPosition.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.maskedTextBoxPosition.Mask = "00"; this.maskedTextBoxPosition.Mask = "00";
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition"; 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; this.maskedTextBoxPosition.TabIndex = 2;
// //
// buttonAddPlane // buttonAddPlane
// //
this.buttonAddPlane.Location = new System.Drawing.Point(19, 85); this.buttonAddPlane.Location = new System.Drawing.Point(17, 315);
this.buttonAddPlane.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonAddPlane.Name = "buttonAddPlane"; 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.TabIndex = 1;
this.buttonAddPlane.Text = "Добавить самолёт"; this.buttonAddPlane.Text = "Добавить самолёт";
this.buttonAddPlane.UseVisualStyleBackColor = true; this.buttonAddPlane.UseVisualStyleBackColor = true;
this.buttonAddPlane.Click += new System.EventHandler(this.buttonAddPlane_Click_1); 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 // pictureBox
// //
this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill; this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBox.Location = new System.Drawing.Point(0, 0); 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.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.TabIndex = 0;
this.pictureBox.TabStop = false; this.pictureBox.TabStop = false;
// //
// FormMapWithSetPlanes // 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.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.pictureBox);
this.Controls.Add(this.groupBox1); this.Controls.Add(this.groupBox1);
this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.Name = "FormMapWithSetPlanes"; this.Name = "FormMapWithSetPlanes";
this.Text = "FormMapWithSetPlanes"; this.Text = "Карта с набором объектов";
this.Click += new System.EventHandler(this.ButtonMove_Click); this.Click += new System.EventHandler(this.ButtonMove_Click);
this.groupBox1.ResumeLayout(false); this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout(); this.groupBox1.PerformLayout();
this.groupBoxMaps.ResumeLayout(false);
this.groupBoxMaps.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
this.ResumeLayout(false); this.ResumeLayout(false);
@ -222,5 +266,10 @@
private Button buttonAddPlane; private Button buttonAddPlane;
private ComboBox comboBoxSelectorMap; private ComboBox comboBoxSelectorMap;
private PictureBox pictureBox; private PictureBox pictureBox;
private GroupBox groupBoxMaps;
private Button buttonDeleteMap;
private ListBox listBoxMaps;
private Button buttonAddMap;
private TextBox textBoxNewMapName;
} }
} }

View File

@ -14,42 +14,95 @@ namespace Airbus
public partial class FormMapWithSetPlanes : Form public partial class FormMapWithSetPlanes : Form
{ {
/// <summary> /// <summary>
/// Объект от класса карты с набором объектов /// Словарь для выпадающего списка
/// </summary> /// </summary>
private MapWithSetPlanesGeneric<DrawningObjectPlane, AbstractMap> _mapPlanesCollectionGeneric; private readonly Dictionary<string, AbstractMap> _mapsDict = new()
{
{ "Простая карта", new SimpleMap() },
{ "Вторая карта", new MyMap() }
};
/// <summary>
/// Объект от коллекции карт
/// </summary>
private readonly MapsCollection _mapsCollection;
/// <summary> /// <summary>
/// Конструктор /// Конструктор
/// </summary> /// </summary>
public FormMapWithSetPlanes() public FormMapWithSetPlanes()
{ {
InitializeComponent(); InitializeComponent();
_mapsCollection = new MapsCollection(pictureBox.Width, pictureBox.Height);
comboBoxSelectorMap.Items.Clear();
foreach (var elem in _mapsDict)
{
comboBoxSelectorMap.Items.Add(elem.Key);
}
}
/// <summary>
/// Заполнение listBoxMaps
/// </summary>
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;
}
}
/// <summary>
/// Добавление карты
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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();
} }
/// <summary> /// <summary>
/// Выбор карты /// Выбор карты
/// </summary> /// </summary>
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private void comboBoxSelectorMap_SelectedIndexChanged_1(object sender, EventArgs e) private void listBoxMaps_SelectedIndexChanged_1(object sender, EventArgs e)
{ {
AbstractMap map = null; pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
switch (comboBoxSelectorMap.Text)
{
case "Простая карта":
map = new SimpleMap();
break;
case "Вторая карта":
map = new MyMap();
break;
} }
if (map != null) /// <summary>
/// Удаление карты
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonDeleteMap_Click_1(object sender, EventArgs e)
{ {
_mapPlanesCollectionGeneric = new if (listBoxMaps.SelectedIndex == -1)
MapWithSetPlanesGeneric<DrawningObjectPlane, AbstractMap>(pictureBox.Width, pictureBox.Height, map); {
return;
} }
else if (MessageBox.Show($"Удалить карту {listBoxMaps.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{ {
_mapPlanesCollectionGeneric = null; _mapsCollection.DelMap(listBoxMaps.SelectedItem?.ToString() ?? string.Empty);
ReloadMaps();
} }
} }
/// <summary> /// <summary>
@ -59,7 +112,7 @@ namespace Airbus
/// <param name="e"></param> /// <param name="e"></param>
private void buttonAddPlane_Click_1(object sender, EventArgs e) private void buttonAddPlane_Click_1(object sender, EventArgs e)
{ {
if (_mapPlanesCollectionGeneric == null) if (listBoxMaps.SelectedIndex == -1)
{ {
return; return;
} }
@ -67,10 +120,10 @@ namespace Airbus
if (form.ShowDialog() == DialogResult.OK) if (form.ShowDialog() == DialogResult.OK)
{ {
DrawningObjectPlane plane = new(form.SelectedPlane); DrawningObjectPlane plane = new(form.SelectedPlane);
if (_mapPlanesCollectionGeneric + plane != -1) if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + plane >= 0)
{ {
MessageBox.Show("Объект добавлен"); MessageBox.Show("Объект добавлен");
pictureBox.Image = _mapPlanesCollectionGeneric.ShowSet(); pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
} }
else else
{ {
@ -85,6 +138,10 @@ namespace Airbus
/// <param name="e"></param> /// <param name="e"></param>
private void buttonRemovePlane_Click_1(object sender, EventArgs e) private void buttonRemovePlane_Click_1(object sender, EventArgs e)
{ {
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text)) if (string.IsNullOrEmpty(maskedTextBoxPosition.Text))
{ {
return; return;
@ -94,10 +151,10 @@ namespace Airbus
return; return;
} }
int pos = Convert.ToInt32(maskedTextBoxPosition.Text); int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
if (_mapPlanesCollectionGeneric - pos != null) if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null)
{ {
MessageBox.Show("Объект удален"); MessageBox.Show("Объект удален");
pictureBox.Image = _mapPlanesCollectionGeneric.ShowSet(); pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
} }
else else
{ {
@ -111,11 +168,12 @@ namespace Airbus
/// <param name="e"></param> /// <param name="e"></param>
private void buttonShowStorage_Click_1(object sender, EventArgs e) private void buttonShowStorage_Click_1(object sender, EventArgs e)
{ {
if (_mapPlanesCollectionGeneric == null) if (listBoxMaps.SelectedIndex == -1)
{ {
return; return;
} }
pictureBox.Image = _mapPlanesCollectionGeneric.ShowSet(); pictureBox.Image =
_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
} }
/// <summary> /// <summary>
/// Вывод карты /// Вывод карты
@ -124,11 +182,12 @@ namespace Airbus
/// <param name="e"></param> /// <param name="e"></param>
private void buttonShowOnMap_Click_1(object sender, EventArgs e) private void buttonShowOnMap_Click_1(object sender, EventArgs e)
{ {
if (_mapPlanesCollectionGeneric == null) if (listBoxMaps.SelectedIndex == -1)
{ {
return; return;
} }
pictureBox.Image = _mapPlanesCollectionGeneric.ShowOnMap(); pictureBox.Image =
_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowOnMap();
} }
/// <summary> /// <summary>
/// Перемещение /// Перемещение
@ -137,7 +196,7 @@ namespace Airbus
/// <param name="e"></param> /// <param name="e"></param>
private void ButtonMove_Click(object sender, EventArgs e) private void ButtonMove_Click(object sender, EventArgs e)
{ {
if (_mapPlanesCollectionGeneric == null) if (listBoxMaps.SelectedIndex == -1)
{ {
return; return;
} }
@ -159,9 +218,9 @@ namespace Airbus
dir = Direction.Right; dir = Direction.Right;
break; break;
} }
pictureBox.Image = _mapPlanesCollectionGeneric.MoveObject(dir); pictureBox.Image =
} _mapsCollection[listBoxMaps.SelectedItem?.ToString() ??
string.Empty].MoveObject(dir);
}
} }
} }

View File

@ -88,16 +88,13 @@ namespace Airbus
public Bitmap ShowOnMap() public Bitmap ShowOnMap()
{ {
Shaking(); 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); return new(_pictureWidth, _pictureHeight);
} }
/// <summary> /// <summary>
/// Перемещение объекта по крате /// Перемещение объекта по крате
/// </summary> /// </summary>
@ -119,11 +116,11 @@ namespace Airbus
int j = _setPlanes.Count - 1; int j = _setPlanes.Count - 1;
for (int i = 0; i < _setPlanes.Count; i++) for (int i = 0; i < _setPlanes.Count; i++)
{ {
if (_setPlanes.Get(i) == null) if (_setPlanes[i] == null)
{ {
for (; j > i; j--) for (; j > i; j--)
{ {
var plane = _setPlanes.Get(j); var plane = _setPlanes[j];
if (plane != null) if (plane != null)
{ {
_setPlanes.Insert(plane, i); _setPlanes.Insert(plane, i);
@ -183,17 +180,16 @@ namespace Airbus
{ {
int width = _pictureWidth / _placeSizeWidth; int width = _pictureWidth / _placeSizeWidth;
int height = _pictureHeight / _placeSizeHeight; int height = _pictureHeight / _placeSizeHeight;
int i = 0;
for (int i = 0; i < _setPlanes.Count; i++) foreach (var plane in _setPlanes.GetPlanes())
{ {
// TODO установка позиции // TODO установка позиции
if(_setPlanes.Get(i) != null) plane.SetObject((width - i % width - 1) * _placeSizeWidth, (height - i / width - 1) * _placeSizeHeight, _pictureWidth, _pictureHeight);
{ plane.DrawningObject(g);
_setPlanes.Get(i).SetObject((width - i % width - 1) * _placeSizeWidth,(height - i / width - 1) * _placeSizeHeight, _pictureWidth, _pictureHeight); i++;
_setPlanes.Get(i)?.DrawningObject(g);
}
}
} }
} }
} }
}

View File

@ -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
{
/// <summary>
/// Словарь (хранилище) с картами
/// </summary>
readonly Dictionary<string, MapWithSetPlanesGeneric<DrawningObjectPlane,AbstractMap>> _mapStorages;
/// <summary>
/// Возвращение списка названий карт
/// </summary>
public List<string> Keys => _mapStorages.Keys.ToList();
/// <summary>
/// Ширина окна отрисовки
/// </summary>
private readonly int _pictureWidth;
/// <summary>
/// Высота окна отрисовки
/// </summary>
private readonly int _pictureHeight;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="pictureWidth"></param>
/// <param name="pictureHeight"></param>
public MapsCollection(int pictureWidth, int pictureHeight)
{
_mapStorages = new Dictionary<string, MapWithSetPlanesGeneric<DrawningObjectPlane, AbstractMap>>();
_pictureWidth = pictureWidth;
_pictureHeight = pictureHeight;
}
/// <summary>
/// Добавление карты
/// </summary>
/// <param name="name">Название карты</param>
/// <param name="map">Карта</param>
public void AddMap(string name, AbstractMap map)
{
// TODO Прописать логику для добавления
if (_mapStorages.ContainsKey(name))
{
return;
}
_mapStorages.Add(name, new MapWithSetPlanesGeneric<DrawningObjectPlane, AbstractMap>(_pictureWidth, _pictureHeight, map));
}
/// <summary>
/// Удаление карты
/// </summary>
/// <param name="name">Название карты</param>
public void DelMap(string name)
{
// TODO Прописать логику для удаления
_mapStorages.Remove(name);
}
/// <summary>
/// Доступ к парковке
/// </summary>
/// <param name="ind"></param>
/// <returns></returns>
public MapWithSetPlanesGeneric<DrawningObjectPlane, AbstractMap> this[string ind]
{
get
{
// TODO Продумать логику получения объекта
if (_mapStorages.ContainsKey(ind))
{
return _mapStorages[ind];
}
return null;
}
}
}
}

View File

@ -10,75 +10,55 @@ namespace Airbus
where T : class where T : class
{ {
/// <summary> /// <summary>
/// Массив объектов, которые храним /// Список объектов, которые храним
/// </summary> /// </summary>
private readonly T[] _places; private readonly List<T> _places;
/// <summary> /// <summary>
/// Количество объектов в массиве /// Количество объектов в списке
/// </summary> /// </summary>
public int Count => _places.Length; public int Count => _places.Count;
private readonly int _maxCount;
/// <summary> /// <summary>
/// Конструктор /// Конструктор
/// </summary> /// </summary>
/// <param name="count"></param> /// <param name="count"></param>
public SetPlanesGeneric(int count) public SetPlanesGeneric(int count)
{ {
_places = new T[count]; _maxCount = count;
_places = new List<T>();
} }
/// <summary> /// <summary>
/// Добавление объекта в набор /// Добавление объекта в набор
/// </summary> /// </summary>
/// <param name="car">Добавляемый самолёт</param> /// <param name="plane">Добавляемый автомобиль</param>
/// <returns></returns> /// <returns></returns>
public int Insert(T plane) public int Insert(T plane)
{ {
// TODO вставка в начало набора // TODO вставка в начало набора
return Insert(plane, 0); // TODO проверка на _maxCount
if (_places.Count + 1 >= _maxCount)
return -1;
_places.Insert(0, plane);
return 0;
} }
/// <summary> /// <summary>
/// Добавление объекта в набор на конкретную позицию /// Добавление объекта в набор на конкретную позицию
/// </summary> /// </summary>
/// <param name="plane">Добавляемый самолёт</param> /// <param name="plane">Добавляемый автомобиль</param>
/// <param name="position">Позиция</param> /// <param name="position">Позиция</param>
/// <returns></returns> /// <returns></returns>
public int Insert(T plane, int position) public int Insert(T plane, int position)
{ {
// TODO проверка позиции // TODO проверка позиции
// TODO проверка, что элемент массива по этой позиции пустой, если нет, то
// проверка, что после вставляемого элемента в массиве есть пустой элемент
// сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента
// TODO вставка по позиции // TODO вставка по позиции
if (position >= _maxCount || position < 0)
if(_places[position] == null)
{
_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;
} }
/// <summary> /// <summary>
/// Удаление объекта из набора с конкретной позиции /// Удаление объекта из набора с конкретной позиции
@ -89,9 +69,12 @@ namespace Airbus
{ {
// TODO проверка позиции // TODO проверка позиции
// TODO удаление объекта из массива, присовив элементу массива значение null // TODO удаление объекта из массива, присовив элементу массива значение null
if (position < 0 || position >= Count || _places[position] == null) return null; if (position >= _maxCount || position < 0)
{
return null;
}
T DeletePlane = _places[position]; T DeletePlane = _places[position];
_places[position] = null; _places.RemoveAt(position);
return DeletePlane; return DeletePlane;
} }
/// <summary> /// <summary>
@ -99,15 +82,44 @@ namespace Airbus
/// </summary> /// </summary>
/// <param name="position"></param> /// <param name="position"></param>
/// <returns></returns> /// <returns></returns>
public T Get(int position) public T this[int position]
{
get
{ {
// TODO проверка позиции // TODO проверка позиции
if (position < 0 || position >= Count) if (position < 0 || position >= _maxCount)
{ {
return null; return null;
} }
return _places[position]; return _places[position];
} }
set
{
// TODO проверка позиции
// TODO вставка в список по позиции
if (position < 0 || position >= _maxCount)
{
Insert(value, position);
}
}
}
/// <summary>
/// Проход по набору до первого пустого
/// </summary>
/// <returns></returns>
public IEnumerable<T> GetPlanes()
{
foreach (var plane in _places)
{
if (plane != null)
{
yield return plane;
}
else
{
yield break;
}
}
}
} }
} }