From 0bdfe1f4041a0ab9d60337c994a22ccb2010fc21 Mon Sep 17 00:00:00 2001 From: malimova Date: Sun, 15 Oct 2023 20:10:39 +0400 Subject: [PATCH 01/12] =?UTF-8?q?=D0=9D=D0=B0=D1=87=D0=B0=D0=BB=D0=BE=20La?= =?UTF-8?q?b3.=20=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5=20=D0=BA?= =?UTF-8?q?=D0=BB=D0=B0=D1=81=D1=81=D0=B0=20SetGeneric?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/SetGeneric.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 AirBomber/AirBomber/SetGeneric.cs diff --git a/AirBomber/AirBomber/SetGeneric.cs b/AirBomber/AirBomber/SetGeneric.cs new file mode 100644 index 0000000..c45e8fc --- /dev/null +++ b/AirBomber/AirBomber/SetGeneric.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AirBomber +{ + internal class SetGeneric + { + } +} -- 2.25.1 From f4bf49eca154a68225feacaee9423b66d718b0cd Mon Sep 17 00:00:00 2001 From: malimova Date: Sun, 15 Oct 2023 20:20:06 +0400 Subject: [PATCH 02/12] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=B0=20PlanesGen?= =?UTF-8?q?ericCollection,=20=D0=B4=D0=BE=D0=BF=D0=BE=D0=BB=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=B0=20Dra?= =?UTF-8?q?wningAirPlane?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/DrawningAirPlane.cs | 6 ++++++ AirBomber/AirBomber/PlanesGenericCollection.cs | 12 ++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 AirBomber/AirBomber/PlanesGenericCollection.cs diff --git a/AirBomber/AirBomber/DrawningAirPlane.cs b/AirBomber/AirBomber/DrawningAirPlane.cs index 758f92c..f805255 100644 --- a/AirBomber/AirBomber/DrawningAirPlane.cs +++ b/AirBomber/AirBomber/DrawningAirPlane.cs @@ -269,5 +269,11 @@ namespace AirBomber break; } } + /// + /// Получение объекта IMoveableObject из объекта DrawningCar + /// + public IMoveableObject GetMoveableObject => new + DrawningObjectAirPlane(this); + } } diff --git a/AirBomber/AirBomber/PlanesGenericCollection.cs b/AirBomber/AirBomber/PlanesGenericCollection.cs new file mode 100644 index 0000000..5a2be1f --- /dev/null +++ b/AirBomber/AirBomber/PlanesGenericCollection.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AirBomber +{ + internal class PlanesGenericCollection + { + } +} -- 2.25.1 From b2213886a70a882c5798651b73edb3b6952f89b4 Mon Sep 17 00:00:00 2001 From: malimova Date: Sun, 15 Oct 2023 21:21:49 +0400 Subject: [PATCH 03/12] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=BD=D0=BE=D0=B2=D0=BE=D0=B9=20=D1=84=D0=BE?= =?UTF-8?q?=D1=80=D0=BC=D1=8B=20FormPlaneCollection?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AirBomber/FormPlaneCollection.Designer.cs | 39 ++++++ AirBomber/AirBomber/FormPlaneCollection.cs | 20 +++ AirBomber/AirBomber/FormPlaneCollection.resx | 120 ++++++++++++++++++ 3 files changed, 179 insertions(+) create mode 100644 AirBomber/AirBomber/FormPlaneCollection.Designer.cs create mode 100644 AirBomber/AirBomber/FormPlaneCollection.cs create mode 100644 AirBomber/AirBomber/FormPlaneCollection.resx diff --git a/AirBomber/AirBomber/FormPlaneCollection.Designer.cs b/AirBomber/AirBomber/FormPlaneCollection.Designer.cs new file mode 100644 index 0000000..0c42113 --- /dev/null +++ b/AirBomber/AirBomber/FormPlaneCollection.Designer.cs @@ -0,0 +1,39 @@ +namespace AirBomber +{ + partial class FormPlaneCollection + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.components = new System.ComponentModel.Container(); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Text = "FormPlaneCollection"; + } + + #endregion + } +} \ No newline at end of file diff --git a/AirBomber/AirBomber/FormPlaneCollection.cs b/AirBomber/AirBomber/FormPlaneCollection.cs new file mode 100644 index 0000000..28a9d7e --- /dev/null +++ b/AirBomber/AirBomber/FormPlaneCollection.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace AirBomber +{ + public partial class FormPlaneCollection : Form + { + public FormPlaneCollection() + { + InitializeComponent(); + } + } +} diff --git a/AirBomber/AirBomber/FormPlaneCollection.resx b/AirBomber/AirBomber/FormPlaneCollection.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/AirBomber/AirBomber/FormPlaneCollection.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file -- 2.25.1 From 442ea7337552526ca3ff2d1d9ea353124e12c3ee Mon Sep 17 00:00:00 2001 From: malimova Date: Sun, 15 Oct 2023 21:45:37 +0400 Subject: [PATCH 04/12] =?UTF-8?q?=D0=9D=D0=BE=D0=B2=D0=B0=D1=8F=20=D0=BB?= =?UTF-8?q?=D0=BE=D0=B3=D0=B8=D0=BA=D0=B0=20=D1=84=D0=BE=D1=80=D0=BC=D1=8B?= =?UTF-8?q?=20FormSportCar?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/DrawningAirBomber.cs | 11 ++- AirBomber/AirBomber/EntityAirBomber.cs | 3 +- AirBomber/AirBomber/FormAirBomber.Designer.cs | 24 +++---- AirBomber/AirBomber/FormAirBomber.cs | 69 ++++++++++++------- 4 files changed, 64 insertions(+), 43 deletions(-) diff --git a/AirBomber/AirBomber/DrawningAirBomber.cs b/AirBomber/AirBomber/DrawningAirBomber.cs index 5ed19eb..05612cf 100644 --- a/AirBomber/AirBomber/DrawningAirBomber.cs +++ b/AirBomber/AirBomber/DrawningAirBomber.cs @@ -22,12 +22,12 @@ namespace AirBomber /// Ширина картинки /// Высота картинки public DrawningAirBomber(int speed, double weight, Color bodyColor, Color - additionalColor, bool bombs, Color bombsColor, bool fuelTanks, int width, int height) : + additionalColor, bool bombs, bool fuelTanks, int width, int height) : base(speed, weight, bodyColor, width, height, 160, 118) { if (EntityAirPlane != null) { - EntityAirPlane = new EntityAirBomber(speed, weight, bodyColor, additionalColor, bombs, bombsColor, fuelTanks); + EntityAirPlane = new EntityAirBomber(speed, weight, bodyColor, additionalColor, bombs, fuelTanks); } } public override void DrawPlane(Graphics g) @@ -38,14 +38,13 @@ namespace AirBomber } Pen pen = new(Color.Black); Brush additionalBrush = new SolidBrush(airBomber.AdditionalColor); - Brush bombsColor = new SolidBrush(airBomber.BombsColor); base.DrawPlane(g); // обвесы - g.FillEllipse(bombsColor, _startPosX + 90, _startPosY + 20, 15, 29); + g.FillEllipse(additionalBrush, _startPosX + 90, _startPosY + 20, 15, 29); g.DrawEllipse(pen, _startPosX + 90, _startPosY + 20, 15, 29); - g.FillEllipse(bombsColor, _startPosX + 90, _startPosY + 70, 15, 29); + g.FillEllipse(additionalBrush, _startPosX + 90, _startPosY + 70, 15, 29); g.DrawEllipse(pen, _startPosX + 90, _startPosY + 70, 15, 29); - g.FillEllipse(bombsColor, _startPosX + 140, _startPosY + 50, 15, 15); + g.FillEllipse(additionalBrush, _startPosX + 140, _startPosY + 50, 15, 15); g.DrawEllipse(pen, _startPosX + 140, _startPosY + 50, 15, 15); // fueltanks g.FillRectangle(additionalBrush, _startPosX + 63, _startPosY + 34, 20, 15); diff --git a/AirBomber/AirBomber/EntityAirBomber.cs b/AirBomber/AirBomber/EntityAirBomber.cs index e64ad03..2197b86 100644 --- a/AirBomber/AirBomber/EntityAirBomber.cs +++ b/AirBomber/AirBomber/EntityAirBomber.cs @@ -14,11 +14,10 @@ namespace AirBomber public Color BombsColor { get; private set; } public bool FuelTanks { get; private set; } public EntityAirBomber(int speed, double weight, Color bodyColor, Color - additionalColor, bool bombs, Color bombsColor, bool fuelTanks) : base(speed, weight, bodyColor) + additionalColor, bool bombs, bool fuelTanks) : base(speed, weight, bodyColor) { AdditionalColor = additionalColor; Bombs = bombs; - BombsColor = bombsColor; FuelTanks = fuelTanks; } } diff --git a/AirBomber/AirBomber/FormAirBomber.Designer.cs b/AirBomber/AirBomber/FormAirBomber.Designer.cs index 7dd0993..806dcdd 100644 --- a/AirBomber/AirBomber/FormAirBomber.Designer.cs +++ b/AirBomber/AirBomber/FormAirBomber.Designer.cs @@ -36,7 +36,7 @@ pictureBoxAirBomber = new PictureBox(); comboBoxStrategy = new ComboBox(); buttonCreateAirPlane = new Button(); - buttonStep = new Button(); + buttonStrategyStep = new Button(); ((System.ComponentModel.ISupportInitialize)pictureBoxAirBomber).BeginInit(); SuspendLayout(); // @@ -131,23 +131,23 @@ buttonCreateAirPlane.UseVisualStyleBackColor = true; buttonCreateAirPlane.Click += buttonCreateAirPlane_Click; // - // buttonStep + // buttonStrategyStep // - buttonStep.Anchor = AnchorStyles.Top | AnchorStyles.Right; - buttonStep.Location = new Point(862, 77); - buttonStep.Name = "buttonStep"; - buttonStep.Size = new Size(112, 49); - buttonStep.TabIndex = 8; - buttonStep.Text = "Шаг"; - buttonStep.UseVisualStyleBackColor = true; - buttonStep.Click += buttonStep_Click; + buttonStrategyStep.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonStrategyStep.Location = new Point(862, 77); + buttonStrategyStep.Name = "buttonStrategyStep"; + buttonStrategyStep.Size = new Size(112, 49); + buttonStrategyStep.TabIndex = 8; + buttonStrategyStep.Text = "Шаг"; + buttonStrategyStep.UseVisualStyleBackColor = true; + buttonStrategyStep.Click += buttonStrategyStep_Click; // // FormAirBomber // AutoScaleDimensions = new SizeF(10F, 25F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(986, 540); - Controls.Add(buttonStep); + Controls.Add(buttonStrategyStep); Controls.Add(buttonCreateAirPlane); Controls.Add(comboBoxStrategy); Controls.Add(buttonUp); @@ -172,6 +172,6 @@ private PictureBox pictureBoxAirBomber; private ComboBox comboBoxStrategy; private Button buttonCreateAirPlane; - private Button buttonStep; + private Button buttonStrategyStep; } } \ No newline at end of file diff --git a/AirBomber/AirBomber/FormAirBomber.cs b/AirBomber/AirBomber/FormAirBomber.cs index aa7e5ba..9405a12 100644 --- a/AirBomber/AirBomber/FormAirBomber.cs +++ b/AirBomber/AirBomber/FormAirBomber.cs @@ -6,10 +6,17 @@ /// /// Стратегия перемещения /// - private AbstractStrategy? _abstractStrategy; + private AbstractStrategy? _strategy; + /// + /// Выбранный самолет + /// + public DrawningAirPlane? SelectedPlane { get; private set; } + public FormAirBomber() { InitializeComponent(); + _strategy = null; + SelectedPlane = null; } private void Draw() { @@ -25,25 +32,33 @@ private void buttonCreateAirBomber_Click(object sender, EventArgs e) { Random random = new(); - _drawningAirPlane = new DrawningAirBomber(random.Next(100, 300), random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), - Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), - Convert.ToBoolean(random.Next(0, 2)), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), - Convert.ToBoolean(random.Next(0, 2)), - pictureBoxAirBomber.Width, pictureBoxAirBomber.Height); + Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)); + //TODO выбор основного цвета + + Color dopColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)); + //TODO выбор дополнительного цвета + + _drawningAirPlane = new DrawningAirBomber(random.Next(100, 300), random.Next(1000, 3000), color, dopColor, + Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), pictureBoxAirBomber.Width, pictureBoxAirBomber.Height); _drawningAirPlane.SetPosition(random.Next(10, 100), random.Next(10, 100)); Draw(); - } private void buttonCreateAirPlane_Click(object sender, EventArgs e) { Random random = new(); - _drawningAirPlane = new DrawningAirPlane(random.Next(100, 300), random.Next(1000, 3000), - Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), - pictureBoxAirBomber.Width, pictureBoxAirBomber.Height); + Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)); + + ColorDialog dialog = new(); + if (dialog.ShowDialog() == DialogResult.OK) + { + color = dialog.Color; + } + _drawningAirPlane = new DrawningAirPlane(random.Next(100, 300), random.Next(1000, 3000), color, pictureBoxAirBomber.Width, pictureBoxAirBomber.Height); _drawningAirPlane.SetPosition(random.Next(10, 100), random.Next(10, 100)); Draw(); + } private void buttonMove_Click(object sender, EventArgs e) { @@ -69,7 +84,7 @@ } Draw(); } - private void buttonStep_Click(object sender, EventArgs e) + private void buttonStrategyStep_Click(object sender, EventArgs e) { if (_drawningAirPlane == null) { @@ -77,34 +92,42 @@ } if (comboBoxStrategy.Enabled) { - _abstractStrategy = comboBoxStrategy.SelectedIndex - switch + _strategy = comboBoxStrategy.SelectedIndex switch { 0 => new MoveToCenter(), 1 => new MoveToBorder(), _ => null, }; - if (_abstractStrategy == null) + if (_strategy == null) { return; } - _abstractStrategy.SetData(new - DrawningObjectAirPlane(_drawningAirPlane), pictureBoxAirBomber.Width, - pictureBoxAirBomber.Height); - comboBoxStrategy.Enabled = false; + _strategy.SetData(_drawningAirPlane.GetMoveableObject, + pictureBoxAirBomber.Width, pictureBoxAirBomber.Height); } - if (_abstractStrategy == null) + if (_strategy == null) { return; } - _abstractStrategy.MakeStep(); + comboBoxStrategy.Enabled = false; + _strategy.MakeStep(); Draw(); - if (_abstractStrategy.GetStatus() == Status.Finish) + if (_strategy.GetStatus() == Status.Finish) { comboBoxStrategy.Enabled = true; - _abstractStrategy = null; + _strategy = null; } - } + /// + /// Выбор самолета + /// + /// + /// + private void ButtonSelectPlane_Click(object sender, EventArgs e) + { + SelectedPlane = _drawningAirPlane; + DialogResult = DialogResult.OK; + } + } } \ No newline at end of file -- 2.25.1 From 53391ab2ec9fad8ee6bd812eed05a48e69e05e4e Mon Sep 17 00:00:00 2001 From: malimova Date: Sun, 15 Oct 2023 22:06:38 +0400 Subject: [PATCH 05/12] =?UTF-8?q?=D0=9B=D0=BE=D0=B3=D0=B8=D0=BA=D0=B0=20?= =?UTF-8?q?=D1=84=D0=BE=D1=80=D0=BC=D1=8B=20FormCarCollection?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AirBomber/FormPlaneCollection.Designer.cs | 95 +++++++++++++- AirBomber/AirBomber/FormPlaneCollection.cs | 59 +++++++++ AirBomber/AirBomber/FormPlaneCollection.resx | 62 +-------- .../AirBomber/PlanesGenericCollection.cs | 124 +++++++++++++++++- AirBomber/AirBomber/SetGeneric.cs | 67 +++++++++- 5 files changed, 340 insertions(+), 67 deletions(-) diff --git a/AirBomber/AirBomber/FormPlaneCollection.Designer.cs b/AirBomber/AirBomber/FormPlaneCollection.Designer.cs index 0c42113..f762bda 100644 --- a/AirBomber/AirBomber/FormPlaneCollection.Designer.cs +++ b/AirBomber/AirBomber/FormPlaneCollection.Designer.cs @@ -28,12 +28,99 @@ /// private void InitializeComponent() { - this.components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "FormPlaneCollection"; + pictureBoxCollection = new PictureBox(); + panelTools = new Panel(); + maskedTextBoxNumber = new MaskedTextBox(); + buttonRefreshCollection = new Button(); + buttonRemovePlane = new Button(); + buttonAddPlane = new Button(); + ((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit(); + panelTools.SuspendLayout(); + SuspendLayout(); + // + // pictureBoxCollection + // + pictureBoxCollection.BackColor = SystemColors.Control; + pictureBoxCollection.Dock = DockStyle.Left; + pictureBoxCollection.Location = new Point(0, 0); + pictureBoxCollection.Name = "pictureBoxCollection"; + pictureBoxCollection.Size = new Size(708, 548); + pictureBoxCollection.TabIndex = 0; + pictureBoxCollection.TabStop = false; + // + // panelTools + // + panelTools.Controls.Add(maskedTextBoxNumber); + panelTools.Controls.Add(buttonRefreshCollection); + panelTools.Controls.Add(buttonRemovePlane); + panelTools.Controls.Add(buttonAddPlane); + panelTools.Dock = DockStyle.Right; + panelTools.Location = new Point(719, 0); + panelTools.Name = "panelTools"; + panelTools.Size = new Size(237, 548); + panelTools.TabIndex = 1; + // + // maskedTextBoxNumber + // + maskedTextBoxNumber.Location = new Point(37, 218); + maskedTextBoxNumber.Mask = "00"; + maskedTextBoxNumber.Name = "maskedTextBoxNumber"; + maskedTextBoxNumber.Size = new Size(160, 31); + maskedTextBoxNumber.TabIndex = 3; + maskedTextBoxNumber.ValidatingType = typeof(int); + // + // buttonRefreshCollection + // + buttonRefreshCollection.Location = new Point(37, 394); + buttonRefreshCollection.Name = "buttonRefreshCollection"; + buttonRefreshCollection.Size = new Size(160, 86); + buttonRefreshCollection.TabIndex = 2; + buttonRefreshCollection.Text = "Обновить коллекцию"; + buttonRefreshCollection.UseVisualStyleBackColor = true; + buttonRefreshCollection.Click += buttonRefreshCollection_Click; + // + // buttonRemovePlane + // + buttonRemovePlane.Location = new Point(37, 266); + buttonRemovePlane.Name = "buttonRemovePlane"; + buttonRemovePlane.Size = new Size(160, 60); + buttonRemovePlane.TabIndex = 1; + buttonRemovePlane.Text = "Удалить самолет"; + buttonRemovePlane.UseVisualStyleBackColor = true; + buttonRemovePlane.Click += buttonRemovePlane_Click; + // + // buttonAddPlane + // + buttonAddPlane.Location = new Point(37, 94); + buttonAddPlane.Name = "buttonAddPlane"; + buttonAddPlane.Size = new Size(160, 64); + buttonAddPlane.TabIndex = 0; + buttonAddPlane.Text = "Добавить самолет"; + buttonAddPlane.UseVisualStyleBackColor = true; + buttonAddPlane.Click += buttonAddPlane_Click; + // + // FormPlaneCollection + // + AutoScaleDimensions = new SizeF(10F, 25F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(956, 548); + Controls.Add(panelTools); + Controls.Add(pictureBoxCollection); + Name = "FormPlaneCollection"; + Text = "Набор самолетов"; + ((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit(); + panelTools.ResumeLayout(false); + panelTools.PerformLayout(); + ResumeLayout(false); } #endregion + + private PictureBox pictureBoxCollection; + private Panel panelTools; + private MaskedTextBox maskedTextBoxNumber; + private Button buttonRefreshCollection; + private Button buttonRemovePlane; + private Button buttonAddPlane; } } \ No newline at end of file diff --git a/AirBomber/AirBomber/FormPlaneCollection.cs b/AirBomber/AirBomber/FormPlaneCollection.cs index 28a9d7e..e9e77ce 100644 --- a/AirBomber/AirBomber/FormPlaneCollection.cs +++ b/AirBomber/AirBomber/FormPlaneCollection.cs @@ -12,9 +12,68 @@ namespace AirBomber { public partial class FormPlaneCollection : Form { + /// + /// Набор объектов + /// + private readonly PlanesGenericCollection _planes; + public FormPlaneCollection() { InitializeComponent(); + _planes = new PlanesGenericCollection(pictureBoxCollection.Width, pictureBoxCollection.Height); + + } + /// + /// Добавление объекта в набор + /// + /// + /// + private void buttonAddPlane_Click(object sender, EventArgs e) + { + FormAirBomber form = new(); + if (form.ShowDialog() == DialogResult.OK) + { + if (_planes + form.SelectedPlane) + { + MessageBox.Show("Объект добавлен"); + pictureBoxCollection.Image = _planes.ShowCars(); + } + else + { + MessageBox.Show("Не удалось добавить объект"); + } + } + } + /// + /// Удаление объекта из набора + /// + /// + /// + private void buttonRemovePlane_Click(object sender, EventArgs e) + { + if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) + { + return; + } + int pos = Convert.ToInt32(maskedTextBoxNumber.Text); + if (_planes - pos != null) + { + MessageBox.Show("Объект удален"); + pictureBoxCollection.Image = _planes.ShowCars(); + } + else + { + MessageBox.Show("Не удалось удалить объект"); + } + } + /// + /// Обновление рисунка по набору + /// + /// + /// + private void buttonRefreshCollection_Click(object sender, EventArgs e) + { + pictureBoxCollection.Image = _planes.ShowCars(); } } } diff --git a/AirBomber/AirBomber/FormPlaneCollection.resx b/AirBomber/AirBomber/FormPlaneCollection.resx index 1af7de1..f298a7b 100644 --- a/AirBomber/AirBomber/FormPlaneCollection.resx +++ b/AirBomber/AirBomber/FormPlaneCollection.resx @@ -1,64 +1,4 @@ - - - + diff --git a/AirBomber/AirBomber/PlanesGenericCollection.cs b/AirBomber/AirBomber/PlanesGenericCollection.cs index 5a2be1f..c19df9f 100644 --- a/AirBomber/AirBomber/PlanesGenericCollection.cs +++ b/AirBomber/AirBomber/PlanesGenericCollection.cs @@ -6,7 +6,129 @@ using System.Threading.Tasks; namespace AirBomber { - internal class PlanesGenericCollection + internal class PlanesGenericCollection + where T : DrawningAirPlane + where U : IMoveableObject { + /// + /// Ширина окна прорисовки + /// + private readonly int _pictureWidth; + /// + /// Высота окна прорисовки + /// + private readonly int _pictureHeight; + /// + /// Размер занимаемого объектом места (ширина) + /// + private readonly int _placeSizeWidth = 210; + /// + /// Размер занимаемого объектом места (высота) + /// + private readonly int _placeSizeHeight = 90; + /// + /// Набор объектов + /// + private readonly SetGeneric _collection; + /// + /// Конструктор + /// + /// + /// + public PlanesGenericCollection(int picWidth, int picHeight) + { + int width = picWidth / _placeSizeWidth; + int height = picHeight / _placeSizeHeight; + _pictureWidth = picWidth; + _pictureHeight = picHeight; + _collection = new SetGeneric(width * height); + } + /// + /// Перегрузка оператора сложения + /// + /// + /// + /// + public static bool operator +(PlanesGenericCollection collect, T? + obj) + { + if (obj == null) + { + return false; + } + return collect?._collection.Insert(obj) ?? false; + } + + /// + /// Перегрузка оператора вычитания + /// + /// + /// + /// + public static T? operator -(PlanesGenericCollection collect, int + pos) + { + T? obj = collect._collection.Get(pos); + if (obj != null) + { + collect._collection.Remove(pos); + } + return obj; + } + /// + /// Получение объекта IMoveableObject + /// + /// + /// + public U? GetU(int pos) + { + return (U?)_collection.Get(pos)?.GetMoveableObject; + } + /// + /// Вывод всего набора объектов + /// + /// + public Bitmap ShowCars() + { + Bitmap bmp = new(_pictureWidth, _pictureHeight); + Graphics gr = Graphics.FromImage(bmp); + DrawBackground(gr); + DrawObjects(gr); + return bmp; + } + /// + /// Метод отрисовки фона + /// + /// + private void DrawBackground(Graphics g) + { + Pen pen = new(Color.Black, 3); + for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++) + { + for (int j = 0; j < _pictureHeight / _placeSizeHeight + + 1; ++j) + {//линия рамзетки места + g.DrawLine(pen, i * _placeSizeWidth, j * + _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * + _placeSizeHeight); + } + g.DrawLine(pen, i * _placeSizeWidth, 0, i * + _placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight); + } + } + /// + /// Метод прорисовки объектов + /// + /// + private void DrawObjects(Graphics g) + { + for (int i = 0; i < _collection.Count; i++) + { + // TODO получение объекта + // TODO установка позиции + // TODO прорисовка объекта + } + } + } } diff --git a/AirBomber/AirBomber/SetGeneric.cs b/AirBomber/AirBomber/SetGeneric.cs index c45e8fc..605f044 100644 --- a/AirBomber/AirBomber/SetGeneric.cs +++ b/AirBomber/AirBomber/SetGeneric.cs @@ -6,7 +6,72 @@ using System.Threading.Tasks; namespace AirBomber { - internal class SetGeneric + internal class SetGeneric + where T : class { + /// + /// Массив объектов, которые храним + /// + private readonly T?[] _places; + /// + /// Количество объектов в массиве + /// + public int Count => _places.Length; + /// + /// Конструктор + /// + /// + public SetGeneric(int count) + { + _places = new T?[count]; + } + /// + /// Добавление объекта в набор + /// + /// Добавляемый самолет + /// + public bool Insert(T plane) + { + // TODO вставка в начало набора + return true; + } + /// + /// Добавление объекта в набор на конкретную позицию + /// + /// Добавляемый самолет + /// Позиция + /// + public bool Insert(T plane, int position) + { + // TODO проверка позиции + // TODO проверка, что элемент массива по этой позиции пустой,если нет, то + // проверка, что после вставляемого элемента в массиве есть пустой элемент + // сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента + // TODO вставка по позиции + _places[position] = plane; + return true; + } + /// + /// Удаление объекта из набора с конкретной позиции + /// + /// + /// + public bool Remove(int position) + { + // TODO проверка позиции + // TODO удаление объекта из массива, присвоив элементу массива значение null + return true; + } + /// + /// Получение объекта из набора по позиции + /// + /// + /// + public T? Get(int position) + { + // TODO проверка позиции + return _places[position]; + } + } } -- 2.25.1 From 2fba868169ce58ff5fffe2fe609e393e347c3b8f Mon Sep 17 00:00:00 2001 From: malimova Date: Sun, 15 Oct 2023 22:09:36 +0400 Subject: [PATCH 06/12] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=BD=D0=B0=D1=8F=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA?= =?UTF-8?q?=D0=B0=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=B0=20Program?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AirBomber/AirBomber/Program.cs b/AirBomber/AirBomber/Program.cs index 76b85fe..e7cb4a7 100644 --- a/AirBomber/AirBomber/Program.cs +++ b/AirBomber/AirBomber/Program.cs @@ -11,7 +11,7 @@ namespace AirBomber // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormAirBomber()); + Application.Run(new FormPlaneCollection()); } } } \ No newline at end of file -- 2.25.1 From 1d0a18b4b7817fc86df3779bef21b024e0575596 Mon Sep 17 00:00:00 2001 From: malimova Date: Sun, 15 Oct 2023 23:48:33 +0400 Subject: [PATCH 07/12] =?UTF-8?q?=D0=92=D1=8B=D0=BF=D0=BE=D0=BB=D0=BD?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20TODO?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/FormAirBomber.Designer.cs | 13 ++++ AirBomber/AirBomber/FormAirBomber.cs | 3 +- AirBomber/AirBomber/FormPlaneCollection.cs | 8 +-- .../AirBomber/PlanesGenericCollection.cs | 34 ++++++----- AirBomber/AirBomber/SetGeneric.cs | 59 +++++++++++++++---- 5 files changed, 83 insertions(+), 34 deletions(-) diff --git a/AirBomber/AirBomber/FormAirBomber.Designer.cs b/AirBomber/AirBomber/FormAirBomber.Designer.cs index 806dcdd..ae4cac6 100644 --- a/AirBomber/AirBomber/FormAirBomber.Designer.cs +++ b/AirBomber/AirBomber/FormAirBomber.Designer.cs @@ -37,6 +37,7 @@ comboBoxStrategy = new ComboBox(); buttonCreateAirPlane = new Button(); buttonStrategyStep = new Button(); + buttonSelectPlane = new Button(); ((System.ComponentModel.ISupportInitialize)pictureBoxAirBomber).BeginInit(); SuspendLayout(); // @@ -142,11 +143,22 @@ buttonStrategyStep.UseVisualStyleBackColor = true; buttonStrategyStep.Click += buttonStrategyStep_Click; // + // buttonSelectPlane + // + buttonSelectPlane.Location = new Point(862, 178); + buttonSelectPlane.Name = "buttonSelectPlane"; + buttonSelectPlane.Size = new Size(110, 91); + buttonSelectPlane.TabIndex = 9; + buttonSelectPlane.Text = "Выбрать самолет"; + buttonSelectPlane.UseVisualStyleBackColor = true; + buttonSelectPlane.Click += buttonSelectPlane_Click; + // // FormAirBomber // AutoScaleDimensions = new SizeF(10F, 25F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(986, 540); + Controls.Add(buttonSelectPlane); Controls.Add(buttonStrategyStep); Controls.Add(buttonCreateAirPlane); Controls.Add(comboBoxStrategy); @@ -173,5 +185,6 @@ private ComboBox comboBoxStrategy; private Button buttonCreateAirPlane; private Button buttonStrategyStep; + private Button buttonSelectPlane; } } \ No newline at end of file diff --git a/AirBomber/AirBomber/FormAirBomber.cs b/AirBomber/AirBomber/FormAirBomber.cs index 9405a12..a50d1cf 100644 --- a/AirBomber/AirBomber/FormAirBomber.cs +++ b/AirBomber/AirBomber/FormAirBomber.cs @@ -123,11 +123,10 @@ /// /// /// - private void ButtonSelectPlane_Click(object sender, EventArgs e) + private void buttonSelectPlane_Click(object sender, EventArgs e) { SelectedPlane = _drawningAirPlane; DialogResult = DialogResult.OK; } - } } \ No newline at end of file diff --git a/AirBomber/AirBomber/FormPlaneCollection.cs b/AirBomber/AirBomber/FormPlaneCollection.cs index e9e77ce..eba8446 100644 --- a/AirBomber/AirBomber/FormPlaneCollection.cs +++ b/AirBomber/AirBomber/FormPlaneCollection.cs @@ -33,10 +33,10 @@ namespace AirBomber FormAirBomber form = new(); if (form.ShowDialog() == DialogResult.OK) { - if (_planes + form.SelectedPlane) + if (_planes + form.SelectedPlane != -1) { MessageBox.Show("Объект добавлен"); - pictureBoxCollection.Image = _planes.ShowCars(); + pictureBoxCollection.Image = _planes.ShowPlanes(); } else { @@ -59,7 +59,7 @@ namespace AirBomber if (_planes - pos != null) { MessageBox.Show("Объект удален"); - pictureBoxCollection.Image = _planes.ShowCars(); + pictureBoxCollection.Image = _planes.ShowPlanes(); } else { @@ -73,7 +73,7 @@ namespace AirBomber /// private void buttonRefreshCollection_Click(object sender, EventArgs e) { - pictureBoxCollection.Image = _planes.ShowCars(); + pictureBoxCollection.Image = _planes.ShowPlanes(); } } } diff --git a/AirBomber/AirBomber/PlanesGenericCollection.cs b/AirBomber/AirBomber/PlanesGenericCollection.cs index c19df9f..0031f45 100644 --- a/AirBomber/AirBomber/PlanesGenericCollection.cs +++ b/AirBomber/AirBomber/PlanesGenericCollection.cs @@ -21,11 +21,11 @@ namespace AirBomber /// /// Размер занимаемого объектом места (ширина) /// - private readonly int _placeSizeWidth = 210; + private readonly int _placeSizeWidth = 150; /// /// Размер занимаемого объектом места (высота) /// - private readonly int _placeSizeHeight = 90; + private readonly int _placeSizeHeight = 118; /// /// Набор объектов /// @@ -49,14 +49,11 @@ namespace AirBomber /// /// /// - public static bool operator +(PlanesGenericCollection collect, T? - obj) + public static int operator +(PlanesGenericCollection collect, T? obj) { if (obj == null) - { - return false; - } - return collect?._collection.Insert(obj) ?? false; + return -1; + return collect?._collection.Insert(obj) ?? -1; } /// @@ -65,8 +62,7 @@ namespace AirBomber /// /// /// - public static T? operator -(PlanesGenericCollection collect, int - pos) + public static T? operator -(PlanesGenericCollection collect, int pos) { T? obj = collect._collection.Get(pos); if (obj != null) @@ -88,7 +84,7 @@ namespace AirBomber /// Вывод всего набора объектов /// /// - public Bitmap ShowCars() + public Bitmap ShowPlanes() { Bitmap bmp = new(_pictureWidth, _pictureHeight); Graphics gr = Graphics.FromImage(bmp); @@ -122,13 +118,21 @@ namespace AirBomber /// private void DrawObjects(Graphics g) { + int heightObjCount = _pictureHeight / _placeSizeHeight; + int widthObjCount = _pictureWidth / _placeSizeWidth; // Добавляем вычисление ширины + for (int i = 0; i < _collection.Count; i++) { - // TODO получение объекта - // TODO установка позиции - // TODO прорисовка объекта + T? type = _collection.Get(i); + if (type != null) + { + int row = i / widthObjCount; // Ряд - сначала сверху вниз + int col = widthObjCount - 1 - (i % widthObjCount); // Столбец - справа налево + + type.SetPosition(col * _placeSizeWidth, row * _placeSizeHeight); + type?.DrawPlane(g); + } } } - } } diff --git a/AirBomber/AirBomber/SetGeneric.cs b/AirBomber/AirBomber/SetGeneric.cs index 605f044..8fe83a3 100644 --- a/AirBomber/AirBomber/SetGeneric.cs +++ b/AirBomber/AirBomber/SetGeneric.cs @@ -30,10 +30,10 @@ namespace AirBomber /// /// Добавляемый самолет /// - public bool Insert(T plane) + public int Insert(T plane) { - // TODO вставка в начало набора - return true; + //was TODO + return Insert(plane, 0); } /// /// Добавление объекта в набор на конкретную позицию @@ -41,15 +41,39 @@ namespace AirBomber /// Добавляемый самолет /// Позиция /// - public bool Insert(T plane, int position) + public int Insert(T plane, int position) { - // TODO проверка позиции + // TODO проверка позиции DONE // TODO проверка, что элемент массива по этой позиции пустой,если нет, то - // проверка, что после вставляемого элемента в массиве есть пустой элемент - // сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента - // TODO вставка по позиции - _places[position] = plane; - return true; + // проверка, что после вставляемого элемента в массиве есть пустой элемент + // сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента + // TODO вставка по позиции + int NoEmpty = 0, temp = 0; + for (int i = position; i < Count; i++) + { + if (_places[i] != null) NoEmpty++; + } + if (NoEmpty == Count - position - 1) return -1; + + if (position < Count && position >= 0) + { + for (int j = position; j < Count; j++) + { + if (_places[j] == null) + { + temp = j; + break; + } + } + + for (int i = temp; i > position; i--) + { + _places[i] = _places[i - 1]; + } + _places[position] = plane; + return position; + } + return -1; } /// /// Удаление объекта из набора с конкретной позиции @@ -58,9 +82,14 @@ namespace AirBomber /// public bool Remove(int position) { - // TODO проверка позиции + // TODO проверка позиции DONE // TODO удаление объекта из массива, присвоив элементу массива значение null - return true; + if (!(position >= 0 && position < Count) || _places[position] == null) + { + return false; + } + _places[position] = null; + return true; } /// /// Получение объекта из набора по позиции @@ -69,7 +98,11 @@ namespace AirBomber /// public T? Get(int position) { - // TODO проверка позиции + // TODO проверка позиции DONE + if (position < 0 || position >= Count) + { + return null; + } return _places[position]; } -- 2.25.1 From 52950b54cb108818f6e96ce95f6b871bf76c8272 Mon Sep 17 00:00:00 2001 From: malimova Date: Sun, 15 Oct 2023 23:57:12 +0400 Subject: [PATCH 08/12] =?UTF-8?q?=D0=94=D0=BE=D1=80=D0=B0=D0=B1=D0=BE?= =?UTF-8?q?=D1=82=D0=BA=D0=B0=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D0=B8=20Dra?= =?UTF-8?q?wObjects?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/PlanesGenericCollection.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/AirBomber/AirBomber/PlanesGenericCollection.cs b/AirBomber/AirBomber/PlanesGenericCollection.cs index 0031f45..0d996fb 100644 --- a/AirBomber/AirBomber/PlanesGenericCollection.cs +++ b/AirBomber/AirBomber/PlanesGenericCollection.cs @@ -119,15 +119,15 @@ namespace AirBomber private void DrawObjects(Graphics g) { int heightObjCount = _pictureHeight / _placeSizeHeight; - int widthObjCount = _pictureWidth / _placeSizeWidth; // Добавляем вычисление ширины + int widthObjCount = _pictureWidth / _placeSizeWidth; for (int i = 0; i < _collection.Count; i++) { T? type = _collection.Get(i); if (type != null) { - int row = i / widthObjCount; // Ряд - сначала сверху вниз - int col = widthObjCount - 1 - (i % widthObjCount); // Столбец - справа налево + int row = i / widthObjCount; + int col = widthObjCount - 1 - (i % widthObjCount); type.SetPosition(col * _placeSizeWidth, row * _placeSizeHeight); type?.DrawPlane(g); -- 2.25.1 From 9cadd9bb31e6e6cd0feab2d3eca5fb51460ed0e7 Mon Sep 17 00:00:00 2001 From: malimova Date: Mon, 16 Oct 2023 00:43:49 +0400 Subject: [PATCH 09/12] =?UTF-8?q?=D0=94=D0=BE=D1=80=D0=B0=D0=B1=D0=BE?= =?UTF-8?q?=D1=82=D0=BA=D0=B0=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D0=B8=20?= =?UTF-8?q?=D0=B2=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=B0=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/PlanesGenericCollection.cs | 6 ++---- AirBomber/AirBomber/SetGeneric.cs | 4 ++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/AirBomber/AirBomber/PlanesGenericCollection.cs b/AirBomber/AirBomber/PlanesGenericCollection.cs index 0d996fb..8958b73 100644 --- a/AirBomber/AirBomber/PlanesGenericCollection.cs +++ b/AirBomber/AirBomber/PlanesGenericCollection.cs @@ -21,11 +21,11 @@ namespace AirBomber /// /// Размер занимаемого объектом места (ширина) /// - private readonly int _placeSizeWidth = 150; + private readonly int _placeSizeWidth = 170; /// /// Размер занимаемого объектом места (высота) /// - private readonly int _placeSizeHeight = 118; + private readonly int _placeSizeHeight = 120; /// /// Набор объектов /// @@ -118,9 +118,7 @@ namespace AirBomber /// private void DrawObjects(Graphics g) { - int heightObjCount = _pictureHeight / _placeSizeHeight; int widthObjCount = _pictureWidth / _placeSizeWidth; - for (int i = 0; i < _collection.Count; i++) { T? type = _collection.Get(i); diff --git a/AirBomber/AirBomber/SetGeneric.cs b/AirBomber/AirBomber/SetGeneric.cs index 8fe83a3..6732b9d 100644 --- a/AirBomber/AirBomber/SetGeneric.cs +++ b/AirBomber/AirBomber/SetGeneric.cs @@ -53,7 +53,7 @@ namespace AirBomber { if (_places[i] != null) NoEmpty++; } - if (NoEmpty == Count - position - 1) return -1; + if (NoEmpty == Count - position) return -1; if (position < Count && position >= 0) { @@ -88,7 +88,7 @@ namespace AirBomber { return false; } - _places[position] = null; + _places[position - 1] = null; return true; } /// -- 2.25.1 From 4bf485c19e0385e73f41e933596f96498a4d3cea Mon Sep 17 00:00:00 2001 From: malimova Date: Mon, 16 Oct 2023 11:36:12 +0400 Subject: [PATCH 10/12] =?UTF-8?q?=D0=94=D0=BE=D1=80=D0=B0=D0=B1=D0=BE?= =?UTF-8?q?=D1=82=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/FormAirBomber.cs | 17 ++++++++++++++--- AirBomber/AirBomber/PlanesGenericCollection.cs | 7 +++++-- AirBomber/AirBomber/SetGeneric.cs | 2 +- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/AirBomber/AirBomber/FormAirBomber.cs b/AirBomber/AirBomber/FormAirBomber.cs index a50d1cf..fa19f00 100644 --- a/AirBomber/AirBomber/FormAirBomber.cs +++ b/AirBomber/AirBomber/FormAirBomber.cs @@ -1,4 +1,6 @@ -namespace AirBomber +using System.Windows.Forms; + +namespace AirBomber { public partial class FormAirBomber : Form { @@ -33,10 +35,19 @@ { Random random = new(); Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)); - //TODO выбор основного цвета + ColorDialog colorDialog = new ColorDialog(); + //TODO выбор основного цвета DONE + if (colorDialog.ShowDialog() == DialogResult.OK) + { + color = colorDialog.Color; + } Color dopColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)); - //TODO выбор дополнительного цвета + //TODO выбор дополнительного цвета DONE + if (colorDialog.ShowDialog() == DialogResult.OK) + { + dopColor = colorDialog.Color; + } _drawningAirPlane = new DrawningAirBomber(random.Next(100, 300), random.Next(1000, 3000), color, dopColor, Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), pictureBoxAirBomber.Width, pictureBoxAirBomber.Height); diff --git a/AirBomber/AirBomber/PlanesGenericCollection.cs b/AirBomber/AirBomber/PlanesGenericCollection.cs index 8958b73..5381999 100644 --- a/AirBomber/AirBomber/PlanesGenericCollection.cs +++ b/AirBomber/AirBomber/PlanesGenericCollection.cs @@ -52,7 +52,9 @@ namespace AirBomber public static int operator +(PlanesGenericCollection collect, T? obj) { if (obj == null) + { return -1; + } return collect?._collection.Insert(obj) ?? -1; } @@ -62,14 +64,15 @@ namespace AirBomber /// /// /// - public static T? operator -(PlanesGenericCollection collect, int pos) + public static bool operator -(PlanesGenericCollection collect, int pos) { T? obj = collect._collection.Get(pos); if (obj != null) { collect._collection.Remove(pos); + return true; } - return obj; + return false; } /// /// Получение объекта IMoveableObject diff --git a/AirBomber/AirBomber/SetGeneric.cs b/AirBomber/AirBomber/SetGeneric.cs index 6732b9d..b1b0f54 100644 --- a/AirBomber/AirBomber/SetGeneric.cs +++ b/AirBomber/AirBomber/SetGeneric.cs @@ -88,7 +88,7 @@ namespace AirBomber { return false; } - _places[position - 1] = null; + _places[position] = null; return true; } /// -- 2.25.1 From ed09a0e092224731ea71d60de4e6a3a863039379 Mon Sep 17 00:00:00 2001 From: malimova Date: Mon, 16 Oct 2023 12:52:06 +0400 Subject: [PATCH 11/12] =?UTF-8?q?=D1=84=D0=B8=D0=BA=D1=81=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/DrawningAirPlane.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/AirBomber/AirBomber/DrawningAirPlane.cs b/AirBomber/AirBomber/DrawningAirPlane.cs index f805255..7401eef 100644 --- a/AirBomber/AirBomber/DrawningAirPlane.cs +++ b/AirBomber/AirBomber/DrawningAirPlane.cs @@ -45,7 +45,7 @@ namespace AirBomber /// Основной цвет /// Ширина картинки /// Высота картинки - public DrawningAirPlane(int speed, double weight, Color bodyColor, int + /*public DrawningAirPlane(int speed, double weight, Color bodyColor, int width, int height) { // TODO: Продумать проверки @@ -56,7 +56,7 @@ namespace AirBomber _pictureWidth = width; _pictureHeight = height; EntityAirPlane = new EntityAirPlane(speed, weight, bodyColor); - } + }*/ /// /// Конструктор /// @@ -270,7 +270,7 @@ namespace AirBomber } } /// - /// Получение объекта IMoveableObject из объекта DrawningCar + /// Получение объекта IMoveableObject из объекта DrawningAirPlane /// public IMoveableObject GetMoveableObject => new DrawningObjectAirPlane(this); -- 2.25.1 From 3ad20712566877d1536ce8153eb91a4635a0e739 Mon Sep 17 00:00:00 2001 From: malimova Date: Sun, 22 Oct 2023 13:37:26 +0400 Subject: [PATCH 12/12] =?UTF-8?q?=D0=A4=D0=BE=D1=80=D0=BC=D0=B0=D1=82?= =?UTF-8?q?=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5.=20=D0=97?= =?UTF-8?q?=D0=B0=D0=B2=D0=B5=D1=80=D1=88=D0=B5=D0=BD=D0=B8=D0=B5=20Lab3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/AbstractStrategy.cs | 4 ++-- AirBomber/AirBomber/DrawningAirPlane.cs | 4 ++-- AirBomber/AirBomber/FormAirBomber.cs | 1 - AirBomber/AirBomber/PlanesGenericCollection.cs | 1 - 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/AirBomber/AirBomber/AbstractStrategy.cs b/AirBomber/AirBomber/AbstractStrategy.cs index 7b44070..c82b1b6 100644 --- a/AirBomber/AirBomber/AbstractStrategy.cs +++ b/AirBomber/AirBomber/AbstractStrategy.cs @@ -37,6 +37,7 @@ namespace AirBomber public void SetData(IMoveableObject moveableObject, int width, int height) { + if (moveableObject == null) { _state = Status.NotInit; @@ -86,8 +87,7 @@ namespace AirBomber /// /// Параметры объекта /// - protected ObjectParameters? GetObjectParameters => - _moveableObject?.GetObjectPosition; + protected ObjectParameters? GetObjectParameters =>_moveableObject?.GetObjectPosition; /// /// Шаг объекта /// diff --git a/AirBomber/AirBomber/DrawningAirPlane.cs b/AirBomber/AirBomber/DrawningAirPlane.cs index 7401eef..ba2b1e2 100644 --- a/AirBomber/AirBomber/DrawningAirPlane.cs +++ b/AirBomber/AirBomber/DrawningAirPlane.cs @@ -45,7 +45,7 @@ namespace AirBomber /// Основной цвет /// Ширина картинки /// Высота картинки - /*public DrawningAirPlane(int speed, double weight, Color bodyColor, int + public DrawningAirPlane(int speed, double weight, Color bodyColor, int width, int height) { // TODO: Продумать проверки @@ -56,7 +56,7 @@ namespace AirBomber _pictureWidth = width; _pictureHeight = height; EntityAirPlane = new EntityAirPlane(speed, weight, bodyColor); - }*/ + } /// /// Конструктор /// diff --git a/AirBomber/AirBomber/FormAirBomber.cs b/AirBomber/AirBomber/FormAirBomber.cs index fa19f00..c9dff90 100644 --- a/AirBomber/AirBomber/FormAirBomber.cs +++ b/AirBomber/AirBomber/FormAirBomber.cs @@ -59,7 +59,6 @@ namespace AirBomber { Random random = new(); Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)); - ColorDialog dialog = new(); if (dialog.ShowDialog() == DialogResult.OK) { diff --git a/AirBomber/AirBomber/PlanesGenericCollection.cs b/AirBomber/AirBomber/PlanesGenericCollection.cs index 5381999..5d4cbf8 100644 --- a/AirBomber/AirBomber/PlanesGenericCollection.cs +++ b/AirBomber/AirBomber/PlanesGenericCollection.cs @@ -57,7 +57,6 @@ namespace AirBomber } return collect?._collection.Insert(obj) ?? -1; } - /// /// Перегрузка оператора вычитания /// -- 2.25.1