Abazov A. A. LabWork04 #4
215
AirBomber/AirBomber/FormMapWithSetAirBombers.Designer.cs
generated
215
AirBomber/AirBomber/FormMapWithSetAirBombers.Designer.cs
generated
@ -29,23 +29,30 @@
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.groupBoxTools = new System.Windows.Forms.GroupBox();
|
||||
this.pictureBox = new System.Windows.Forms.PictureBox();
|
||||
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.buttonAddAirBomber = new System.Windows.Forms.Button();
|
||||
this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
|
||||
this.buttonRemoveAirBomber = new System.Windows.Forms.Button();
|
||||
this.buttonShowStorage = new System.Windows.Forms.Button();
|
||||
this.buttonShowOnMap = new System.Windows.Forms.Button();
|
||||
this.buttonRight = new System.Windows.Forms.Button();
|
||||
this.buttonDown = new System.Windows.Forms.Button();
|
||||
this.buttonLeft = new System.Windows.Forms.Button();
|
||||
this.buttonUp = new System.Windows.Forms.Button();
|
||||
this.buttonShowOnMap = new System.Windows.Forms.Button();
|
||||
this.buttonShowStorage = new System.Windows.Forms.Button();
|
||||
this.buttonRemoveAirBomber = new System.Windows.Forms.Button();
|
||||
this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
|
||||
this.buttonAddAirBomber = new System.Windows.Forms.Button();
|
||||
this.pictureBox = new System.Windows.Forms.PictureBox();
|
||||
this.groupBoxTools.SuspendLayout();
|
||||
this.groupBoxMaps.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// groupBoxTools
|
||||
//
|
||||
this.groupBoxTools.Controls.Add(this.groupBoxMaps);
|
||||
this.groupBoxTools.Controls.Add(this.buttonShowOnMap);
|
||||
this.groupBoxTools.Controls.Add(this.buttonRight);
|
||||
this.groupBoxTools.Controls.Add(this.buttonDown);
|
||||
@ -55,84 +62,99 @@
|
||||
this.groupBoxTools.Controls.Add(this.buttonRemoveAirBomber);
|
||||
this.groupBoxTools.Controls.Add(this.maskedTextBoxPosition);
|
||||
this.groupBoxTools.Controls.Add(this.buttonAddAirBomber);
|
||||
this.groupBoxTools.Controls.Add(this.comboBoxSelectorMap);
|
||||
this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right;
|
||||
this.groupBoxTools.Location = new System.Drawing.Point(621, 0);
|
||||
this.groupBoxTools.Name = "groupBoxTools";
|
||||
this.groupBoxTools.Size = new System.Drawing.Size(261, 453);
|
||||
this.groupBoxTools.Size = new System.Drawing.Size(261, 671);
|
||||
this.groupBoxTools.TabIndex = 0;
|
||||
this.groupBoxTools.TabStop = false;
|
||||
this.groupBoxTools.Text = "Инструменты";
|
||||
//
|
||||
// pictureBox
|
||||
// groupBoxMaps
|
||||
//
|
||||
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(621, 453);
|
||||
this.pictureBox.TabIndex = 1;
|
||||
this.pictureBox.TabStop = false;
|
||||
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(18, 34);
|
||||
this.groupBoxMaps.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.groupBoxMaps.Name = "groupBoxMaps";
|
||||
this.groupBoxMaps.Padding = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.groupBoxMaps.Size = new System.Drawing.Size(219, 331);
|
||||
this.groupBoxMaps.TabIndex = 20;
|
||||
this.groupBoxMaps.TabStop = false;
|
||||
this.groupBoxMaps.Text = "Карты";
|
||||
//
|
||||
// buttonAddMap
|
||||
//
|
||||
this.buttonAddMap.Location = new System.Drawing.Point(13, 107);
|
||||
this.buttonAddMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.buttonAddMap.Name = "buttonAddMap";
|
||||
this.buttonAddMap.Size = new System.Drawing.Size(200, 47);
|
||||
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(13, 275);
|
||||
this.buttonDeleteMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.buttonDeleteMap.Name = "buttonDeleteMap";
|
||||
this.buttonDeleteMap.Size = new System.Drawing.Size(200, 47);
|
||||
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 = 20;
|
||||
this.listBoxMaps.Location = new System.Drawing.Point(13, 161);
|
||||
this.listBoxMaps.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.listBoxMaps.Name = "listBoxMaps";
|
||||
this.listBoxMaps.Size = new System.Drawing.Size(199, 104);
|
||||
this.listBoxMaps.TabIndex = 3;
|
||||
this.listBoxMaps.SelectedIndexChanged += new System.EventHandler(this.listBoxMaps_SelectedIndexChanged);
|
||||
//
|
||||
// textBoxNewMapName
|
||||
//
|
||||
this.textBoxNewMapName.Location = new System.Drawing.Point(13, 29);
|
||||
this.textBoxNewMapName.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.textBoxNewMapName.Name = "textBoxNewMapName";
|
||||
this.textBoxNewMapName.Size = new System.Drawing.Size(199, 27);
|
||||
this.textBoxNewMapName.TabIndex = 0;
|
||||
//
|
||||
// comboBoxSelectorMap
|
||||
//
|
||||
this.comboBoxSelectorMap.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
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(19, 35);
|
||||
"Простая карта"});
|
||||
this.comboBoxSelectorMap.Location = new System.Drawing.Point(13, 68);
|
||||
this.comboBoxSelectorMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
|
||||
this.comboBoxSelectorMap.Size = new System.Drawing.Size(218, 28);
|
||||
this.comboBoxSelectorMap.TabIndex = 10;
|
||||
this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.comboBoxSelectorMap_SelectedIndexChanged);
|
||||
this.comboBoxSelectorMap.Size = new System.Drawing.Size(199, 28);
|
||||
this.comboBoxSelectorMap.TabIndex = 1;
|
||||
//
|
||||
// buttonAddAirBomber
|
||||
// buttonShowOnMap
|
||||
//
|
||||
this.buttonAddAirBomber.Location = new System.Drawing.Point(19, 109);
|
||||
this.buttonAddAirBomber.Name = "buttonAddAirBomber";
|
||||
this.buttonAddAirBomber.Size = new System.Drawing.Size(218, 41);
|
||||
this.buttonAddAirBomber.TabIndex = 11;
|
||||
this.buttonAddAirBomber.Text = "Добавить бомбардировщик";
|
||||
this.buttonAddAirBomber.UseVisualStyleBackColor = true;
|
||||
this.buttonAddAirBomber.Click += new System.EventHandler(this.buttonAddAirBomber_Click);
|
||||
//
|
||||
// maskedTextBoxPosition
|
||||
//
|
||||
this.maskedTextBoxPosition.Location = new System.Drawing.Point(19, 188);
|
||||
this.maskedTextBoxPosition.Mask = "00";
|
||||
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
|
||||
this.maskedTextBoxPosition.Size = new System.Drawing.Size(218, 27);
|
||||
this.maskedTextBoxPosition.TabIndex = 12;
|
||||
this.maskedTextBoxPosition.ValidatingType = typeof(int);
|
||||
//
|
||||
// buttonRemoveAirBomber
|
||||
//
|
||||
this.buttonRemoveAirBomber.Location = new System.Drawing.Point(19, 221);
|
||||
this.buttonRemoveAirBomber.Name = "buttonRemoveAirBomber";
|
||||
this.buttonRemoveAirBomber.Size = new System.Drawing.Size(218, 41);
|
||||
this.buttonRemoveAirBomber.TabIndex = 13;
|
||||
this.buttonRemoveAirBomber.Text = "Удалить бомбардировщик";
|
||||
this.buttonRemoveAirBomber.UseVisualStyleBackColor = true;
|
||||
this.buttonRemoveAirBomber.Click += new System.EventHandler(this.buttonRemoveAirBomber_Click);
|
||||
//
|
||||
// buttonShowStorage
|
||||
//
|
||||
this.buttonShowStorage.Location = new System.Drawing.Point(19, 281);
|
||||
this.buttonShowStorage.Name = "buttonShowStorage";
|
||||
this.buttonShowStorage.Size = new System.Drawing.Size(218, 41);
|
||||
this.buttonShowStorage.TabIndex = 14;
|
||||
this.buttonShowStorage.Text = "Посмотреть хранилище";
|
||||
this.buttonShowStorage.UseVisualStyleBackColor = true;
|
||||
this.buttonShowStorage.Click += new System.EventHandler(this.buttonShowStorage_Click);
|
||||
this.buttonShowOnMap.Location = new System.Drawing.Point(6, 546);
|
||||
this.buttonShowOnMap.Name = "buttonShowOnMap";
|
||||
this.buttonShowOnMap.Size = new System.Drawing.Size(243, 41);
|
||||
this.buttonShowOnMap.TabIndex = 19;
|
||||
this.buttonShowOnMap.Text = "Посмотреть карту";
|
||||
this.buttonShowOnMap.UseVisualStyleBackColor = true;
|
||||
this.buttonShowOnMap.Click += new System.EventHandler(this.buttonShowOnMap_Click);
|
||||
//
|
||||
// buttonRight
|
||||
//
|
||||
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonRight.BackgroundImage = global::AirBomber.Properties.Resources.arrowRight;
|
||||
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonRight.Location = new System.Drawing.Point(148, 411);
|
||||
this.buttonRight.Location = new System.Drawing.Point(148, 629);
|
||||
this.buttonRight.Name = "buttonRight";
|
||||
this.buttonRight.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonRight.TabIndex = 18;
|
||||
@ -144,7 +166,7 @@
|
||||
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonDown.BackgroundImage = global::AirBomber.Properties.Resources.arrowDown;
|
||||
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonDown.Location = new System.Drawing.Point(112, 411);
|
||||
this.buttonDown.Location = new System.Drawing.Point(112, 629);
|
||||
this.buttonDown.Name = "buttonDown";
|
||||
this.buttonDown.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonDown.TabIndex = 17;
|
||||
@ -156,7 +178,7 @@
|
||||
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonLeft.BackgroundImage = global::AirBomber.Properties.Resources.arrowLeft;
|
||||
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonLeft.Location = new System.Drawing.Point(76, 411);
|
||||
this.buttonLeft.Location = new System.Drawing.Point(76, 629);
|
||||
this.buttonLeft.Name = "buttonLeft";
|
||||
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonLeft.TabIndex = 16;
|
||||
@ -168,34 +190,74 @@
|
||||
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonUp.BackgroundImage = global::AirBomber.Properties.Resources.arrowUp;
|
||||
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonUp.Location = new System.Drawing.Point(112, 375);
|
||||
this.buttonUp.Location = new System.Drawing.Point(112, 593);
|
||||
this.buttonUp.Name = "buttonUp";
|
||||
this.buttonUp.Size = new System.Drawing.Size(30, 30);
|
||||
this.buttonUp.TabIndex = 15;
|
||||
this.buttonUp.UseVisualStyleBackColor = true;
|
||||
this.buttonUp.Click += new System.EventHandler(this.buttonMove_Click);
|
||||
//
|
||||
// buttonShowOnMap
|
||||
// buttonShowStorage
|
||||
//
|
||||
this.buttonShowOnMap.Location = new System.Drawing.Point(19, 328);
|
||||
this.buttonShowOnMap.Name = "buttonShowOnMap";
|
||||
this.buttonShowOnMap.Size = new System.Drawing.Size(218, 41);
|
||||
this.buttonShowOnMap.TabIndex = 19;
|
||||
this.buttonShowOnMap.Text = "Посмотреть карту";
|
||||
this.buttonShowOnMap.UseVisualStyleBackColor = true;
|
||||
this.buttonShowOnMap.Click += new System.EventHandler(this.buttonShowOnMap_Click);
|
||||
this.buttonShowStorage.Location = new System.Drawing.Point(6, 499);
|
||||
this.buttonShowStorage.Name = "buttonShowStorage";
|
||||
this.buttonShowStorage.Size = new System.Drawing.Size(243, 41);
|
||||
this.buttonShowStorage.TabIndex = 14;
|
||||
this.buttonShowStorage.Text = "Посмотреть хранилище";
|
||||
this.buttonShowStorage.UseVisualStyleBackColor = true;
|
||||
this.buttonShowStorage.Click += new System.EventHandler(this.buttonShowStorage_Click);
|
||||
//
|
||||
// buttonRemoveAirBomber
|
||||
//
|
||||
this.buttonRemoveAirBomber.Location = new System.Drawing.Point(6, 452);
|
||||
this.buttonRemoveAirBomber.Name = "buttonRemoveAirBomber";
|
||||
this.buttonRemoveAirBomber.Size = new System.Drawing.Size(243, 41);
|
||||
this.buttonRemoveAirBomber.TabIndex = 13;
|
||||
this.buttonRemoveAirBomber.Text = "Удалить бомбардировщик";
|
||||
this.buttonRemoveAirBomber.UseVisualStyleBackColor = true;
|
||||
this.buttonRemoveAirBomber.Click += new System.EventHandler(this.buttonRemoveAirBomber_Click);
|
||||
//
|
||||
// maskedTextBoxPosition
|
||||
//
|
||||
this.maskedTextBoxPosition.Location = new System.Drawing.Point(31, 419);
|
||||
this.maskedTextBoxPosition.Mask = "00";
|
||||
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
|
||||
this.maskedTextBoxPosition.Size = new System.Drawing.Size(199, 27);
|
||||
this.maskedTextBoxPosition.TabIndex = 12;
|
||||
this.maskedTextBoxPosition.ValidatingType = typeof(int);
|
||||
//
|
||||
// buttonAddAirBomber
|
||||
//
|
||||
this.buttonAddAirBomber.Location = new System.Drawing.Point(6, 372);
|
||||
this.buttonAddAirBomber.Name = "buttonAddAirBomber";
|
||||
this.buttonAddAirBomber.Size = new System.Drawing.Size(243, 41);
|
||||
this.buttonAddAirBomber.TabIndex = 11;
|
||||
this.buttonAddAirBomber.Text = "Добавить бомбардировщик";
|
||||
this.buttonAddAirBomber.UseVisualStyleBackColor = true;
|
||||
this.buttonAddAirBomber.Click += new System.EventHandler(this.buttonAddAirBomber_Click);
|
||||
//
|
||||
// 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(621, 671);
|
||||
this.pictureBox.TabIndex = 1;
|
||||
this.pictureBox.TabStop = false;
|
||||
//
|
||||
// FormMapWithSetAirBombers
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(882, 453);
|
||||
this.ClientSize = new System.Drawing.Size(882, 671);
|
||||
this.Controls.Add(this.pictureBox);
|
||||
this.Controls.Add(this.groupBoxTools);
|
||||
this.Name = "FormMapWithSetAirBombers";
|
||||
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);
|
||||
|
||||
@ -205,7 +267,6 @@
|
||||
|
||||
private GroupBox groupBoxTools;
|
||||
private PictureBox pictureBox;
|
||||
private ComboBox comboBoxSelectorMap;
|
||||
private MaskedTextBox maskedTextBoxPosition;
|
||||
private Button buttonAddAirBomber;
|
||||
private Button buttonShowStorage;
|
||||
@ -215,5 +276,11 @@
|
||||
private Button buttonLeft;
|
||||
private Button buttonUp;
|
||||
private Button buttonShowOnMap;
|
||||
private GroupBox groupBoxMaps;
|
||||
private Button buttonAddMap;
|
||||
private Button buttonDeleteMap;
|
||||
private ListBox listBoxMaps;
|
||||
private TextBox textBoxNewMapName;
|
||||
private ComboBox comboBoxSelectorMap;
|
||||
}
|
||||
}
|
@ -14,44 +14,33 @@ namespace AirBomber
|
||||
public partial class FormMapWithSetAirBombers : Form
|
||||
{
|
||||
/// <summary>
|
||||
/// Объект от класса карты с набором объектов
|
||||
/// Словарь для выпадающего списка
|
||||
/// </summary>
|
||||
private MapWithSetAirBombersGeneric<DrawingObjectAirBomber, AbstractMap> _mapAirBombersCollectionGeneric;
|
||||
private readonly Dictionary<string, AbstractMap> _mapsDict = new()
|
||||
{
|
||||
{ "Простая карта", new SimpleMap() },
|
||||
{"Городская карта", new CityMap() },
|
||||
{"Линейная карта", new LineMap() }
|
||||
};
|
||||
/// <summary>
|
||||
/// Объект от коллекции карт
|
||||
/// </summary>
|
||||
private readonly MapsCollection _mapsCollection;
|
||||
|
||||
public FormMapWithSetAirBombers()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void comboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
AbstractMap map = null;
|
||||
switch (comboBoxSelectorMap.Text)
|
||||
_mapsCollection = new MapsCollection(pictureBox.Width, pictureBox.Height);
|
||||
comboBoxSelectorMap.Items.Clear();
|
||||
foreach (var elem in _mapsDict)
|
||||
{
|
||||
case "Простая карта":
|
||||
map = new SimpleMap();
|
||||
break;
|
||||
case "Городская карта":
|
||||
map = new CityMap();
|
||||
break;
|
||||
case "Линейная карта":
|
||||
map = new LineMap();
|
||||
break;
|
||||
}
|
||||
if (map != null)
|
||||
{
|
||||
_mapAirBombersCollectionGeneric = new MapWithSetAirBombersGeneric<DrawingObjectAirBomber, AbstractMap>(
|
||||
pictureBox.Width, pictureBox.Height, map);
|
||||
}
|
||||
else
|
||||
{
|
||||
_mapAirBombersCollectionGeneric = null;
|
||||
comboBoxSelectorMap.Items.Add(elem.Key);
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonAddAirBomber_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_mapAirBombersCollectionGeneric == null)
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -59,10 +48,10 @@ namespace AirBomber
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
DrawingObjectAirBomber airBomber = new(form.SelectedAirBomber);
|
||||
if (_mapAirBombersCollectionGeneric + airBomber != -1)
|
||||
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + airBomber != -1)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBox.Image = _mapAirBombersCollectionGeneric.ShowSet();
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -73,6 +62,10 @@ namespace AirBomber
|
||||
|
||||
private void buttonRemoveAirBomber_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text))
|
||||
{
|
||||
return;
|
||||
@ -82,10 +75,10 @@ namespace AirBomber
|
||||
return;
|
||||
}
|
||||
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
|
||||
if (_mapAirBombersCollectionGeneric - pos != null)
|
||||
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBox.Image = _mapAirBombersCollectionGeneric.ShowSet();
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -95,20 +88,20 @@ namespace AirBomber
|
||||
|
||||
private void buttonShowStorage_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_mapAirBombersCollectionGeneric == null)
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
pictureBox.Image = _mapAirBombersCollectionGeneric.ShowSet();
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
|
||||
private void buttonShowOnMap_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_mapAirBombersCollectionGeneric == null)
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
pictureBox.Image = _mapAirBombersCollectionGeneric.ShowOnMap();
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowOnMap();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -136,7 +129,61 @@ namespace AirBomber
|
||||
dir = Direction.Right;
|
||||
break;
|
||||
}
|
||||
pictureBox.Image = _mapAirBombersCollectionGeneric?.MoveObject(dir);
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].MoveObject(dir);
|
||||
}
|
||||
|
||||
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 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -53,11 +53,11 @@ namespace AirBomber
|
||||
/// Перегрузка оператора сложения
|
||||
/// </summary>
|
||||
/// <param name="map"></param>
|
||||
/// <param name="car"></param>
|
||||
/// <param name="airBomber"></param>
|
||||
/// <returns></returns>
|
||||
public static int operator +(MapWithSetAirBombersGeneric<T, U> map, T car)
|
||||
public static int operator +(MapWithSetAirBombersGeneric<T, U> map, T airBomber)
|
||||
{
|
||||
return map._setAirBombers.Insert(car);
|
||||
return map._setAirBombers.Insert(airBomber);
|
||||
}
|
||||
/// <summary>
|
||||
/// Перегрузка оператора вычитания
|
||||
@ -88,13 +88,9 @@ namespace AirBomber
|
||||
public Bitmap ShowOnMap()
|
||||
{
|
||||
Shaking();
|
||||
for (int i = 0; i < _setAirBombers.Count; i++)
|
||||
foreach (var airBomber in _setAirBombers.GetAirBombers())
|
||||
{
|
||||
var airBomber = _setAirBombers.Get(i);
|
||||
if (airBomber != null)
|
||||
{
|
||||
return _map.CreateMap(_pictureWidth, _pictureHeight, airBomber);
|
||||
}
|
||||
return _map.CreateMap(_pictureWidth, _pictureHeight, airBomber);
|
||||
}
|
||||
return new(_pictureWidth, _pictureHeight);
|
||||
}
|
||||
@ -119,11 +115,11 @@ namespace AirBomber
|
||||
int j = _setAirBombers.Count - 1;
|
||||
for (int i = 0; i < _setAirBombers.Count; i++)
|
||||
{
|
||||
if (_setAirBombers.Get(i) == null)
|
||||
if (_setAirBombers[i] == null)
|
||||
{
|
||||
for (; j > i; j--)
|
||||
{
|
||||
var car = _setAirBombers.Get(j);
|
||||
var car = _setAirBombers[j];
|
||||
if (car != null)
|
||||
{
|
||||
_setAirBombers.Insert(car, i);
|
||||
@ -163,10 +159,12 @@ namespace AirBomber
|
||||
private void DrawAirBombers(Graphics g)
|
||||
{
|
||||
int numOfObjectsInRow = _pictureWidth / _placeSizeWidth;
|
||||
for (int i = 0; i < _setAirBombers.Count; i++)
|
||||
int i = 0;
|
||||
foreach (var airBomber in _setAirBombers.GetAirBombers())
|
||||
{
|
||||
_setAirBombers.Get(i)?.SetObject((numOfObjectsInRow - (i % numOfObjectsInRow) - 1) * _placeSizeWidth, (i / numOfObjectsInRow) * _placeSizeHeight, _pictureWidth, _pictureHeight);
|
||||
_setAirBombers.Get(i)?.DrawingObject(g);
|
||||
airBomber.SetObject((numOfObjectsInRow - (i % numOfObjectsInRow) - 1) * _placeSizeWidth, (i / numOfObjectsInRow) * _placeSizeHeight, _pictureWidth, _pictureHeight);
|
||||
airBomber.DrawingObject(g);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
77
AirBomber/AirBomber/MapsCollection.cs
Normal file
77
AirBomber/AirBomber/MapsCollection.cs
Normal file
@ -0,0 +1,77 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AirBomber
|
||||
{
|
||||
internal class MapsCollection
|
||||
{
|
||||
/// <summary>
|
||||
/// Словарь (хранилище) с картами
|
||||
/// </summary>
|
||||
readonly Dictionary<string, MapWithSetAirBombersGeneric<DrawingObjectAirBomber, 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, MapWithSetAirBombersGeneric<DrawingObjectAirBomber, AbstractMap>>();
|
||||
_pictureWidth = pictureWidth;
|
||||
_pictureHeight = pictureHeight;
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление карты
|
||||
/// </summary>
|
||||
/// <param name="name">Название карты</param>
|
||||
/// <param name="map">Карта</param>
|
||||
public void AddMap(string name, AbstractMap map)
|
||||
{
|
||||
if (_mapStorages.ContainsKey(name))
|
||||
{
|
||||
MessageBox.Show("Карта с таким названием уже существует!");
|
||||
|
||||
return;
|
||||
}
|
||||
_mapStorages.Add(name, new MapWithSetAirBombersGeneric<DrawingObjectAirBomber, AbstractMap>(_pictureWidth, _pictureHeight, map));
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление карты
|
||||
/// </summary>
|
||||
/// <param name="name">Название карты</param>
|
||||
public void DelMap(string name)
|
||||
{
|
||||
if (_mapStorages.ContainsKey(name))
|
||||
{
|
||||
_mapStorages.Remove(name);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Доступ к парковке
|
||||
/// </summary>
|
||||
/// <param name="ind"></param>
|
||||
/// <returns></returns>
|
||||
public MapWithSetAirBombersGeneric<DrawingObjectAirBomber, AbstractMap> this[string ind]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_mapStorages.ContainsKey(ind)) return _mapStorages[ind];
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -10,20 +10,24 @@ namespace AirBomber
|
||||
where T : class
|
||||
{
|
||||
/// <summary>
|
||||
/// Массив объектов, которые храним
|
||||
/// Список объектов, которые храним
|
||||
/// </summary>
|
||||
private readonly T[] _places;
|
||||
private readonly List<T> _places;
|
||||
/// <summary>
|
||||
/// Количество объектов в массиве
|
||||
/// Количество объектов в списке
|
||||
/// </summary>
|
||||
public int Count => _places.Length;
|
||||
public int Count => _places.Count;
|
||||
|
||||
private readonly int _maxCount;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="count"></param>
|
||||
///
|
||||
public SetAirBombersGeneric(int count)
|
||||
{
|
||||
_places = new T[count];
|
||||
_maxCount = count;
|
||||
_places = new List<T>();
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор
|
||||
@ -32,7 +36,9 @@ namespace AirBomber
|
||||
/// <returns></returns>
|
||||
public int Insert(T airBomber)
|
||||
{
|
||||
return Insert(airBomber, 0);
|
||||
if (_places.Count + 1 >= _maxCount) return -1;
|
||||
_places.Insert(0, airBomber);
|
||||
return 0;
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор на конкретную позицию
|
||||
@ -42,30 +48,9 @@ namespace AirBomber
|
||||
/// <returns></returns>
|
||||
public int Insert(T airBomber, int position)
|
||||
{
|
||||
if (position >= _places.Length)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if (_places[position] != null)
|
||||
{
|
||||
int indexNull = -1;
|
||||
for (int i = position; i < _places.Length; i++)
|
||||
{
|
||||
if (_places[i] == null)
|
||||
{
|
||||
indexNull = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (indexNull == -1) return -1;
|
||||
for (int i = indexNull; i > position; i--)
|
||||
{
|
||||
T tmp = _places[i];
|
||||
_places[i] = _places[i - 1];
|
||||
_places[i - 1] = tmp;
|
||||
}
|
||||
}
|
||||
_places[position] = airBomber;
|
||||
if (position < 0 || position >= _maxCount) return -1;
|
||||
if (_places.Count + 1 >= _maxCount) return -1;
|
||||
_places.Insert(position, airBomber);
|
||||
return position;
|
||||
}
|
||||
/// <summary>
|
||||
@ -75,12 +60,9 @@ namespace AirBomber
|
||||
/// <returns></returns>
|
||||
public T Remove(int position)
|
||||
{
|
||||
if (position >= _places.Length)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (position < 0 || position >= _maxCount) return null;
|
||||
T removedObject = _places[position];
|
||||
_places[position] = null;
|
||||
_places.RemoveAt(position);
|
||||
return removedObject;
|
||||
}
|
||||
/// <summary>
|
||||
@ -88,13 +70,36 @@ namespace AirBomber
|
||||
/// </summary>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public T Get(int position)
|
||||
public T this[int position]
|
||||
{
|
||||
if (position >= _places.Length)
|
||||
get
|
||||
{
|
||||
return null;
|
||||
if (position < 0 || position >= _maxCount) return null;
|
||||
return _places[position];
|
||||
}
|
||||
set
|
||||
{
|
||||
if (position < 0 || position >= _maxCount) Insert(value, position);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Проход по набору до первого пустого
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public IEnumerable<T> GetAirBombers()
|
||||
{
|
||||
foreach (var airBomber in _places)
|
||||
{
|
||||
if (airBomber != null)
|
||||
{
|
||||
yield return airBomber;
|
||||
}
|
||||
else
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
return _places[position];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user
В классе с логикой не выводят сообщения