Merge branch 'Lab3' of http://student.git.athene.tech/d.agliullov/ISEbd-21_Agliullov.D.A._AirBomber.Advanced into Lab3
This commit is contained in:
commit
6d0fc2ec46
@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace AirBomber
|
namespace AirBomber
|
||||||
{
|
{
|
||||||
internal class DrawningObject : IDrawningObject
|
public class DrawningObject : IDrawningObject
|
||||||
{
|
{
|
||||||
private DrawningAirplane _airplane;
|
private DrawningAirplane _airplane;
|
||||||
|
|
||||||
@ -29,12 +29,19 @@ namespace AirBomber
|
|||||||
|
|
||||||
public void SetObject(int x, int y, int width, int height)
|
public void SetObject(int x, int y, int width, int height)
|
||||||
{
|
{
|
||||||
_airplane.SetPosition(x, y, width, height);
|
_airplane?.SetPosition(x, y, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DrawObject(Graphics g)
|
public void DrawObject(Graphics g)
|
||||||
{
|
{
|
||||||
_airplane.DrawTransport(g);
|
_airplane.DrawTransport(g);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Получения самолета из объекта отрисовки
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="drawningObject">The drawning object.</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static explicit operator DrawningAirplane(DrawningObject drawningObject) => drawningObject._airplane;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,11 +8,13 @@ namespace AirBomber
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Âűáđŕííűé ńŕěîëĺň
|
/// Âűáđŕííűé ńŕěîëĺň
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public DrawningAirplane SelectedAirplane { get; private set; }
|
public DrawningObject SelectedAirplane { get; private set; }
|
||||||
|
|
||||||
public FormAirBomber()
|
public FormAirBomber(DrawningAirplane? airplane = null)
|
||||||
{
|
{
|
||||||
|
_airplane = airplane;
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
Draw();
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ěĺňîä ďđîđčńîâęč ěŕřčíű
|
/// Ěĺňîä ďđîđčńîâęč ěŕřčíű
|
||||||
@ -22,6 +24,7 @@ namespace AirBomber
|
|||||||
Bitmap bmp = new(pictureBoxCar.Width, pictureBoxCar.Height);
|
Bitmap bmp = new(pictureBoxCar.Width, pictureBoxCar.Height);
|
||||||
Graphics gr = Graphics.FromImage(bmp);
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
_airplane?.DrawTransport(gr);
|
_airplane?.DrawTransport(gr);
|
||||||
|
|
||||||
pictureBoxCar.Image = bmp;
|
pictureBoxCar.Image = bmp;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -99,7 +102,7 @@ namespace AirBomber
|
|||||||
|
|
||||||
private void buttonSelectAirplane_Click(object sender, EventArgs e)
|
private void buttonSelectAirplane_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
SelectedAirplane = _airplane;
|
SelectedAirplane = new(_airplane);
|
||||||
DialogResult = DialogResult.OK;
|
DialogResult = DialogResult.OK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
144
AirBomber/AirBomber/FormMapWithSetAirplanes.Designer.cs
generated
144
AirBomber/AirBomber/FormMapWithSetAirplanes.Designer.cs
generated
@ -30,6 +30,13 @@
|
|||||||
{
|
{
|
||||||
this.comboTypeEngines = new System.Windows.Forms.ComboBox();
|
this.comboTypeEngines = new System.Windows.Forms.ComboBox();
|
||||||
this.groupBoxTools = new System.Windows.Forms.GroupBox();
|
this.groupBoxTools = new System.Windows.Forms.GroupBox();
|
||||||
|
this.btnAddDeletedObject = new System.Windows.Forms.Button();
|
||||||
|
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.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
|
||||||
this.buttonRemoveAirplane = new System.Windows.Forms.Button();
|
this.buttonRemoveAirplane = new System.Windows.Forms.Button();
|
||||||
this.buttonShowStorage = new System.Windows.Forms.Button();
|
this.buttonShowStorage = new System.Windows.Forms.Button();
|
||||||
@ -47,11 +54,11 @@
|
|||||||
this.btnGenerateAirplane = new System.Windows.Forms.Button();
|
this.btnGenerateAirplane = new System.Windows.Forms.Button();
|
||||||
this.buttonDown = new System.Windows.Forms.Button();
|
this.buttonDown = new System.Windows.Forms.Button();
|
||||||
this.buttonRight = new System.Windows.Forms.Button();
|
this.buttonRight = new System.Windows.Forms.Button();
|
||||||
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
|
|
||||||
this.buttonLeft = new System.Windows.Forms.Button();
|
this.buttonLeft = new System.Windows.Forms.Button();
|
||||||
this.buttonUp = new System.Windows.Forms.Button();
|
this.buttonUp = new System.Windows.Forms.Button();
|
||||||
this.pictureBox = new System.Windows.Forms.PictureBox();
|
this.pictureBox = new System.Windows.Forms.PictureBox();
|
||||||
this.groupBoxTools.SuspendLayout();
|
this.groupBoxTools.SuspendLayout();
|
||||||
|
this.groupBoxMaps.SuspendLayout();
|
||||||
this.groupBoxGenerate.SuspendLayout();
|
this.groupBoxGenerate.SuspendLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.numericSpeed)).BeginInit();
|
((System.ComponentModel.ISupportInitialize)(this.numericSpeed)).BeginInit();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.numericUpDownEngines)).BeginInit();
|
((System.ComponentModel.ISupportInitialize)(this.numericUpDownEngines)).BeginInit();
|
||||||
@ -74,6 +81,8 @@
|
|||||||
//
|
//
|
||||||
// groupBoxTools
|
// groupBoxTools
|
||||||
//
|
//
|
||||||
|
this.groupBoxTools.Controls.Add(this.btnAddDeletedObject);
|
||||||
|
this.groupBoxTools.Controls.Add(this.groupBoxMaps);
|
||||||
this.groupBoxTools.Controls.Add(this.maskedTextBoxPosition);
|
this.groupBoxTools.Controls.Add(this.maskedTextBoxPosition);
|
||||||
this.groupBoxTools.Controls.Add(this.buttonRemoveAirplane);
|
this.groupBoxTools.Controls.Add(this.buttonRemoveAirplane);
|
||||||
this.groupBoxTools.Controls.Add(this.buttonShowStorage);
|
this.groupBoxTools.Controls.Add(this.buttonShowStorage);
|
||||||
@ -82,20 +91,92 @@
|
|||||||
this.groupBoxTools.Controls.Add(this.groupBoxGenerate);
|
this.groupBoxTools.Controls.Add(this.groupBoxGenerate);
|
||||||
this.groupBoxTools.Controls.Add(this.buttonDown);
|
this.groupBoxTools.Controls.Add(this.buttonDown);
|
||||||
this.groupBoxTools.Controls.Add(this.buttonRight);
|
this.groupBoxTools.Controls.Add(this.buttonRight);
|
||||||
this.groupBoxTools.Controls.Add(this.comboBoxSelectorMap);
|
|
||||||
this.groupBoxTools.Controls.Add(this.buttonLeft);
|
this.groupBoxTools.Controls.Add(this.buttonLeft);
|
||||||
this.groupBoxTools.Controls.Add(this.buttonUp);
|
this.groupBoxTools.Controls.Add(this.buttonUp);
|
||||||
this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right;
|
this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right;
|
||||||
this.groupBoxTools.Location = new System.Drawing.Point(811, 0);
|
this.groupBoxTools.Location = new System.Drawing.Point(811, 0);
|
||||||
this.groupBoxTools.Name = "groupBoxTools";
|
this.groupBoxTools.Name = "groupBoxTools";
|
||||||
this.groupBoxTools.Size = new System.Drawing.Size(204, 594);
|
this.groupBoxTools.Size = new System.Drawing.Size(204, 810);
|
||||||
this.groupBoxTools.TabIndex = 0;
|
this.groupBoxTools.TabIndex = 0;
|
||||||
this.groupBoxTools.TabStop = false;
|
this.groupBoxTools.TabStop = false;
|
||||||
this.groupBoxTools.Text = "Инструменты";
|
this.groupBoxTools.Text = "Инструменты";
|
||||||
//
|
//
|
||||||
|
// btnAddDeletedObject
|
||||||
|
//
|
||||||
|
this.btnAddDeletedObject.Location = new System.Drawing.Point(17, 689);
|
||||||
|
this.btnAddDeletedObject.Name = "btnAddDeletedObject";
|
||||||
|
this.btnAddDeletedObject.Size = new System.Drawing.Size(175, 45);
|
||||||
|
this.btnAddDeletedObject.TabIndex = 27;
|
||||||
|
this.btnAddDeletedObject.Text = "Добавить удаленный самолет";
|
||||||
|
this.btnAddDeletedObject.UseVisualStyleBackColor = true;
|
||||||
|
this.btnAddDeletedObject.Click += new System.EventHandler(this.btnAddDeletedObject_Click);
|
||||||
|
//
|
||||||
|
// 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, 267);
|
||||||
|
this.groupBoxMaps.Name = "groupBoxMaps";
|
||||||
|
this.groupBoxMaps.Size = new System.Drawing.Size(192, 248);
|
||||||
|
this.groupBoxMaps.TabIndex = 26;
|
||||||
|
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 = 0;
|
||||||
|
//
|
||||||
// maskedTextBoxPosition
|
// maskedTextBoxPosition
|
||||||
//
|
//
|
||||||
this.maskedTextBoxPosition.Location = new System.Drawing.Point(23, 317);
|
this.maskedTextBoxPosition.Location = new System.Drawing.Point(17, 565);
|
||||||
this.maskedTextBoxPosition.Mask = "00";
|
this.maskedTextBoxPosition.Mask = "00";
|
||||||
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
|
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
|
||||||
this.maskedTextBoxPosition.Size = new System.Drawing.Size(175, 23);
|
this.maskedTextBoxPosition.Size = new System.Drawing.Size(175, 23);
|
||||||
@ -104,9 +185,9 @@
|
|||||||
//
|
//
|
||||||
// buttonRemoveAirplane
|
// buttonRemoveAirplane
|
||||||
//
|
//
|
||||||
this.buttonRemoveAirplane.Location = new System.Drawing.Point(23, 346);
|
this.buttonRemoveAirplane.Location = new System.Drawing.Point(17, 594);
|
||||||
this.buttonRemoveAirplane.Name = "buttonRemoveAirplane";
|
this.buttonRemoveAirplane.Name = "buttonRemoveAirplane";
|
||||||
this.buttonRemoveAirplane.Size = new System.Drawing.Size(175, 35);
|
this.buttonRemoveAirplane.Size = new System.Drawing.Size(175, 26);
|
||||||
this.buttonRemoveAirplane.TabIndex = 23;
|
this.buttonRemoveAirplane.TabIndex = 23;
|
||||||
this.buttonRemoveAirplane.Text = "Удалить самолет";
|
this.buttonRemoveAirplane.Text = "Удалить самолет";
|
||||||
this.buttonRemoveAirplane.UseVisualStyleBackColor = true;
|
this.buttonRemoveAirplane.UseVisualStyleBackColor = true;
|
||||||
@ -114,9 +195,9 @@
|
|||||||
//
|
//
|
||||||
// buttonShowStorage
|
// buttonShowStorage
|
||||||
//
|
//
|
||||||
this.buttonShowStorage.Location = new System.Drawing.Point(23, 387);
|
this.buttonShowStorage.Location = new System.Drawing.Point(17, 626);
|
||||||
this.buttonShowStorage.Name = "buttonShowStorage";
|
this.buttonShowStorage.Name = "buttonShowStorage";
|
||||||
this.buttonShowStorage.Size = new System.Drawing.Size(175, 35);
|
this.buttonShowStorage.Size = new System.Drawing.Size(175, 26);
|
||||||
this.buttonShowStorage.TabIndex = 24;
|
this.buttonShowStorage.TabIndex = 24;
|
||||||
this.buttonShowStorage.Text = "Посмотреть хранилище";
|
this.buttonShowStorage.Text = "Посмотреть хранилище";
|
||||||
this.buttonShowStorage.UseVisualStyleBackColor = true;
|
this.buttonShowStorage.UseVisualStyleBackColor = true;
|
||||||
@ -124,9 +205,9 @@
|
|||||||
//
|
//
|
||||||
// buttonShowOnMap
|
// buttonShowOnMap
|
||||||
//
|
//
|
||||||
this.buttonShowOnMap.Location = new System.Drawing.Point(23, 424);
|
this.buttonShowOnMap.Location = new System.Drawing.Point(17, 658);
|
||||||
this.buttonShowOnMap.Name = "buttonShowOnMap";
|
this.buttonShowOnMap.Name = "buttonShowOnMap";
|
||||||
this.buttonShowOnMap.Size = new System.Drawing.Size(175, 35);
|
this.buttonShowOnMap.Size = new System.Drawing.Size(175, 25);
|
||||||
this.buttonShowOnMap.TabIndex = 25;
|
this.buttonShowOnMap.TabIndex = 25;
|
||||||
this.buttonShowOnMap.Text = "Посмотреть карту";
|
this.buttonShowOnMap.Text = "Посмотреть карту";
|
||||||
this.buttonShowOnMap.UseVisualStyleBackColor = true;
|
this.buttonShowOnMap.UseVisualStyleBackColor = true;
|
||||||
@ -134,7 +215,7 @@
|
|||||||
//
|
//
|
||||||
// buttonAddAirplane
|
// buttonAddAirplane
|
||||||
//
|
//
|
||||||
this.buttonAddAirplane.Location = new System.Drawing.Point(23, 273);
|
this.buttonAddAirplane.Location = new System.Drawing.Point(17, 521);
|
||||||
this.buttonAddAirplane.Name = "buttonAddAirplane";
|
this.buttonAddAirplane.Name = "buttonAddAirplane";
|
||||||
this.buttonAddAirplane.Size = new System.Drawing.Size(175, 35);
|
this.buttonAddAirplane.Size = new System.Drawing.Size(175, 35);
|
||||||
this.buttonAddAirplane.TabIndex = 21;
|
this.buttonAddAirplane.TabIndex = 21;
|
||||||
@ -244,78 +325,71 @@
|
|||||||
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
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.BackgroundImage = global::AirBomber.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(91, 544);
|
this.buttonDown.Location = new System.Drawing.Point(90, 774);
|
||||||
this.buttonDown.Name = "buttonDown";
|
this.buttonDown.Name = "buttonDown";
|
||||||
this.buttonDown.Size = new System.Drawing.Size(30, 30);
|
this.buttonDown.Size = new System.Drawing.Size(30, 30);
|
||||||
this.buttonDown.TabIndex = 10;
|
this.buttonDown.TabIndex = 10;
|
||||||
this.buttonDown.UseVisualStyleBackColor = true;
|
this.buttonDown.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||||
//
|
//
|
||||||
// buttonRight
|
// buttonRight
|
||||||
//
|
//
|
||||||
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
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.BackgroundImage = global::AirBomber.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(127, 544);
|
this.buttonRight.Location = new System.Drawing.Point(126, 774);
|
||||||
this.buttonRight.Name = "buttonRight";
|
this.buttonRight.Name = "buttonRight";
|
||||||
this.buttonRight.Size = new System.Drawing.Size(30, 30);
|
this.buttonRight.Size = new System.Drawing.Size(30, 30);
|
||||||
this.buttonRight.TabIndex = 9;
|
this.buttonRight.TabIndex = 9;
|
||||||
this.buttonRight.UseVisualStyleBackColor = true;
|
this.buttonRight.UseVisualStyleBackColor = true;
|
||||||
//
|
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_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(23, 465);
|
|
||||||
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);
|
|
||||||
//
|
//
|
||||||
// buttonLeft
|
// buttonLeft
|
||||||
//
|
//
|
||||||
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
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.BackgroundImage = global::AirBomber.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(55, 544);
|
this.buttonLeft.Location = new System.Drawing.Point(54, 774);
|
||||||
this.buttonLeft.Name = "buttonLeft";
|
this.buttonLeft.Name = "buttonLeft";
|
||||||
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
|
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
|
||||||
this.buttonLeft.TabIndex = 8;
|
this.buttonLeft.TabIndex = 8;
|
||||||
this.buttonLeft.UseVisualStyleBackColor = true;
|
this.buttonLeft.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||||
//
|
//
|
||||||
// buttonUp
|
// buttonUp
|
||||||
//
|
//
|
||||||
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
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.BackgroundImage = global::AirBomber.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(91, 508);
|
this.buttonUp.Location = new System.Drawing.Point(90, 738);
|
||||||
this.buttonUp.Name = "buttonUp";
|
this.buttonUp.Name = "buttonUp";
|
||||||
this.buttonUp.Size = new System.Drawing.Size(30, 30);
|
this.buttonUp.Size = new System.Drawing.Size(30, 30);
|
||||||
this.buttonUp.TabIndex = 7;
|
this.buttonUp.TabIndex = 7;
|
||||||
this.buttonUp.UseVisualStyleBackColor = true;
|
this.buttonUp.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
|
||||||
//
|
//
|
||||||
// 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(811, 594);
|
this.pictureBox.Size = new System.Drawing.Size(811, 810);
|
||||||
this.pictureBox.TabIndex = 1;
|
this.pictureBox.TabIndex = 1;
|
||||||
this.pictureBox.TabStop = false;
|
this.pictureBox.TabStop = false;
|
||||||
//
|
//
|
||||||
// FormGeneratorAirplane
|
// FormMapWithSetAirplanes
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
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(1015, 594);
|
this.ClientSize = new System.Drawing.Size(1015, 810);
|
||||||
this.Controls.Add(this.pictureBox);
|
this.Controls.Add(this.pictureBox);
|
||||||
this.Controls.Add(this.groupBoxTools);
|
this.Controls.Add(this.groupBoxTools);
|
||||||
this.Name = "FormGeneratorAirplane";
|
this.Name = "FormMapWithSetAirplanes";
|
||||||
this.Text = "Генератор самолетов";
|
this.Text = "Генератор самолетов";
|
||||||
this.groupBoxTools.ResumeLayout(false);
|
this.groupBoxTools.ResumeLayout(false);
|
||||||
this.groupBoxTools.PerformLayout();
|
this.groupBoxTools.PerformLayout();
|
||||||
|
this.groupBoxMaps.ResumeLayout(false);
|
||||||
|
this.groupBoxMaps.PerformLayout();
|
||||||
this.groupBoxGenerate.ResumeLayout(false);
|
this.groupBoxGenerate.ResumeLayout(false);
|
||||||
this.groupBoxGenerate.PerformLayout();
|
this.groupBoxGenerate.PerformLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.numericSpeed)).EndInit();
|
((System.ComponentModel.ISupportInitialize)(this.numericSpeed)).EndInit();
|
||||||
@ -351,5 +425,11 @@
|
|||||||
private Button buttonShowStorage;
|
private Button buttonShowStorage;
|
||||||
private Button buttonShowOnMap;
|
private Button buttonShowOnMap;
|
||||||
private Button buttonAddAirplane;
|
private Button buttonAddAirplane;
|
||||||
|
private GroupBox groupBoxMaps;
|
||||||
|
private Button buttonAddMap;
|
||||||
|
private Button buttonDeleteMap;
|
||||||
|
private ListBox listBoxMaps;
|
||||||
|
private TextBox textBoxNewMapName;
|
||||||
|
private Button btnAddDeletedObject;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -5,59 +5,130 @@ namespace AirBomber
|
|||||||
public partial class FormMapWithSetAirplanes : Form
|
public partial class FormMapWithSetAirplanes : Form
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Объект от класса карты с набором объектов
|
/// Словарь для выпадающего списка
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private MapWithSetAirplanesGeneric<DrawningObject, AbstractMap> _mapAirplanesCollectionGeneric;
|
private readonly Dictionary<string, AbstractMap> _mapsDict = new()
|
||||||
|
{
|
||||||
|
{ "Простая карта", new SimpleMap() },
|
||||||
|
{ "Карта со стенами", new WallMap() },
|
||||||
|
};
|
||||||
|
/// <summary>
|
||||||
|
/// Объект от коллекции карт
|
||||||
|
/// </summary>
|
||||||
|
private readonly MapsCollection _mapsCollection;
|
||||||
private GeneratorAirplane<EntityAirplane, IAirplaneEngines> _generatorAirplane;
|
private GeneratorAirplane<EntityAirplane, IAirplaneEngines> _generatorAirplane;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
/// Все объекты удаленные с каких либо карт
|
||||||
|
/// </summary>
|
||||||
|
private LinkedList<DrawningObject> _deletedObjects;
|
||||||
|
/// <summary>
|
||||||
/// Конструктор
|
/// Конструктор
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public FormMapWithSetAirplanes()
|
public FormMapWithSetAirplanes()
|
||||||
{
|
{
|
||||||
_generatorAirplane = new(100, 100);
|
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
_generatorAirplane = new(100, 100);
|
||||||
|
_mapsCollection = new MapsCollection(pictureBox.Width, pictureBox.Height);
|
||||||
|
_deletedObjects = new();
|
||||||
|
comboBoxSelectorMap.Items.Clear();
|
||||||
|
foreach (var elem in _mapsDict)
|
||||||
|
{
|
||||||
|
comboBoxSelectorMap.Items.Add(elem.Key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private string NameMap => listBoxMaps.SelectedItem?.ToString() ?? string.Empty;
|
||||||
|
/// <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>
|
||||||
/// Добавление самолета на карту
|
/// Добавление карты
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="airplane">самолет.</param>
|
/// <param name="sender"></param>
|
||||||
private void AddAirplaneInMap(DrawningObject airplane)
|
/// <param name="e"></param>
|
||||||
|
private void ButtonAddMap_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (airplane == null || (_mapAirplanesCollectionGeneric + airplane) == -1)
|
if (comboBoxSelectorMap.SelectedIndex == -1 || string.IsNullOrEmpty(textBoxNewMapName.Text))
|
||||||
{
|
{
|
||||||
MessageBox.Show("Не удалось добавить объект");
|
MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else
|
if (!_mapsDict.ContainsKey(comboBoxSelectorMap.Text))
|
||||||
{
|
{
|
||||||
MessageBox.Show("Объект добавлен");
|
MessageBox.Show("Нет такой карты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
pictureBox.Image = _mapAirplanesCollectionGeneric.ShowSet();
|
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(object sender, EventArgs e)
|
private void ListBoxMaps_SelectedIndexChanged(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
AbstractMap map = null;
|
pictureBox.Image = _mapsCollection[NameMap].ShowSet();
|
||||||
switch (comboBoxSelectorMap.Text)
|
|
||||||
{
|
|
||||||
case "Простая карта":
|
|
||||||
map = new SimpleMap();
|
|
||||||
break;
|
|
||||||
case "Карта со стенами":
|
|
||||||
map = new WallMap();
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
if (map != null)
|
/// <summary>
|
||||||
|
/// Удаление карты
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ButtonDeleteMap_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
_mapAirplanesCollectionGeneric = new MapWithSetAirplanesGeneric<DrawningObject, AbstractMap>(
|
if (listBoxMaps.SelectedIndex == -1)
|
||||||
pictureBox.Width, pictureBox.Height, map);
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (MessageBox.Show($"Удалить карту {listBoxMaps.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||||
|
{
|
||||||
|
_mapsCollection.DelMap(NameMap);
|
||||||
|
ReloadMaps();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>Добавление самолета на карту</summary>
|
||||||
|
/// <param name="airplane">Самолет</param>
|
||||||
|
/// <param name="text">Текст MessageBox если самолета нет</param>
|
||||||
|
/// <param name="caption">Заголовок MessageBox если самолета нет</param>
|
||||||
|
private void AddAirplaneInMap(DrawningObject? airplane, string? text = null, string? caption = null)
|
||||||
|
{
|
||||||
|
if (listBoxMaps.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (airplane == null)
|
||||||
|
{
|
||||||
|
MessageBox.Show(text, caption);
|
||||||
|
}
|
||||||
|
else if ((_mapsCollection[NameMap] + airplane) == -1)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не удалось добавить объект");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_mapAirplanesCollectionGeneric = null;
|
MessageBox.Show("Объект добавлен");
|
||||||
|
pictureBox.Image = _mapsCollection[NameMap].ShowSet();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -85,7 +156,7 @@ namespace AirBomber
|
|||||||
dir = Direction.Right;
|
dir = Direction.Right;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
pictureBox.Image = _mapAirplanesCollectionGeneric?.MoveObject(dir) ?? pictureBox.Image;
|
pictureBox.Image = _mapsCollection[NameMap].MoveObject(dir);
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Добавления типа двигателя и его количество в генератор
|
/// Добавления типа двигателя и его количество в генератор
|
||||||
@ -116,19 +187,10 @@ namespace AirBomber
|
|||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
private void btnGenerateAirplane_Click(object sender, EventArgs e)
|
private void btnGenerateAirplane_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (_mapAirplanesCollectionGeneric == null)
|
AddAirplaneInMap(_generatorAirplane.Generate(),
|
||||||
{
|
"Не удалось сгенерировать самолет. Добавьте хотя бы по одному количество двигателей и свойств для генерации",
|
||||||
return;
|
"Генерация самолета"
|
||||||
}
|
);
|
||||||
var airplane = _generatorAirplane.Generate();
|
|
||||||
if (airplane == null)
|
|
||||||
{
|
|
||||||
MessageBox.Show("Не удалось сгенерировать самолет. Добавьте хотя бы по одному количество двигателей и свойств для генерации"
|
|
||||||
, "Генерация самолета");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
AddAirplaneInMap(airplane);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Добавления сущности в генератор
|
/// Добавления сущности в генератор
|
||||||
@ -160,14 +222,14 @@ namespace AirBomber
|
|||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
private void ButtonAddAirplane_Click(object sender, EventArgs e)
|
private void ButtonAddAirplane_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (_mapAirplanesCollectionGeneric == null)
|
if (listBoxMaps.SelectedIndex == -1)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
FormAirBomber form = new();
|
FormAirBomber form = new();
|
||||||
if (form.ShowDialog() == DialogResult.OK && form.SelectedAirplane != null)
|
if (form.ShowDialog() == DialogResult.OK && form.SelectedAirplane != null)
|
||||||
{
|
{
|
||||||
AddAirplaneInMap(new(form.SelectedAirplane));
|
AddAirplaneInMap(form.SelectedAirplane);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -177,19 +239,18 @@ namespace AirBomber
|
|||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
private void ButtonRemoveAirplane_Click(object sender, EventArgs e)
|
private void ButtonRemoveAirplane_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text))
|
if (listBoxMaps.SelectedIndex == -1 || string.IsNullOrEmpty(maskedTextBoxPosition.Text)
|
||||||
{
|
|| MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
|
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
|
||||||
if (_mapAirplanesCollectionGeneric - pos != null)
|
var deletedObject = _mapsCollection[NameMap, pos];
|
||||||
|
if (_mapsCollection[NameMap] - pos != null)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Объект удален");
|
MessageBox.Show("Объект удален");
|
||||||
pictureBox.Image = _mapAirplanesCollectionGeneric.ShowSet();
|
_deletedObjects.AddLast(deletedObject);
|
||||||
|
pictureBox.Image = _mapsCollection[NameMap].ShowSet();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -203,11 +264,11 @@ namespace AirBomber
|
|||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
private void ButtonShowStorage_Click(object sender, EventArgs e)
|
private void ButtonShowStorage_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (_mapAirplanesCollectionGeneric == null)
|
if (listBoxMaps.SelectedIndex == -1)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
pictureBox.Image = _mapAirplanesCollectionGeneric.ShowSet();
|
pictureBox.Image = _mapsCollection[NameMap].ShowSet();
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Вывод карты
|
/// Вывод карты
|
||||||
@ -216,11 +277,30 @@ namespace AirBomber
|
|||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
private void ButtonShowOnMap_Click(object sender, EventArgs e)
|
private void ButtonShowOnMap_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (_mapAirplanesCollectionGeneric == null)
|
if (listBoxMaps.SelectedIndex == -1)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
pictureBox.Image = _mapAirplanesCollectionGeneric.ShowOnMap();
|
pictureBox.Image = _mapsCollection[NameMap].ShowOnMap();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void btnAddDeletedObject_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listBoxMaps.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (_deletedObjects.Count == 0)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Нет удаленных объектов", "Добавление удаленного объекта");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
FormAirBomber form = new((DrawningAirplane)_deletedObjects.First());
|
||||||
|
_deletedObjects.RemoveFirst();
|
||||||
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
AddAirplaneInMap(form.SelectedAirplane);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -29,7 +29,7 @@ namespace AirBomber
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Набор объектов
|
/// Набор объектов
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly SetAirplanesGeneric<T> _setAirplanes;
|
public SetAirplanesGeneric<T> SetAirplanes { get; private set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Карта
|
/// Карта
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -44,7 +44,7 @@ namespace AirBomber
|
|||||||
{
|
{
|
||||||
int width = picWidth / _placeSizeWidth;
|
int width = picWidth / _placeSizeWidth;
|
||||||
int height = picHeight / _placeSizeHeight;
|
int height = picHeight / _placeSizeHeight;
|
||||||
_setAirplanes = new SetAirplanesGeneric<T>(width * height);
|
SetAirplanes = new SetAirplanesGeneric<T>(width * height);
|
||||||
_pictureWidth = picWidth;
|
_pictureWidth = picWidth;
|
||||||
_pictureHeight = picHeight;
|
_pictureHeight = picHeight;
|
||||||
_map = map;
|
_map = map;
|
||||||
@ -57,7 +57,7 @@ namespace AirBomber
|
|||||||
/// <returns>Возвращает позицию вставленого объекта либо -1, если не получилось его добавить</returns>
|
/// <returns>Возвращает позицию вставленого объекта либо -1, если не получилось его добавить</returns>
|
||||||
public static int operator +(MapWithSetAirplanesGeneric<T, U> map, T airplane)
|
public static int operator +(MapWithSetAirplanesGeneric<T, U> map, T airplane)
|
||||||
{
|
{
|
||||||
return map._setAirplanes.Insert(airplane);
|
return map.SetAirplanes.Insert(airplane);
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Перегрузка оператора вычитания
|
/// Перегрузка оператора вычитания
|
||||||
@ -67,7 +67,7 @@ namespace AirBomber
|
|||||||
/// <returns>Возвращает удаленный объект, либо null если его не удалось удалить</returns>
|
/// <returns>Возвращает удаленный объект, либо null если его не удалось удалить</returns>
|
||||||
public static T operator -(MapWithSetAirplanesGeneric<T, U> map, int position)
|
public static T operator -(MapWithSetAirplanesGeneric<T, U> map, int position)
|
||||||
{
|
{
|
||||||
return map._setAirplanes.Remove(position);
|
return map.SetAirplanes.Remove(position);
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Вывод всего набора объектов
|
/// Вывод всего набора объектов
|
||||||
@ -88,9 +88,9 @@ namespace AirBomber
|
|||||||
public Bitmap ShowOnMap()
|
public Bitmap ShowOnMap()
|
||||||
{
|
{
|
||||||
Shaking();
|
Shaking();
|
||||||
for (int i = 0; i < _setAirplanes.Count; i++)
|
for (int i = 0; i < SetAirplanes.Count; i++)
|
||||||
{
|
{
|
||||||
var airplane = _setAirplanes.Get(i);
|
var airplane = SetAirplanes[i];
|
||||||
if (airplane != null)
|
if (airplane != null)
|
||||||
{
|
{
|
||||||
return _map.CreateMap(_pictureWidth, _pictureHeight, airplane);
|
return _map.CreateMap(_pictureWidth, _pictureHeight, airplane);
|
||||||
@ -116,18 +116,18 @@ namespace AirBomber
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void Shaking()
|
private void Shaking()
|
||||||
{
|
{
|
||||||
int j = _setAirplanes.Count - 1;
|
int j = SetAirplanes.Count - 1;
|
||||||
for (int i = 0; i < _setAirplanes.Count; i++)
|
for (int i = 0; i < SetAirplanes.Count; i++)
|
||||||
{
|
{
|
||||||
if (_setAirplanes.Get(i) == null)
|
if (SetAirplanes[i] == null)
|
||||||
{
|
{
|
||||||
for (; j > i; j--)
|
for (; j > i; j--)
|
||||||
{
|
{
|
||||||
var airplane = _setAirplanes.Get(j);
|
var airplane = SetAirplanes[j];
|
||||||
if (airplane != null)
|
if (airplane != null)
|
||||||
{
|
{
|
||||||
_setAirplanes.Insert(airplane, i);
|
SetAirplanes.Insert(airplane, i);
|
||||||
_setAirplanes.Remove(j);
|
SetAirplanes.Remove(j);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -150,7 +150,6 @@ namespace AirBomber
|
|||||||
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; j++)
|
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; j++)
|
||||||
{
|
{
|
||||||
DrawHangar(g, pen, new RectangleF(i * _placeSizeWidth, j * _placeSizeHeight, _placeSizeWidth / 1.8F, _placeSizeHeight / 1.6F));
|
DrawHangar(g, pen, new RectangleF(i * _placeSizeWidth, j * _placeSizeHeight, _placeSizeWidth / 1.8F, _placeSizeHeight / 1.6F));
|
||||||
// g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -173,9 +172,9 @@ namespace AirBomber
|
|||||||
{
|
{
|
||||||
int countInLine = _pictureWidth / _placeSizeWidth;
|
int countInLine = _pictureWidth / _placeSizeWidth;
|
||||||
int maxLeft = (countInLine - 1) * _placeSizeWidth;
|
int maxLeft = (countInLine - 1) * _placeSizeWidth;
|
||||||
for (int i = 0; i < _setAirplanes.Count; i++)
|
for (int i = 0; i < SetAirplanes.Count; i++)
|
||||||
{
|
{
|
||||||
var airplane = _setAirplanes.Get(i);
|
var airplane = SetAirplanes[i];
|
||||||
airplane?.SetObject(maxLeft - i % countInLine * _placeSizeWidth, i / countInLine * _placeSizeHeight + 3, _pictureWidth, _pictureHeight);
|
airplane?.SetObject(maxLeft - i % countInLine * _placeSizeWidth, i / countInLine * _placeSizeHeight + 3, _pictureWidth, _pictureHeight);
|
||||||
airplane?.DrawObject(g);
|
airplane?.DrawObject(g);
|
||||||
}
|
}
|
||||||
|
84
AirBomber/AirBomber/MapsCollection.cs
Normal file
84
AirBomber/AirBomber/MapsCollection.cs
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
using AirBomber;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AirBomber
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Класс для хранения коллекции карт
|
||||||
|
/// </summary>
|
||||||
|
internal class MapsCollection
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Словарь (хранилище) с картами
|
||||||
|
/// </summary>
|
||||||
|
readonly Dictionary<string, MapWithSetAirplanesGeneric<DrawningObject,
|
||||||
|
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,
|
||||||
|
MapWithSetAirplanesGeneric<DrawningObject, AbstractMap>>();
|
||||||
|
_pictureWidth = pictureWidth;
|
||||||
|
_pictureHeight = pictureHeight;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление карты
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">Название карты</param>
|
||||||
|
/// <param name="map">Карта</param>
|
||||||
|
public void AddMap(string name, AbstractMap map)
|
||||||
|
{
|
||||||
|
_mapStorages.Add(name, new(_pictureWidth, _pictureHeight, map));
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Удаление карты
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">Название карты</param>
|
||||||
|
public void DelMap(string name)
|
||||||
|
{
|
||||||
|
_mapStorages.Remove(name);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Доступ к аэродрому
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ind"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public MapWithSetAirplanesGeneric<DrawningObject, AbstractMap> this[string ind]
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
_mapStorages.TryGetValue(ind, out var mapWithSetAirplanesGeneric);
|
||||||
|
return mapWithSetAirplanesGeneric;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public DrawningObject this[string ind, int indDrawningObject]
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
_mapStorages.TryGetValue(ind, out var mapWithSetAirplanesGeneric);
|
||||||
|
return mapWithSetAirplanesGeneric?.SetAirplanes[indDrawningObject];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -14,20 +14,23 @@ namespace AirBomber
|
|||||||
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 SetAirplanesGeneric(int count)
|
public SetAirplanesGeneric(int count)
|
||||||
{
|
{
|
||||||
_places = new T[count];
|
_maxcount = count;
|
||||||
|
_places = new List<T>();
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Добавление объекта в набор
|
/// Добавление объекта в набор
|
||||||
@ -41,7 +44,7 @@ namespace AirBomber
|
|||||||
|
|
||||||
private bool isCorrectPosition(int position)
|
private bool isCorrectPosition(int position)
|
||||||
{
|
{
|
||||||
return 0 <= position && position < Count;
|
return 0 <= position && position < _maxcount;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Добавление объекта в набор на конкретную позицию
|
/// Добавление объекта в набор на конкретную позицию
|
||||||
@ -51,22 +54,11 @@ namespace AirBomber
|
|||||||
/// <returns>Возвращает позицию вставленого объекта либо -1, если не получилось его добавить</returns>
|
/// <returns>Возвращает позицию вставленого объекта либо -1, если не получилось его добавить</returns>
|
||||||
public int Insert(T airplane, int position)
|
public int Insert(T airplane, int position)
|
||||||
{
|
{
|
||||||
int positionNullElement = position;
|
if (!isCorrectPosition(position))
|
||||||
while (Get(positionNullElement) != null)
|
|
||||||
{
|
|
||||||
positionNullElement++;
|
|
||||||
}
|
|
||||||
// Если изначальная позиция была некорректной или пустых элементов справа не оказалось возвращаем false
|
|
||||||
if (!isCorrectPosition(positionNullElement))
|
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
while (positionNullElement != position) // Смещение вправо
|
_places.Insert(position, airplane);
|
||||||
{
|
|
||||||
_places[positionNullElement] = _places[positionNullElement - 1];
|
|
||||||
positionNullElement--;
|
|
||||||
}
|
|
||||||
_places[position] = airplane;
|
|
||||||
return position;
|
return position;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -76,20 +68,46 @@ namespace AirBomber
|
|||||||
/// <returns>Возвращает удаленный объект, либо null если его не удалось удалить</returns>
|
/// <returns>Возвращает удаленный объект, либо null если его не удалось удалить</returns>
|
||||||
public T Remove(int position)
|
public T Remove(int position)
|
||||||
{
|
{
|
||||||
if (!isCorrectPosition(position))
|
if (!isCorrectPosition(position) || position >= Count)
|
||||||
return null;
|
return null;
|
||||||
var result = _places[position];
|
var deletedObj = _places[position];
|
||||||
_places[position] = null;
|
_places.RemoveAt(position);
|
||||||
return result;
|
return deletedObj;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Получение объекта из набора по позиции
|
/// Получение объекта из набора по позиции
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="position"></param>
|
/// <param name="position"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public T Get(int position)
|
public T this[int position]
|
||||||
{
|
{
|
||||||
return isCorrectPosition(position) ? _places[position] : null;
|
get
|
||||||
|
{
|
||||||
|
return isCorrectPosition(position) && position < Count ? _places[position] : null;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
Insert(value, position);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Проход по набору до первого пустого
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public IEnumerable<T> GetAirplanes()
|
||||||
|
{
|
||||||
|
foreach (var airplane in _places)
|
||||||
|
{
|
||||||
|
if (airplane != null)
|
||||||
|
{
|
||||||
|
yield return airplane;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
yield break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user