Реализован способ инициализации разных типов двигателей

This commit is contained in:
Данияр Аглиуллов 2022-09-22 07:50:53 +04:00
parent 006cea0aca
commit a02a602dce
4 changed files with 54 additions and 20 deletions

View File

@ -19,8 +19,9 @@ namespace AirBomber
/// <param name="dopColor">Дополнительный цвет</param> /// <param name="dopColor">Дополнительный цвет</param>
/// <param name="hasBombs">Признак наличия бомб</param> /// <param name="hasBombs">Признак наличия бомб</param>
/// <param name="hasFuelTanks">Признак наличия топливных баков</param> /// <param name="hasFuelTanks">Признак наличия топливных баков</param>
public DrawningAirBomber(int speed, float weight, Color bodyColor, Color dopColor, bool hasBombs, bool hasFuelTanks) /// <param name="typeAirplaneEngines">Какой будет двигатель самолета. null - двигатели отсутствуют</param>
: base(speed, weight, bodyColor, 115, 155) public DrawningAirBomber(int speed, float weight, Color bodyColor, Color dopColor, bool hasBombs, bool hasFuelTanks, IAirplaneEngines? typeAirplaneEngines = null)
: base(speed, weight, bodyColor, 115, 155, typeAirplaneEngines)
{ {
Airplane = new EntityAirBomber(speed, weight, bodyColor, dopColor, hasBombs, hasFuelTanks); Airplane = new EntityAirBomber(speed, weight, bodyColor, dopColor, hasBombs, hasFuelTanks);
} }

View File

@ -10,7 +10,7 @@
/// </summary> /// </summary>
public EntityAirplane Airplane { get; protected set; } public EntityAirplane Airplane { get; protected set; }
public IAirplaneEngines DrawningEngines { get; private set; } public IAirplaneEngines? DrawningEngines { get; private set; }
/// <summary> /// <summary>
/// Левая координата отрисовки автомобиля /// Левая координата отрисовки автомобиля
/// </summary> /// </summary>
@ -30,21 +30,22 @@
/// <summary> /// <summary>
/// Ширина отрисовки автомобиля /// Ширина отрисовки автомобиля
/// </summary> /// </summary>
protected readonly int _airplaneWidth = 80; protected readonly int _airplaneWidth = 90;
/// <summary> /// <summary>
/// Высота отрисовки автомобиля /// Высота отрисовки автомобиля
/// </summary> /// </summary>
protected readonly int _airplaneHeight = 90; protected readonly int _airplaneHeight = 105;
/// <summary> /// <summary>
/// Инициализация свойств /// Инициализация свойств
/// </summary> /// </summary>
/// <param name="speed">Скорость</param> /// <param name="speed">Скорость</param>
/// <param name="weight">Вес самолета</param> /// <param name="weight">Вес самолета</param>
/// <param name="bodyColor">Цвет обшивки</param> /// <param name="bodyColor">Цвет обшивки</param>
public DrawningAirplane(int speed, float weight, Color bodyColor) /// <param name="typeAirplaneEngines">Какой будет двигатель самолета. null - двигатели отсутствуют</param>
public DrawningAirplane(int speed, float weight, Color bodyColor, IAirplaneEngines? typeAirplaneEngines = null)
{ {
Airplane = new EntityAirplane(speed, weight, bodyColor); Airplane = new EntityAirplane(speed, weight, bodyColor);
DrawningEngines = new DrawningAirplaneEngines(); DrawningEngines = typeAirplaneEngines;
} }
/// <summary> /// <summary>
@ -55,8 +56,9 @@
/// <param name="bodyColor">Цвет обшивки</param> /// <param name="bodyColor">Цвет обшивки</param>
/// <param name="airplaneWidth">Ширина отрисовки самолета</param> /// <param name="airplaneWidth">Ширина отрисовки самолета</param>
/// <param name="airplaneHeight">Высота отрисовки самолета</param> /// <param name="airplaneHeight">Высота отрисовки самолета</param>
protected DrawningAirplane(int speed, float weight, Color bodyColor, int airplaneWidth, int airplaneHeight) : /// <param name="typeAirplaneEngines">Какой будет двигатель самолета. null - двигатели отсутствуют</param>
this(speed, weight, bodyColor) protected DrawningAirplane(int speed, float weight, Color bodyColor, int airplaneWidth, int airplaneHeight, IAirplaneEngines? typeAirplaneEngines) :
this(speed, weight, bodyColor, typeAirplaneEngines)
{ {
_airplaneWidth = airplaneWidth; _airplaneWidth = airplaneWidth;
_airplaneHeight = airplaneHeight; _airplaneHeight = airplaneHeight;
@ -169,7 +171,7 @@
// Конец хвоста // Конец хвоста
g.FillRectangle(BodyColorBrush, x + w - 5, y + 15, 5, h - 30); g.FillRectangle(BodyColorBrush, x + w - 5, y + 15, 5, h - 30);
// Двигатели // Двигатели
DrawningEngines.DrawEngines(g, Airplane.BodyColor, x + w / 2 - 20, y + h, y, 15); DrawningEngines?.DrawEngines(g, Airplane.BodyColor, x + w / 2 - 20, y + h, y, 15);
} }

View File

@ -33,6 +33,7 @@
this.toolStripStatusLabelSpeed = new System.Windows.Forms.ToolStripStatusLabel(); this.toolStripStatusLabelSpeed = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusLabelWeight = new System.Windows.Forms.ToolStripStatusLabel(); this.toolStripStatusLabelWeight = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusLabelBodyColor = new System.Windows.Forms.ToolStripStatusLabel(); this.toolStripStatusLabelBodyColor = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusCountEngines = new System.Windows.Forms.ToolStripStatusLabel();
this.buttonCreate = new System.Windows.Forms.Button(); this.buttonCreate = new System.Windows.Forms.Button();
this.buttonUp = new System.Windows.Forms.Button(); this.buttonUp = new System.Windows.Forms.Button();
this.buttonLeft = new System.Windows.Forms.Button(); this.buttonLeft = new System.Windows.Forms.Button();
@ -40,7 +41,7 @@
this.buttonDown = new System.Windows.Forms.Button(); this.buttonDown = new System.Windows.Forms.Button();
this.countEngineBox = new System.Windows.Forms.NumericUpDown(); this.countEngineBox = new System.Windows.Forms.NumericUpDown();
this.labelInformCountEngines = new System.Windows.Forms.Label(); this.labelInformCountEngines = new System.Windows.Forms.Label();
this.toolStripStatusCountEngines = new System.Windows.Forms.ToolStripStatusLabel(); this.comboTypeEngines = new System.Windows.Forms.ComboBox();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCar)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxCar)).BeginInit();
this.statusStrip.SuspendLayout(); this.statusStrip.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.countEngineBox)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.countEngineBox)).BeginInit();
@ -87,10 +88,16 @@
this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(36, 17); this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(36, 17);
this.toolStripStatusLabelBodyColor.Text = "Цвет:"; this.toolStripStatusLabelBodyColor.Text = "Цвет:";
// //
// toolStripStatusCountEngines
//
this.toolStripStatusCountEngines.Name = "toolStripStatusCountEngines";
this.toolStripStatusCountEngines.Size = new System.Drawing.Size(139, 17);
this.toolStripStatusCountEngines.Text = "Количество двигателей:";
//
// buttonCreate // buttonCreate
// //
this.buttonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.buttonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.buttonCreate.Location = new System.Drawing.Point(244, 390); this.buttonCreate.Location = new System.Drawing.Point(372, 390);
this.buttonCreate.Name = "buttonCreate"; this.buttonCreate.Name = "buttonCreate";
this.buttonCreate.Size = new System.Drawing.Size(75, 23); this.buttonCreate.Size = new System.Drawing.Size(75, 23);
this.buttonCreate.TabIndex = 2; this.buttonCreate.TabIndex = 2;
@ -149,37 +156,45 @@
// countEngineBox // countEngineBox
// //
this.countEngineBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); 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.Location = new System.Drawing.Point(306, 390);
this.countEngineBox.Maximum = new decimal(new int[] { this.countEngineBox.Maximum = new decimal(new int[] {
10000, 10000,
0, 0,
0, 0,
0}); 0});
this.countEngineBox.Name = "countEngineBox"; this.countEngineBox.Name = "countEngineBox";
this.countEngineBox.Size = new System.Drawing.Size(96, 23); this.countEngineBox.Size = new System.Drawing.Size(60, 23);
this.countEngineBox.TabIndex = 7; this.countEngineBox.TabIndex = 7;
// //
// labelInformCountEngines // labelInformCountEngines
// //
this.labelInformCountEngines.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.labelInformCountEngines.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.labelInformCountEngines.AutoSize = true; this.labelInformCountEngines.AutoSize = true;
this.labelInformCountEngines.Location = new System.Drawing.Point(0, 394); this.labelInformCountEngines.Location = new System.Drawing.Point(161, 394);
this.labelInformCountEngines.Name = "labelInformCountEngines"; this.labelInformCountEngines.Name = "labelInformCountEngines";
this.labelInformCountEngines.Size = new System.Drawing.Size(139, 15); this.labelInformCountEngines.Size = new System.Drawing.Size(139, 15);
this.labelInformCountEngines.TabIndex = 8; this.labelInformCountEngines.TabIndex = 8;
this.labelInformCountEngines.Text = "Количество двигателей:"; this.labelInformCountEngines.Text = "Количество двигателей:";
// //
// toolStripStatusCountEngines // comboTypeEngines
// //
this.toolStripStatusCountEngines.Name = "toolStripStatusCountEngines"; this.comboTypeEngines.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.toolStripStatusCountEngines.Size = new System.Drawing.Size(139, 17); this.comboTypeEngines.FormattingEnabled = true;
this.toolStripStatusCountEngines.Text = "Количество двигателей:"; this.comboTypeEngines.Items.AddRange(new object[] {
"Закругленный",
"Квадратный",
"Стрелка"});
this.comboTypeEngines.Location = new System.Drawing.Point(12, 390);
this.comboTypeEngines.Name = "comboTypeEngines";
this.comboTypeEngines.Size = new System.Drawing.Size(143, 23);
this.comboTypeEngines.TabIndex = 9;
// //
// FormAirBomber // FormAirBomber
// //
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(800, 450); this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.comboTypeEngines);
this.Controls.Add(this.labelInformCountEngines); this.Controls.Add(this.labelInformCountEngines);
this.Controls.Add(this.countEngineBox); this.Controls.Add(this.countEngineBox);
this.Controls.Add(this.buttonDown); this.Controls.Add(this.buttonDown);
@ -215,5 +230,6 @@
private NumericUpDown countEngineBox; private NumericUpDown countEngineBox;
private Label labelInformCountEngines; private Label labelInformCountEngines;
private ToolStripStatusLabel toolStripStatusCountEngines; private ToolStripStatusLabel toolStripStatusCountEngines;
private ComboBox comboTypeEngines;
} }
} }

View File

@ -25,8 +25,23 @@ namespace AirBomber
/// <param name="e"></param> /// <param name="e"></param>
private void ButtonCreate_Click(object sender, EventArgs e) private void ButtonCreate_Click(object sender, EventArgs e)
{ {
IAirplaneEngines? typeAirplaneEngines = null;
switch (comboTypeEngines.Text)
{
case "Êâàäðàòíûé":
typeAirplaneEngines = new AirplaneRectEngines();
break;
case "Ñòðåëêà":
typeAirplaneEngines = new AirplaneArrowEngines();
break;
default:
typeAirplaneEngines = new DrawningAirplaneEngines();
break;
}
Random rnd = new(); Random rnd = new();
_airplane = new DrawningAirplane(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); _airplane = new DrawningAirplane(rnd.Next(100, 300), rnd.Next(1000, 2000),
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
typeAirplaneEngines);
_airplane.DrawningEngines.CountEngines = (int)countEngineBox.Value; _airplane.DrawningEngines.CountEngines = (int)countEngineBox.Value;
_airplane.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxCar.Width, pictureBoxCar.Height); _airplane.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxCar.Width, pictureBoxCar.Height);
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_airplane.Airplane.Speed}"; toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_airplane.Airplane.Speed}";