Merge pull request 'Eliseev E.E. LabWork04' (#5) from LabWork04 into LabWork03

Reviewed-on: http://student.git.athene.tech/ElEgEv/PIbd-21_Eliseev_E.E._Airbus_Base/pulls/5
This commit is contained in:
Евгений Эгов 2022-10-21 08:54:21 +04:00
commit 5717c213a0
5 changed files with 320 additions and 147 deletions

View File

@ -29,6 +29,12 @@
private void InitializeComponent() private void InitializeComponent()
{ {
this.groupBoxTools = new System.Windows.Forms.GroupBox(); 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.buttonRight = new System.Windows.Forms.Button();
this.buttonDown = new System.Windows.Forms.Button(); this.buttonDown = new System.Windows.Forms.Button();
this.buttonLeft = new System.Windows.Forms.Button(); this.buttonLeft = 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.groupBoxTools.SuspendLayout(); this.groupBoxTools.SuspendLayout();
this.groupBoxMaps.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
this.SuspendLayout(); this.SuspendLayout();
// //
// groupBoxTools // groupBoxTools
// //
this.groupBoxTools.Controls.Add(this.groupBoxMaps);
this.groupBoxTools.Controls.Add(this.buttonRight); this.groupBoxTools.Controls.Add(this.buttonRight);
this.groupBoxTools.Controls.Add(this.buttonDown); this.groupBoxTools.Controls.Add(this.buttonDown);
this.groupBoxTools.Controls.Add(this.buttonLeft); this.groupBoxTools.Controls.Add(this.buttonLeft);
@ -55,20 +62,83 @@
this.groupBoxTools.Controls.Add(this.buttonRemovePlane); this.groupBoxTools.Controls.Add(this.buttonRemovePlane);
this.groupBoxTools.Controls.Add(this.maskedTextBoxPosition); this.groupBoxTools.Controls.Add(this.maskedTextBoxPosition);
this.groupBoxTools.Controls.Add(this.buttonAddPlane); this.groupBoxTools.Controls.Add(this.buttonAddPlane);
this.groupBoxTools.Controls.Add(this.comboBoxSelectorMap);
this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right; 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.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.TabIndex = 0;
this.groupBoxTools.TabStop = false; this.groupBoxTools.TabStop = false;
this.groupBoxTools.Text = "Инструменты"; 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 // 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.BackgroundImage = global::Airbus.Properties.Resources.Right;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; 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.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(45, 45); this.buttonRight.Size = new System.Drawing.Size(45, 45);
this.buttonRight.TabIndex = 9; this.buttonRight.TabIndex = 9;
@ -77,9 +147,10 @@
// //
// buttonDown // 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.BackgroundImage = global::Airbus.Properties.Resources.Down;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; 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.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(45, 45); this.buttonDown.Size = new System.Drawing.Size(45, 45);
this.buttonDown.TabIndex = 8; this.buttonDown.TabIndex = 8;
@ -88,9 +159,10 @@
// //
// buttonLeft // 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.BackgroundImage = global::Airbus.Properties.Resources.Left;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; 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.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(45, 45); this.buttonLeft.Size = new System.Drawing.Size(45, 45);
this.buttonLeft.TabIndex = 7; this.buttonLeft.TabIndex = 7;
@ -99,9 +171,10 @@
// //
// buttonUp // 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.BackgroundImage = global::Airbus.Properties.Resources.Up;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; 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.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(45, 45); this.buttonUp.Size = new System.Drawing.Size(45, 45);
this.buttonUp.TabIndex = 6; this.buttonUp.TabIndex = 6;
@ -110,7 +183,7 @@
// //
// buttonShowOnMap // 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.Name = "buttonShowOnMap";
this.buttonShowOnMap.Size = new System.Drawing.Size(218, 29); this.buttonShowOnMap.Size = new System.Drawing.Size(218, 29);
this.buttonShowOnMap.TabIndex = 5; this.buttonShowOnMap.TabIndex = 5;
@ -120,7 +193,7 @@
// //
// buttonShowStorage // 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.Name = "buttonShowStorage";
this.buttonShowStorage.Size = new System.Drawing.Size(218, 29); this.buttonShowStorage.Size = new System.Drawing.Size(218, 29);
this.buttonShowStorage.TabIndex = 4; this.buttonShowStorage.TabIndex = 4;
@ -130,7 +203,7 @@
// //
// buttonRemovePlane // 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.Name = "buttonRemovePlane";
this.buttonRemovePlane.Size = new System.Drawing.Size(218, 29); this.buttonRemovePlane.Size = new System.Drawing.Size(218, 29);
this.buttonRemovePlane.TabIndex = 3; this.buttonRemovePlane.TabIndex = 3;
@ -140,7 +213,7 @@
// //
// maskedTextBoxPosition // 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.Mask = "00";
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition"; this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
this.maskedTextBoxPosition.Size = new System.Drawing.Size(218, 27); this.maskedTextBoxPosition.Size = new System.Drawing.Size(218, 27);
@ -148,7 +221,7 @@
// //
// buttonAddPlane // 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.Name = "buttonAddPlane";
this.buttonAddPlane.Size = new System.Drawing.Size(218, 29); this.buttonAddPlane.Size = new System.Drawing.Size(218, 29);
this.buttonAddPlane.TabIndex = 1; this.buttonAddPlane.TabIndex = 1;
@ -156,25 +229,12 @@
this.buttonAddPlane.UseVisualStyleBackColor = true; this.buttonAddPlane.UseVisualStyleBackColor = true;
this.buttonAddPlane.Click += new System.EventHandler(this.ButtonAddPlane_Click); 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 // 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.Name = "pictureBox"; 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.TabIndex = 1;
this.pictureBox.TabStop = false; this.pictureBox.TabStop = false;
// //
@ -182,13 +242,15 @@
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 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.pictureBox);
this.Controls.Add(this.groupBoxTools); this.Controls.Add(this.groupBoxTools);
this.Name = "FormMapWithSetPlanes"; this.Name = "FormMapWithSetPlanes";
this.Text = "FormMapWithSetPlanes"; this.Text = "FormMapWithSetPlanes";
this.groupBoxTools.ResumeLayout(false); this.groupBoxTools.ResumeLayout(false);
this.groupBoxTools.PerformLayout(); this.groupBoxTools.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);
@ -208,5 +270,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

@ -4,6 +4,7 @@ using System.ComponentModel;
using System.Data; using System.Data;
using System.Drawing; using System.Drawing;
using System.Linq; using System.Linq;
using System.Reflection;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
@ -12,47 +13,97 @@ namespace Airbus
{ {
public partial class FormMapWithSetPlanes : Form public partial class FormMapWithSetPlanes : Form
{ {
//объект от класса карты с набором объектов //словарь для выпадающего списка
private MapWithSetPlanesGeneric<DrawningObjectPlane, AbstractMap> _mapPlanesCollectionGeneric; private readonly Dictionary<string, AbstractMap> _mapsDict = new()
{
{"Простая карта", new SimpleMap() },
{"Буря в пустыне", new DesertStormMap() },
{"Звёздные войны", new StarWarsMap() }
};
//объект от коллекции карт
private readonly MapsCollection _mapsCollection;
public FormMapWithSetPlanes() public FormMapWithSetPlanes()
{ {
InitializeComponent(); InitializeComponent();
_mapsCollection = new MapsCollection(pictureBox.Width, pictureBox.Height);
comboBoxSelectorMap.Items.Clear();
foreach (var element in _mapsDict)
{
comboBoxSelectorMap.Items.Add(element.Key);
}
} }
//выбор карты //заполнение ListBoxMaps
private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e) 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 "Простая карта": listBoxMaps.Items.Add(_mapsCollection.Keys[i]);
map = new SimpleMap();
break;
case "Буря в пустыне":
map = new DesertStormMap();
break;
case "Звёздные войны":
map = new StarWarsMap();
break;
} }
if(map != null) if (listBoxMaps.Items.Count > 0 && (index == -1 || index >= listBoxMaps.Items.Count))
{ {
_mapPlanesCollectionGeneric = new MapWithSetPlanesGeneric<DrawningObjectPlane, AbstractMap>( listBoxMaps.SelectedIndex = 0;
pictureBox.Width, pictureBox.Height, map);
} }
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) private void ButtonAddPlane_Click(object sender, EventArgs e)
{ {
if(_mapPlanesCollectionGeneric == null) if(_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? String.Empty] == null)
{ {
return; return;
} }
@ -63,10 +114,10 @@ namespace Airbus
{ {
DrawningObjectPlane plane = new(form.SelectedPlane); DrawningObjectPlane plane = new(form.SelectedPlane);
if(_mapPlanesCollectionGeneric + plane != -1) if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? String.Empty] + plane != -1)
{ {
MessageBox.Show("Объект добавлен"); MessageBox.Show("Объект добавлен");
pictureBox.Image = _mapPlanesCollectionGeneric.ShowSet(); pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? String.Empty].ShowSet();
} }
else else
{ {
@ -91,10 +142,10 @@ namespace Airbus
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
{ {
@ -105,29 +156,29 @@ namespace Airbus
//вывод набора //вывод набора
private void ButtonShowStorage_Click(object sender, EventArgs e) private void ButtonShowStorage_Click(object sender, EventArgs e)
{ {
if(_mapPlanesCollectionGeneric == null) if(_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? String.Empty] == null)
{ {
return; return;
} }
pictureBox.Image = _mapPlanesCollectionGeneric.ShowSet(); pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? String.Empty].ShowSet();
} }
//вывод карты //вывод карты
private void ButtonShowOnMap_Click(object sender, EventArgs e) private void ButtonShowOnMap_Click(object sender, EventArgs e)
{ {
if (_mapPlanesCollectionGeneric == null) if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? String.Empty] == null)
{ {
return; return;
} }
pictureBox.Image = _mapPlanesCollectionGeneric.ShowOnMap(); pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? String.Empty].ShowOnMap();
} }
//перемещение //перемещение
private void ButtonMove_Click(object sender, EventArgs e) private void ButtonMove_Click(object sender, EventArgs e)
{ {
if(_mapPlanesCollectionGeneric == null) if(_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? String.Empty] == null)
{ {
return; return;
} }
@ -152,7 +203,7 @@ namespace Airbus
break; break;
} }
pictureBox.Image = _mapPlanesCollectionGeneric.MoveObject(dir); pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? String.Empty].MoveObject(dir);
} }
} }
} }

View File

@ -69,14 +69,9 @@ namespace Airbus
{ {
Shaking(); Shaking();
for(int i = 0; i < _setPlanes.Count; i++) foreach(var plane in _setPlanes.GetAirbus())
{ {
var plane = _setPlanes.Get(i); return _map.CreateMap(_pictureWidth, _pictureHeight, plane);
if(plane != null)
{
return _map.CreateMap(_pictureWidth, _pictureHeight, plane);
}
} }
return new(_pictureWidth, _pictureHeight); return new(_pictureWidth, _pictureHeight);
@ -100,11 +95,11 @@ namespace Airbus
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)
{ {
@ -132,35 +127,37 @@ namespace Airbus
Brush asphaltBrush = new SolidBrush(Color.DarkGray); Brush asphaltBrush = new SolidBrush(Color.DarkGray);
Brush marcupBrush = new SolidBrush(Color.White); Brush marcupBrush = new SolidBrush(Color.White);
g.FillRectangle(concreteBrush, 0, 0, _pictureWidth, _pictureHeight); //заливаем область в цвет бетона //заливаем область в цвет бетона
g.FillRectangle(concreteBrush, 0, 0, _pictureWidth, _pictureHeight);
for(int i = 0; i < _pictureWidth / _placeSizeWidth - 1; i++) for(int i = 0; i < _pictureWidth / _placeSizeWidth - 1; i++)
{ {
for(int j = 2; j < _pictureHeight / _placeSizeHeight + 1; ++j) //линия разметки места
{//линия разметки места for (int j = 2; j < _pictureHeight / _placeSizeHeight + 1; ++j)
g.DrawLine(pen, i * _placeSizeWidth + 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(marcupBrush, _placeSizeWidth * 3 + 10, 0, 185, _pictureHeight);
g.FillRectangle(asphaltBrush, _placeSizeWidth * 2 + 35, 0, 175, _pictureHeight); g.FillRectangle(asphaltBrush, _placeSizeWidth * 3 + 15, 0, 175, _pictureHeight);
g.DrawLine(marcupPen, _placeSizeWidth * 2 + 210, 0, _placeSizeWidth * 2 + 210, _pictureHeight); g.DrawLine(marcupPen, _placeSizeWidth * 3 + 190, 0, _placeSizeWidth * 3 + 190, _pictureHeight);
g.DrawLine(marcupPen, _placeSizeWidth * 2 + 35, 0, _placeSizeWidth * 2 + 35, _pictureHeight); g.DrawLine(marcupPen, _placeSizeWidth * 3 + 15, 0, _placeSizeWidth * 3 + 15, _pictureHeight);
g.DrawLine(marcupPen, _placeSizeWidth * 2 + 215, 0, _placeSizeWidth * 2 + 215, _pictureHeight); g.DrawLine(marcupPen, _placeSizeWidth * 3 + 195, 0, _placeSizeWidth * 3 + 195, _pictureHeight);
g.DrawLine(marcupPen, _placeSizeWidth * 2 + 30, 0, _placeSizeWidth * 2 + 30, _pictureHeight); g.DrawLine(marcupPen, _placeSizeWidth * 3 + 10, 0, _placeSizeWidth * 3 + 10, _pictureHeight);
for (int i = 0; i < _pictureHeight / _placeSizeHeight; ++i) 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++) 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 - 5, 20 + i * _placeSizeHeight / 2, _placeSizeWidth * 3 - 5, (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 * 4, 20 + i * _placeSizeHeight / 2, _placeSizeWidth * 4, (i + 1) * _placeSizeHeight / 2 - 20);
} }
//отрисовка сочков //отрисовка сочков
@ -185,24 +182,21 @@ namespace Airbus
//метод прорисовки объеков //метод прорисовки объеков
public void DrawPlanes(Graphics g) public void DrawPlanes(Graphics g)
{ {
int position = 0; int currentWidth = 2;
int currentWidth = 1; int currentHeight = 7;
int currentHeight = 5;
for (int i = 0; i < _setPlanes.Count; i++) foreach (var plane in _setPlanes.GetAirbus())
{ {
_setPlanes.Get(i)?.SetObject(currentWidth * _placeSizeWidth + 20, currentHeight * _placeSizeHeight + 20, _pictureWidth, _pictureHeight); plane.SetObject(currentWidth * _placeSizeWidth + 20, currentHeight * _placeSizeHeight + 20, _pictureWidth, _pictureHeight);
_setPlanes.Get(i)?.DrawningObject(g); plane.DrawningObject(g);
if(position % 2 == 0) if(currentWidth != 0)
{ {
position++;
currentWidth--; currentWidth--;
} }
else else
{ {
position = 0; currentWidth = 2;
currentWidth = 1;
currentHeight--; currentHeight--;
} }
} }

View File

@ -0,0 +1,55 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Airbus
{
//класс для хранения коллекции карт
internal class MapsCollection
{
//словарь (хранилище) с картами
readonly Dictionary<string, MapWithSetPlanesGeneric<DrawningObjectPlane, AbstractMap>> _mapStorage;
//возвращение списка названий карт
public List<string> Keys => _mapStorage.Keys.ToList();
//ширина окна отрисовки
private readonly int _pictureWidth;
//высота окна отрисовки
private readonly int _pictureHeight;
//конструктор
public MapsCollection(int pictureWidth, int pictureHeight)
{
_mapStorage = new Dictionary<string, MapWithSetPlanesGeneric<DrawningObjectPlane, AbstractMap>>();
_pictureWidth = pictureWidth;
_pictureHeight = pictureHeight;
}
//добавление карты
public void AddMap(string name, AbstractMap map)
{
var NewElem = new MapWithSetPlanesGeneric<DrawningObjectPlane, AbstractMap>(
_pictureWidth, _pictureHeight, map);
_mapStorage.Add(name, NewElem);
}
//удаление карты
public void DelMap(string name)
{
_mapStorage.Remove(name);
}
//Доступ к аэродрому
public MapWithSetPlanesGeneric<DrawningObjectPlane, AbstractMap> this[string ind]
{
get
{
return _mapStorage[ind];
}
}
}
}

View File

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Reflection.PortableExecutable;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -9,65 +10,38 @@ namespace Airbus
internal class SetPlanesGeneric<T> internal class SetPlanesGeneric<T>
where T: class where T: class
{ {
//массив объектов, которые храним //список объектов, которые храним
private readonly T[] _places; private readonly List<T> _places;
//количество объектов в массиве //количество объектов в массиве
public int Count => _places.Length; public int Count => _places.Count;
//ограничение по кол-ву объектов
private readonly int _maxCount;
//конструктор //конструктор
public SetPlanesGeneric(int count) public SetPlanesGeneric(int count)
{ {
_places = new T[count]; _maxCount = count;
_places = new List<T>();
} }
//добавление объекта в набор //добавление объекта в набор
public int Insert(T plane) 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) public int Insert(T plane, int position)
{ {
// проверка позиции if (position >= _maxCount && position < 0)
if (position >= _places.Length || position < 0)
{ {
return -1; return -1;
} }
//проверка, что элемент массива по этой позиции пустой, если нет, то _places.Insert(position, plane);
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;
return position; return position;
} }
@ -75,32 +49,64 @@ namespace Airbus
//удаление объекта из набора с конкретной позиции //удаление объекта из набора с конкретной позиции
public T Remove(int position) public T Remove(int position)
{ {
// проверка позиции if (position < _maxCount && position >= 0)
if (position >= _places.Length || position < 0)
{ {
if (_places.ElementAt(position) != null)
{
T result = _places.ElementAt(position);
_places.RemoveAt(position);
return result;
}
return null; return null;
} }
// удаление объекта из массива, присовив элементу массива значение null return null;
T temp = _places[position];
_places[position] = null;
return temp;
} }
//получение объекта из набора по позиции //получение объекта из набора по позиции
public T Get(int position) public T this[int position]
{ {
if (position >= _places.Length || position < 0) get
{ {
return null; if (position >= _places.Count || position < 0)
} {
else if (_places[position] == null) return null;
{ }
return null; else if (_places[position] == null)
} {
return null;
}
return _places[position]; return _places[position];
}
set
{
if (position < _maxCount && position >= 0)
{
Insert(this[position], position);
}
}
}
//проход по набору до первого пустого
public IEnumerable<T> GetAirbus()
{
foreach(var plane in _places)
{
if(plane != null)
{
yield return plane;
}
else
{
yield break;
}
}
} }
} }
} }