diff --git a/AirBomber/AirBomber/CountEngines.cs b/AirBomber/AirBomber/CountEngines.cs
new file mode 100644
index 0000000..a448b75
--- /dev/null
+++ b/AirBomber/AirBomber/CountEngines.cs
@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AirBomber
+{
+ internal enum CountEngines
+ {
+ Two = 2,
+ Four = 4,
+ Six = 6,
+ }
+}
diff --git a/AirBomber/AirBomber/DrawningAirplane.cs b/AirBomber/AirBomber/DrawningAirplane.cs
index 9d73ff9..3754ad5 100644
--- a/AirBomber/AirBomber/DrawningAirplane.cs
+++ b/AirBomber/AirBomber/DrawningAirplane.cs
@@ -9,6 +9,8 @@
/// Класс-сущность
///
public EntityAirplane Airplane { get; private set; }
+
+ public DrawningAirplaneEngines DrawningEngines { get; private set; }
///
/// Левая координата отрисовки автомобиля
///
@@ -43,6 +45,8 @@
{
Airplane = new EntityAirplane();
Airplane.Init(speed, weight, bodyColor);
+ DrawningEngines = new();
+ DrawningEngines.CountEngines = 6;
}
///
/// Установка позиции самолета
@@ -151,6 +155,8 @@
});
// Конец хвоста
g.FillRectangle(BodyColorBrush, x + w - 5, y + 15, 5, h - 30);
+ // Двигатели
+ DrawningEngines.DrawEngines(g, Airplane.BodyColor, x + w / 2 - 20, y + h, y, 15);
}
diff --git a/AirBomber/AirBomber/DrawningAirplaneEngines.cs b/AirBomber/AirBomber/DrawningAirplaneEngines.cs
new file mode 100644
index 0000000..e8ac24b
--- /dev/null
+++ b/AirBomber/AirBomber/DrawningAirplaneEngines.cs
@@ -0,0 +1,57 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AirBomber
+{
+ ///
+ /// Класс-дополнение к самолету отвечающий за число двигателей и их отрисовку
+ ///
+ internal class DrawningAirplaneEngines
+ {
+ /// Приватное поле содержащие текущее количество двигателей самолета
+ private CountEngines _countEngines;
+
+ /// Получение действительного количества двигателей или установка поддерживаемого числа двигателей
+ /// The count engines.
+ public int CountEngines
+ {
+ get => (int)_countEngines;
+
+ set
+ {
+ int currCountEngines = Math.Clamp(value, 2, 6); // Отсекаем значения меньше 2 и больше 6
+ _countEngines = (CountEngines)(currCountEngines - currCountEngines % 2); // Значения между 2, 4, 6 округляем в нижнию сторону
+ }
+ }
+
+
+ /// Отрисовывает все двигатели на обеих крыльях
+ /// The g.
+ /// Цвет двигателей.
+ /// Позиция крыльев по x. В этой координате будут центры двигателей
+ /// Крайняя левая позиция левого крыла по y
+ /// Крайняя правая позиция правого крыла по y
+ /// Ширина тела самолета, или расстояние между крыльями.
+ public void DrawEngines(Graphics g, Color colorEngine, float wingPosX, float leftWingY, float rightWingY, int widthBodyAirplane)
+ {
+ float distanceBetweenEngines = (leftWingY - rightWingY - widthBodyAirplane) / 8.0f;
+ float centerY = rightWingY + (leftWingY - rightWingY) / 2.0f;
+ float distToWing = widthBodyAirplane / 2.0f;
+ for (var i = 1; i <= CountEngines / 2; i++)
+ {
+ DrawEngine(g, colorEngine, new RectangleF(wingPosX - 10, centerY - distToWing - distanceBetweenEngines * i - 5, 20, 10));
+ DrawEngine(g, colorEngine, new RectangleF(wingPosX - 10, centerY + distToWing + distanceBetweenEngines * i - 5, 20, 10));
+ }
+ }
+
+ private void DrawEngine(Graphics g, Color colorAirplane, RectangleF rectAroundEngine)
+ {
+ g.FillEllipse(new SolidBrush(colorAirplane), rectAroundEngine);
+ g.FillEllipse(new SolidBrush(Color.Black),
+ new RectangleF(rectAroundEngine.X, rectAroundEngine.Y, rectAroundEngine.Width / 4, rectAroundEngine.Height));
+ }
+ }
+}
diff --git a/AirBomber/AirBomber/FormAirBomber.Designer.cs b/AirBomber/AirBomber/FormAirBomber.Designer.cs
index bfc871f..52f71e3 100644
--- a/AirBomber/AirBomber/FormAirBomber.Designer.cs
+++ b/AirBomber/AirBomber/FormAirBomber.Designer.cs
@@ -38,8 +38,12 @@
this.buttonLeft = new System.Windows.Forms.Button();
this.buttonRight = new System.Windows.Forms.Button();
this.buttonDown = new System.Windows.Forms.Button();
+ this.countEngineBox = new System.Windows.Forms.NumericUpDown();
+ this.labelInformCountEngines = new System.Windows.Forms.Label();
+ this.toolStripStatusCountEngines = new System.Windows.Forms.ToolStripStatusLabel();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCar)).BeginInit();
this.statusStrip.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.countEngineBox)).BeginInit();
this.SuspendLayout();
//
// pictureBoxCar
@@ -51,7 +55,6 @@
this.pictureBoxCar.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.pictureBoxCar.TabIndex = 0;
this.pictureBoxCar.TabStop = false;
- this.pictureBoxCar.Click += new System.EventHandler(this.pictureBoxCar_Click);
this.pictureBoxCar.Resize += new System.EventHandler(this.PictureBoxCar_Resize);
//
// statusStrip
@@ -59,7 +62,8 @@
this.statusStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.toolStripStatusLabelSpeed,
this.toolStripStatusLabelWeight,
- this.toolStripStatusLabelBodyColor});
+ this.toolStripStatusLabelBodyColor,
+ this.toolStripStatusCountEngines});
this.statusStrip.Location = new System.Drawing.Point(0, 428);
this.statusStrip.Name = "statusStrip";
this.statusStrip.Size = new System.Drawing.Size(800, 22);
@@ -86,7 +90,7 @@
// buttonCreate
//
this.buttonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
- this.buttonCreate.Location = new System.Drawing.Point(12, 390);
+ this.buttonCreate.Location = new System.Drawing.Point(244, 390);
this.buttonCreate.Name = "buttonCreate";
this.buttonCreate.Size = new System.Drawing.Size(75, 23);
this.buttonCreate.TabIndex = 2;
@@ -142,11 +146,42 @@
this.buttonDown.UseVisualStyleBackColor = true;
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
//
+ // countEngineBox
+ //
+ this.countEngineBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
+ this.countEngineBox.Location = new System.Drawing.Point(142, 390);
+ this.countEngineBox.Maximum = new decimal(new int[] {
+ 10000,
+ 0,
+ 0,
+ 0});
+ this.countEngineBox.Name = "countEngineBox";
+ this.countEngineBox.Size = new System.Drawing.Size(96, 23);
+ this.countEngineBox.TabIndex = 7;
+ //
+ // labelInformCountEngines
+ //
+ this.labelInformCountEngines.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
+ this.labelInformCountEngines.AutoSize = true;
+ this.labelInformCountEngines.Location = new System.Drawing.Point(0, 394);
+ this.labelInformCountEngines.Name = "labelInformCountEngines";
+ this.labelInformCountEngines.Size = new System.Drawing.Size(139, 15);
+ this.labelInformCountEngines.TabIndex = 8;
+ this.labelInformCountEngines.Text = "Количество двигателей:";
+ //
+ // toolStripStatusCountEngines
+ //
+ this.toolStripStatusCountEngines.Name = "toolStripStatusCountEngines";
+ this.toolStripStatusCountEngines.Size = new System.Drawing.Size(139, 17);
+ this.toolStripStatusCountEngines.Text = "Количество двигателей:";
+ //
// FormAirBomber
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
+ this.Controls.Add(this.labelInformCountEngines);
+ this.Controls.Add(this.countEngineBox);
this.Controls.Add(this.buttonDown);
this.Controls.Add(this.buttonRight);
this.Controls.Add(this.buttonLeft);
@@ -159,6 +194,7 @@
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCar)).EndInit();
this.statusStrip.ResumeLayout(false);
this.statusStrip.PerformLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.countEngineBox)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
@@ -176,5 +212,8 @@
private Button buttonLeft;
private Button buttonRight;
private Button buttonDown;
+ private NumericUpDown countEngineBox;
+ private Label labelInformCountEngines;
+ private ToolStripStatusLabel toolStripStatusCountEngines;
}
}
\ No newline at end of file
diff --git a/AirBomber/AirBomber/FormAirBomber.cs b/AirBomber/AirBomber/FormAirBomber.cs
index 9623044..94c2e7c 100644
--- a/AirBomber/AirBomber/FormAirBomber.cs
+++ b/AirBomber/AirBomber/FormAirBomber.cs
@@ -28,10 +28,12 @@ namespace AirBomber
Random rnd = new();
_airplane = new DrawningAirplane();
_airplane.Init(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
+ _airplane.DrawningEngines.CountEngines = (int)countEngineBox.Value;
_airplane.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxCar.Width, pictureBoxCar.Height);
toolStripStatusLabelSpeed.Text = $": {_airplane.Airplane.Speed}";
toolStripStatusLabelWeight.Text = $": {_airplane.Airplane.Weight}";
toolStripStatusLabelBodyColor.Text = $": {_airplane.Airplane.BodyColor.Name}";
+ toolStripStatusCountEngines.Text = $" : {_airplane.DrawningEngines.CountEngines}";
Draw();
}
///
@@ -70,10 +72,5 @@ namespace AirBomber
_airplane?.ChangeBorders(pictureBoxCar.Width, pictureBoxCar.Height);
Draw();
}
-
- private void pictureBoxCar_Click(object sender, EventArgs e)
- {
-
- }
}
}
\ No newline at end of file