diff --git a/WarPlanes/WarPlanes/DrawningObjectWarPlane.cs b/WarPlanes/WarPlanes/DrawningObjectWarPlane.cs
index c8e2c7d..bb74e90 100644
--- a/WarPlanes/WarPlanes/DrawningObjectWarPlane.cs
+++ b/WarPlanes/WarPlanes/DrawningObjectWarPlane.cs
@@ -23,7 +23,7 @@
public void SetObject(int x, int y, int width, int height)
{
- _warplane.SetPosition(x, y, width, height);
+ _warplane?.SetPosition(x, y, width, height);
}
void IDrawningObject.DrawningObject(Graphics g)
diff --git a/WarPlanes/WarPlanes/FormMapWithSetWarPlanes.Designer.cs b/WarPlanes/WarPlanes/FormMapWithSetWarPlanes.Designer.cs
index 888b39e..6e7001e 100644
--- a/WarPlanes/WarPlanes/FormMapWithSetWarPlanes.Designer.cs
+++ b/WarPlanes/WarPlanes/FormMapWithSetWarPlanes.Designer.cs
@@ -29,6 +29,12 @@
private void InitializeComponent()
{
this.groupBoxTools = new System.Windows.Forms.GroupBox();
+ this.groupBoxMaps = new System.Windows.Forms.GroupBox();
+ this.buttonAddMap = new System.Windows.Forms.Button();
+ this.buttonDeleteMap = new System.Windows.Forms.Button();
+ this.listBoxMaps = new System.Windows.Forms.ListBox();
+ this.textBoxNewMapName = new System.Windows.Forms.TextBox();
+ this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
this.buttonRemoveWarPlane = new System.Windows.Forms.Button();
this.buttonShowStorage = new System.Windows.Forms.Button();
@@ -38,14 +44,15 @@
this.buttonUp = new System.Windows.Forms.Button();
this.buttonShowOnMap = new System.Windows.Forms.Button();
this.buttonAddWarPlane = new System.Windows.Forms.Button();
- this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
this.pictureBox = new System.Windows.Forms.PictureBox();
this.groupBoxTools.SuspendLayout();
+ this.groupBoxMaps.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
this.SuspendLayout();
//
// groupBoxTools
//
+ this.groupBoxTools.Controls.Add(this.groupBoxMaps);
this.groupBoxTools.Controls.Add(this.maskedTextBoxPosition);
this.groupBoxTools.Controls.Add(this.buttonRemoveWarPlane);
this.groupBoxTools.Controls.Add(this.buttonShowStorage);
@@ -55,18 +62,79 @@
this.groupBoxTools.Controls.Add(this.buttonUp);
this.groupBoxTools.Controls.Add(this.buttonShowOnMap);
this.groupBoxTools.Controls.Add(this.buttonAddWarPlane);
- this.groupBoxTools.Controls.Add(this.comboBoxSelectorMap);
this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right;
this.groupBoxTools.Location = new System.Drawing.Point(811, 0);
this.groupBoxTools.Name = "groupBoxTools";
- this.groupBoxTools.Size = new System.Drawing.Size(204, 554);
+ this.groupBoxTools.Size = new System.Drawing.Size(204, 600);
this.groupBoxTools.TabIndex = 0;
this.groupBoxTools.TabStop = false;
this.groupBoxTools.Text = "Инструменты";
//
+ // groupBoxMaps
+ //
+ this.groupBoxMaps.Controls.Add(this.buttonAddMap);
+ this.groupBoxMaps.Controls.Add(this.buttonDeleteMap);
+ this.groupBoxMaps.Controls.Add(this.listBoxMaps);
+ 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(192, 248);
+ this.groupBoxMaps.TabIndex = 11;
+ this.groupBoxMaps.TabStop = false;
+ this.groupBoxMaps.Text = "Карты";
+ //
+ // buttonAddMap
+ //
+ this.buttonAddMap.Location = new System.Drawing.Point(11, 80);
+ this.buttonAddMap.Name = "buttonAddMap";
+ this.buttonAddMap.Size = new System.Drawing.Size(175, 35);
+ this.buttonAddMap.TabIndex = 2;
+ this.buttonAddMap.Text = "Добавить карту";
+ this.buttonAddMap.UseVisualStyleBackColor = true;
+ this.buttonAddMap.Click += new System.EventHandler(this.ButtonAddMap_Click);
+ //
+ // buttonDeleteMap
+ //
+ this.buttonDeleteMap.Location = new System.Drawing.Point(11, 206);
+ this.buttonDeleteMap.Name = "buttonDeleteMap";
+ this.buttonDeleteMap.Size = new System.Drawing.Size(175, 35);
+ this.buttonDeleteMap.TabIndex = 4;
+ 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(11, 121);
+ this.listBoxMaps.Name = "listBoxMaps";
+ this.listBoxMaps.Size = new System.Drawing.Size(175, 79);
+ this.listBoxMaps.TabIndex = 3;
+ this.listBoxMaps.SelectedIndexChanged += new System.EventHandler(this.ListBoxMaps_SelectedIndexChanged);
+ //
+ // textBoxNewMapName
+ //
+ this.textBoxNewMapName.Location = new System.Drawing.Point(11, 22);
+ this.textBoxNewMapName.Name = "textBoxNewMapName";
+ this.textBoxNewMapName.Size = new System.Drawing.Size(175, 23);
+ this.textBoxNewMapName.TabIndex = 0;
+ //
+ // comboBoxSelectorMap
+ //
+ this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
+ 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(175, 23);
+ this.comboBoxSelectorMap.TabIndex = 1;
+ //
// maskedTextBoxPosition
//
- this.maskedTextBoxPosition.Location = new System.Drawing.Point(17, 166);
+ this.maskedTextBoxPosition.Location = new System.Drawing.Point(17, 349);
this.maskedTextBoxPosition.Mask = "00";
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
this.maskedTextBoxPosition.Size = new System.Drawing.Size(175, 23);
@@ -75,7 +143,7 @@
//
// buttonRemoveWarPlane
//
- this.buttonRemoveWarPlane.Location = new System.Drawing.Point(17, 195);
+ this.buttonRemoveWarPlane.Location = new System.Drawing.Point(17, 378);
this.buttonRemoveWarPlane.Name = "buttonRemoveWarPlane";
this.buttonRemoveWarPlane.Size = new System.Drawing.Size(175, 35);
this.buttonRemoveWarPlane.TabIndex = 3;
@@ -85,7 +153,7 @@
//
// buttonShowStorage
//
- this.buttonShowStorage.Location = new System.Drawing.Point(17, 287);
+ this.buttonShowStorage.Location = new System.Drawing.Point(17, 419);
this.buttonShowStorage.Name = "buttonShowStorage";
this.buttonShowStorage.Size = new System.Drawing.Size(175, 35);
this.buttonShowStorage.TabIndex = 4;
@@ -98,7 +166,7 @@
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonDown.BackgroundImage = global::AirFighter.Properties.Resources.arrowDown;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
- this.buttonDown.Location = new System.Drawing.Point(91, 504);
+ this.buttonDown.Location = new System.Drawing.Point(91, 550);
this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(30, 30);
this.buttonDown.TabIndex = 10;
@@ -110,7 +178,7 @@
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonRight.BackgroundImage = global::AirFighter.Properties.Resources.arrowRight;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
- this.buttonRight.Location = new System.Drawing.Point(127, 504);
+ this.buttonRight.Location = new System.Drawing.Point(127, 550);
this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(30, 30);
this.buttonRight.TabIndex = 9;
@@ -122,7 +190,7 @@
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonLeft.BackgroundImage = global::AirFighter.Properties.Resources.arrowLeft;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
- this.buttonLeft.Location = new System.Drawing.Point(55, 504);
+ this.buttonLeft.Location = new System.Drawing.Point(55, 550);
this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
this.buttonLeft.TabIndex = 8;
@@ -134,7 +202,7 @@
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonUp.BackgroundImage = global::AirFighter.Properties.Resources.arrowUp;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
- this.buttonUp.Location = new System.Drawing.Point(91, 468);
+ this.buttonUp.Location = new System.Drawing.Point(91, 514);
this.buttonUp.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(30, 30);
this.buttonUp.TabIndex = 7;
@@ -143,7 +211,7 @@
//
// buttonShowOnMap
//
- this.buttonShowOnMap.Location = new System.Drawing.Point(17, 391);
+ this.buttonShowOnMap.Location = new System.Drawing.Point(17, 460);
this.buttonShowOnMap.Name = "buttonShowOnMap";
this.buttonShowOnMap.Size = new System.Drawing.Size(175, 35);
this.buttonShowOnMap.TabIndex = 5;
@@ -153,7 +221,7 @@
//
// buttonAddWarPlane
//
- this.buttonAddWarPlane.Location = new System.Drawing.Point(17, 106);
+ this.buttonAddWarPlane.Location = new System.Drawing.Point(17, 308);
this.buttonAddWarPlane.Name = "buttonAddWarPlane";
this.buttonAddWarPlane.Size = new System.Drawing.Size(175, 35);
this.buttonAddWarPlane.TabIndex = 1;
@@ -161,25 +229,12 @@
this.buttonAddWarPlane.UseVisualStyleBackColor = true;
this.buttonAddWarPlane.Click += new System.EventHandler(this.ButtonAddWarPlane_Click);
//
- // comboBoxSelectorMap
- //
- this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
- this.comboBoxSelectorMap.FormattingEnabled = true;
- this.comboBoxSelectorMap.Items.AddRange(new object[] {
- "Простая карта",
- "Закрытая карта"});
- this.comboBoxSelectorMap.Location = new System.Drawing.Point(17, 32);
- this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
- this.comboBoxSelectorMap.Size = new System.Drawing.Size(175, 23);
- this.comboBoxSelectorMap.TabIndex = 0;
- this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);
- //
// pictureBox
//
this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBox.Location = new System.Drawing.Point(0, 0);
this.pictureBox.Name = "pictureBox";
- this.pictureBox.Size = new System.Drawing.Size(811, 554);
+ this.pictureBox.Size = new System.Drawing.Size(811, 600);
this.pictureBox.TabIndex = 1;
this.pictureBox.TabStop = false;
//
@@ -187,13 +242,15 @@
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(1015, 554);
+ this.ClientSize = new System.Drawing.Size(1015, 600);
this.Controls.Add(this.pictureBox);
this.Controls.Add(this.groupBoxTools);
this.Name = "FormMapWithSetWarPlanes";
this.Text = "Карта с набором объектов";
this.groupBoxTools.ResumeLayout(false);
this.groupBoxTools.PerformLayout();
+ this.groupBoxMaps.ResumeLayout(false);
+ this.groupBoxMaps.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
this.ResumeLayout(false);
@@ -203,7 +260,6 @@
private GroupBox groupBoxTools;
private PictureBox pictureBox;
- private ComboBox comboBoxSelectorMap;
private Button buttonShowOnMap;
private Button buttonAddWarPlane;
private Button buttonDown;
@@ -213,5 +269,11 @@
private Button buttonShowStorage;
private Button buttonRemoveWarPlane;
private MaskedTextBox maskedTextBoxPosition;
+ private GroupBox groupBoxMaps;
+ private Button buttonAddMap;
+ private Button buttonDeleteMap;
+ private ListBox listBoxMaps;
+ private TextBox textBoxNewMapName;
+ private ComboBox comboBoxSelectorMap;
}
}
\ No newline at end of file
diff --git a/WarPlanes/WarPlanes/FormMapWithSetWarPlanes.cs b/WarPlanes/WarPlanes/FormMapWithSetWarPlanes.cs
index 2f2b50f..0ea95e4 100644
--- a/WarPlanes/WarPlanes/FormMapWithSetWarPlanes.cs
+++ b/WarPlanes/WarPlanes/FormMapWithSetWarPlanes.cs
@@ -3,41 +3,97 @@
public partial class FormMapWithSetWarPlanes : Form
{
///
- /// Объект от класса карты с набором объектов
+ /// Словарь для выпадающего списка
///
- private MapWithSetWarPlanesGeneric _mapWarPlanesCollectionGeneric;
+ private readonly Dictionary _mapsDict = new()
+ {
+ { "Простая карта", new SimpleMap() },
+ { "Закрытая карта", new CloseMap() }
+ };
+ ///
+ /// Объект от коллекции карт
+ ///
+ private readonly MapsCollection _mapsCollection;
///
/// Конструктор
///
public FormMapWithSetWarPlanes()
{
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 CloseMap();
- break;
+ return;
}
- if (map != null)
+
+ if (MessageBox.Show($"Удалить карту {listBoxMaps.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
- _mapWarPlanesCollectionGeneric = new MapWithSetWarPlanesGeneric(
- pictureBox.Width, pictureBox.Height, map);
- }
- else
- {
- _mapWarPlanesCollectionGeneric = null;
+ _mapsCollection.DelMap(listBoxMaps.SelectedItem?.ToString() ?? string.Empty);
+ ReloadMaps();
}
}
///
@@ -47,7 +103,7 @@
///
private void ButtonAddWarPlane_Click(object sender, EventArgs e)
{
- if(_mapWarPlanesCollectionGeneric == null)
+ if (listBoxMaps.SelectedIndex == -1)
{
return;
}
@@ -55,14 +111,14 @@
if (form.ShowDialog() == DialogResult.OK)
{
DrawningObjectWarPlane warplane = new(form.SelectedWarPlane);
- if (form.SelectedWarPlane == null || (_mapWarPlanesCollectionGeneric + warplane) == -1)
+ if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + warplane != -1)
{
- MessageBox.Show("Не удалось добавить объект");
+ MessageBox.Show("Объект добавлен");
+ pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
else
{
- MessageBox.Show("Объект добавлен");
- pictureBox.Image = _mapWarPlanesCollectionGeneric.ShowSet();
+ MessageBox.Show("Не удалось добавить объект");
}
}
}
@@ -73,6 +129,10 @@
///
private void ButtonRemoveWarPlane_Click(object sender, EventArgs e)
{
+ if (listBoxMaps.SelectedIndex == -1)
+ {
+ return;
+ }
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text))
{
return;
@@ -82,10 +142,10 @@
return;
}
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
- if (_mapWarPlanesCollectionGeneric - pos != null)
+ if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null)
{
MessageBox.Show("Объект удален");
- pictureBox.Image = _mapWarPlanesCollectionGeneric.ShowSet();
+ pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
else
{
@@ -99,11 +159,11 @@
///
private void ButtonShowStorage_Click(object sender, EventArgs e)
{
- if (_mapWarPlanesCollectionGeneric == null)
+ if (listBoxMaps.SelectedIndex == -1)
{
return;
}
- pictureBox.Image = _mapWarPlanesCollectionGeneric.ShowSet();
+ pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
///
/// Вывод карты
@@ -112,11 +172,11 @@
///
private void ButtonShowOnMap_Click(object sender, EventArgs e)
{
- if (_mapWarPlanesCollectionGeneric == null)
+ if (listBoxMaps.SelectedIndex == -1)
{
return;
}
- pictureBox.Image = _mapWarPlanesCollectionGeneric.ShowOnMap();
+ pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowOnMap();
}
///
/// Перемещение
@@ -125,7 +185,7 @@
///
private void ButtonMove_Click(object sender, EventArgs e)
{
- if (_mapWarPlanesCollectionGeneric == null)
+ if (listBoxMaps.SelectedIndex == -1)
{
return;
}
@@ -147,7 +207,7 @@
dir = Direction.Right;
break;
}
- pictureBox.Image = _mapWarPlanesCollectionGeneric.MoveObject(dir);
+ pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].MoveObject(dir);
}
}
}
\ No newline at end of file
diff --git a/WarPlanes/WarPlanes/FormWarPlane.Designer.cs b/WarPlanes/WarPlanes/FormWarPlane.Designer.cs
index 89a83cb..77a11c2 100644
--- a/WarPlanes/WarPlanes/FormWarPlane.Designer.cs
+++ b/WarPlanes/WarPlanes/FormWarPlane.Designer.cs
@@ -39,7 +39,7 @@
this.toolStripStatusLabelWeight = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusLabelBodyColor = new System.Windows.Forms.ToolStripStatusLabel();
this.buttonCreateModif = new System.Windows.Forms.Button();
- this.buttonSelectCar = new System.Windows.Forms.Button();
+ this.buttonSelectWarPlane = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxWarPlane)).BeginInit();
this.statusStrip.SuspendLayout();
this.SuspendLayout();
@@ -153,23 +153,23 @@
this.buttonCreateModif.UseVisualStyleBackColor = true;
this.buttonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_Click);
//
- // buttonSelectCar
+ // buttonSelectWarPlane
//
- this.buttonSelectCar.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
- this.buttonSelectCar.Location = new System.Drawing.Point(569, 390);
- this.buttonSelectCar.Name = "buttonSelectCar";
- this.buttonSelectCar.Size = new System.Drawing.Size(75, 23);
- this.buttonSelectCar.TabIndex = 15;
- this.buttonSelectCar.Text = "Выбрать";
- this.buttonSelectCar.UseVisualStyleBackColor = true;
- this.buttonSelectCar.Click += new System.EventHandler(this.ButtonSelectWarPlane_Click);
+ this.buttonSelectWarPlane.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
+ this.buttonSelectWarPlane.Location = new System.Drawing.Point(569, 390);
+ this.buttonSelectWarPlane.Name = "buttonSelectWarPlane";
+ this.buttonSelectWarPlane.Size = new System.Drawing.Size(75, 23);
+ this.buttonSelectWarPlane.TabIndex = 15;
+ this.buttonSelectWarPlane.Text = "Выбрать";
+ this.buttonSelectWarPlane.UseVisualStyleBackColor = true;
+ this.buttonSelectWarPlane.Click += new System.EventHandler(this.ButtonSelectWarPlane_Click);
//
// FormWarPlane
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
- this.Controls.Add(this.buttonSelectCar);
+ this.Controls.Add(this.buttonSelectWarPlane);
this.Controls.Add(this.buttonCreateModif);
this.Controls.Add(this.buttonDown);
this.Controls.Add(this.buttonRight);
@@ -201,6 +201,6 @@
private ToolStripStatusLabel toolStripStatusLabelWeight;
private ToolStripStatusLabel toolStripStatusLabelBodyColor;
private Button buttonCreateModif;
- private Button buttonSelectCar;
+ private Button buttonSelectWarPlane;
}
}
\ No newline at end of file
diff --git a/WarPlanes/WarPlanes/MapWithSetWarPlanesGeneric.cs b/WarPlanes/WarPlanes/MapWithSetWarPlanesGeneric.cs
index 687f8d4..c739395 100644
--- a/WarPlanes/WarPlanes/MapWithSetWarPlanesGeneric.cs
+++ b/WarPlanes/WarPlanes/MapWithSetWarPlanesGeneric.cs
@@ -87,14 +87,11 @@
public Bitmap ShowOnMap()
{
Shaking();
- for (int i = 0; i < _setWarPlanes.Count; i++)
+ foreach (var warplane in _setWarPlanes.GetWarPlanes())
{
- var warplane = _setWarPlanes.Get(i);
- if (warplane != null)
- {
- return _map.CreateMap(_pictureWidth, _pictureHeight, warplane);
- }
+ return _map.CreateMap(_pictureWidth, _pictureHeight, warplane);
}
+
return new(_pictureWidth, _pictureHeight);
}
///
@@ -118,11 +115,11 @@
int j = _setWarPlanes.Count - 1;
for (int i = 0; i < _setWarPlanes.Count; i++)
{
- if (_setWarPlanes.Get(i) == null)
+ if (_setWarPlanes[i] == null)
{
for (; j > i; j--)
{
- var warplane = _setWarPlanes.Get(j);
+ var warplane = _setWarPlanes[j];
if (warplane != null)
{
_setWarPlanes.Insert(warplane, i);
@@ -150,7 +147,6 @@
///
private void DrawBackground(Graphics g)
{
-
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
{
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
@@ -167,11 +163,12 @@
{
int countInLine = _pictureWidth / _placeSizeWidth;
int maxLeft = (countInLine - 1) * _placeSizeWidth;
- for (int i = 0; i < _setWarPlanes.Count; i++)
+ int i = 0;
+ foreach (var warplane in _setWarPlanes.GetWarPlanes())
{
- var warplane = _setWarPlanes.Get(i);
- warplane?.SetObject(maxLeft - i % countInLine * _placeSizeWidth +10, _pictureHeight - _placeSizeHeight - i / countInLine * _placeSizeHeight, _pictureWidth, _pictureHeight);
+ warplane?.SetObject(maxLeft - i % countInLine * _placeSizeWidth, _pictureHeight - _placeSizeHeight - i / countInLine * _placeSizeHeight - 50, _pictureWidth, _pictureHeight);
warplane?.DrawningObject(g);
+ i++;
}
}
}
diff --git a/WarPlanes/WarPlanes/MapsCollection.cs b/WarPlanes/WarPlanes/MapsCollection.cs
new file mode 100644
index 0000000..47df4fc
--- /dev/null
+++ b/WarPlanes/WarPlanes/MapsCollection.cs
@@ -0,0 +1,70 @@
+namespace AirFighter
+{
+ ///
+ /// Класс для хранения коллекции карт
+ ///
+ 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.TryGetValue(name, out var buffer);
+ if (buffer == null)
+ {
+ _mapStorages.Add(name, new(_pictureWidth, _pictureHeight, map));
+ }
+ }
+ ///
+ /// Удаление карты
+ ///
+ /// Название карты
+ public void DelMap(string name)
+ {
+ _mapStorages.Remove(name);
+ }
+ ///
+ /// Доступ к парковке
+ ///
+ ///
+ ///
+ public MapWithSetWarPlanesGeneric this[string ind]
+ {
+ get
+ {
+ _mapStorages.TryGetValue(ind, out var mapWithSetWarPlanesGeneric);
+ return mapWithSetWarPlanesGeneric;
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/WarPlanes/WarPlanes/SetWarPlanesGeneric.cs b/WarPlanes/WarPlanes/SetWarPlanesGeneric.cs
index 669f92f..1dfd5f2 100644
--- a/WarPlanes/WarPlanes/SetWarPlanesGeneric.cs
+++ b/WarPlanes/WarPlanes/SetWarPlanesGeneric.cs
@@ -10,18 +10,20 @@
///
/// Массив объектов, которые храним
///
- private readonly T[] _places;
+ private readonly List _places;
///
/// Количество объектов в массиве
///
- public int Count => _places.Length;
+ public int Count => _places.Count;
+ private readonly int _maxcount;
///
/// Конструктор
///
///
public SetWarPlanesGeneric(int count)
{
- _places = new T[count];
+ _places = new List();
+ _maxcount = count;
}
///
/// Добавление объекта в набор
@@ -34,7 +36,7 @@
}
private bool isCorrectPosition(int position)
{
- return 0 <= position && position < Count;
+ return 0 <= position && position < _maxcount;
}
///
/// Добавление объекта в набор на конкретную позицию
@@ -44,21 +46,11 @@
///
public int Insert(T warplane, 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] = warplane;
+ _places.Insert(position, warplane);
return position;
}
///
@@ -70,7 +62,7 @@
{
if (!isCorrectPosition(position)) return null;
var result = _places[position];
- _places[position] = null;
+ _places.RemoveAt(position);
return result;
}
///
@@ -78,10 +70,35 @@
///
///
///
- public T Get(int position)
+ public T this[int position]
{
- if (isCorrectPosition(position)) { return _places[position]; }
- else { return null; }
+ get
+ {
+ if(isCorrectPosition(position) && position < Count) return _places[position];
+ return null;
+ }
+ set
+ {
+ Insert(value, position);
+ }
+ }
+ ///
+ /// Проход по набору до первого пустого
+ ///
+ ///
+ public IEnumerable GetWarPlanes()
+ {
+ foreach (var warplane in _places)
+ {
+ if (warplane != null)
+ {
+ yield return warplane;
+ }
+ else
+ {
+ yield break;
+ }
+ }
}
}
}
\ No newline at end of file