Добавлены двигатели самолета и возможность изменить их количество
This commit is contained in:
parent
44aa62d4c1
commit
e85c686be1
15
AirBomber/AirBomber/CountEngines.cs
Normal file
15
AirBomber/AirBomber/CountEngines.cs
Normal file
@ -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,
|
||||||
|
}
|
||||||
|
}
|
@ -9,6 +9,8 @@
|
|||||||
/// Класс-сущность
|
/// Класс-сущность
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public EntityAirplane Airplane { get; private set; }
|
public EntityAirplane Airplane { get; private set; }
|
||||||
|
|
||||||
|
public DrawningAirplaneEngines DrawningEngines { get; private set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Левая координата отрисовки автомобиля
|
/// Левая координата отрисовки автомобиля
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -43,6 +45,8 @@
|
|||||||
{
|
{
|
||||||
Airplane = new EntityAirplane();
|
Airplane = new EntityAirplane();
|
||||||
Airplane.Init(speed, weight, bodyColor);
|
Airplane.Init(speed, weight, bodyColor);
|
||||||
|
DrawningEngines = new();
|
||||||
|
DrawningEngines.CountEngines = 6;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Установка позиции самолета
|
/// Установка позиции самолета
|
||||||
@ -151,6 +155,8 @@
|
|||||||
});
|
});
|
||||||
// Конец хвоста
|
// Конец хвоста
|
||||||
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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
57
AirBomber/AirBomber/DrawningAirplaneEngines.cs
Normal file
57
AirBomber/AirBomber/DrawningAirplaneEngines.cs
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AirBomber
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Класс-дополнение к самолету отвечающий за число двигателей и их отрисовку
|
||||||
|
/// </summary>
|
||||||
|
internal class DrawningAirplaneEngines
|
||||||
|
{
|
||||||
|
/// <summary>Приватное поле содержащие текущее количество двигателей самолета</summary>
|
||||||
|
private CountEngines _countEngines;
|
||||||
|
|
||||||
|
/// <summary>Получение действительного количества двигателей или установка поддерживаемого числа двигателей</summary>
|
||||||
|
/// <value>The count engines.</value>
|
||||||
|
public int CountEngines
|
||||||
|
{
|
||||||
|
get => (int)_countEngines;
|
||||||
|
|
||||||
|
set
|
||||||
|
{
|
||||||
|
int currCountEngines = Math.Clamp(value, 2, 6); // Отсекаем значения меньше 2 и больше 6
|
||||||
|
_countEngines = (CountEngines)(currCountEngines - currCountEngines % 2); // Значения между 2, 4, 6 округляем в нижнию сторону
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>Отрисовывает все двигатели на обеих крыльях</summary>
|
||||||
|
/// <param name="g">The g.</param>
|
||||||
|
/// <param name="colorEngine">Цвет двигателей.</param>
|
||||||
|
/// <param name="wingPosX">Позиция крыльев по x. В этой координате будут центры двигателей</param>
|
||||||
|
/// <param name="leftWingY">Крайняя левая позиция левого крыла по y</param>
|
||||||
|
/// <param name="rightWingY">Крайняя правая позиция правого крыла по y</param>
|
||||||
|
/// <param name="widthBodyAirplane">Ширина тела самолета, или расстояние между крыльями.</param>
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
45
AirBomber/AirBomber/FormAirBomber.Designer.cs
generated
45
AirBomber/AirBomber/FormAirBomber.Designer.cs
generated
@ -38,8 +38,12 @@
|
|||||||
this.buttonLeft = new System.Windows.Forms.Button();
|
this.buttonLeft = new System.Windows.Forms.Button();
|
||||||
this.buttonRight = new System.Windows.Forms.Button();
|
this.buttonRight = new System.Windows.Forms.Button();
|
||||||
this.buttonDown = 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();
|
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCar)).BeginInit();
|
||||||
this.statusStrip.SuspendLayout();
|
this.statusStrip.SuspendLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.countEngineBox)).BeginInit();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
//
|
//
|
||||||
// pictureBoxCar
|
// pictureBoxCar
|
||||||
@ -51,7 +55,6 @@
|
|||||||
this.pictureBoxCar.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
|
this.pictureBoxCar.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
|
||||||
this.pictureBoxCar.TabIndex = 0;
|
this.pictureBoxCar.TabIndex = 0;
|
||||||
this.pictureBoxCar.TabStop = false;
|
this.pictureBoxCar.TabStop = false;
|
||||||
this.pictureBoxCar.Click += new System.EventHandler(this.pictureBoxCar_Click);
|
|
||||||
this.pictureBoxCar.Resize += new System.EventHandler(this.PictureBoxCar_Resize);
|
this.pictureBoxCar.Resize += new System.EventHandler(this.PictureBoxCar_Resize);
|
||||||
//
|
//
|
||||||
// statusStrip
|
// statusStrip
|
||||||
@ -59,7 +62,8 @@
|
|||||||
this.statusStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
this.statusStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||||
this.toolStripStatusLabelSpeed,
|
this.toolStripStatusLabelSpeed,
|
||||||
this.toolStripStatusLabelWeight,
|
this.toolStripStatusLabelWeight,
|
||||||
this.toolStripStatusLabelBodyColor});
|
this.toolStripStatusLabelBodyColor,
|
||||||
|
this.toolStripStatusCountEngines});
|
||||||
this.statusStrip.Location = new System.Drawing.Point(0, 428);
|
this.statusStrip.Location = new System.Drawing.Point(0, 428);
|
||||||
this.statusStrip.Name = "statusStrip";
|
this.statusStrip.Name = "statusStrip";
|
||||||
this.statusStrip.Size = new System.Drawing.Size(800, 22);
|
this.statusStrip.Size = new System.Drawing.Size(800, 22);
|
||||||
@ -86,7 +90,7 @@
|
|||||||
// 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(12, 390);
|
this.buttonCreate.Location = new System.Drawing.Point(244, 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;
|
||||||
@ -142,11 +146,42 @@
|
|||||||
this.buttonDown.UseVisualStyleBackColor = true;
|
this.buttonDown.UseVisualStyleBackColor = true;
|
||||||
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
|
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
|
// 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.labelInformCountEngines);
|
||||||
|
this.Controls.Add(this.countEngineBox);
|
||||||
this.Controls.Add(this.buttonDown);
|
this.Controls.Add(this.buttonDown);
|
||||||
this.Controls.Add(this.buttonRight);
|
this.Controls.Add(this.buttonRight);
|
||||||
this.Controls.Add(this.buttonLeft);
|
this.Controls.Add(this.buttonLeft);
|
||||||
@ -159,6 +194,7 @@
|
|||||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCar)).EndInit();
|
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCar)).EndInit();
|
||||||
this.statusStrip.ResumeLayout(false);
|
this.statusStrip.ResumeLayout(false);
|
||||||
this.statusStrip.PerformLayout();
|
this.statusStrip.PerformLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.countEngineBox)).EndInit();
|
||||||
this.ResumeLayout(false);
|
this.ResumeLayout(false);
|
||||||
this.PerformLayout();
|
this.PerformLayout();
|
||||||
|
|
||||||
@ -176,5 +212,8 @@
|
|||||||
private Button buttonLeft;
|
private Button buttonLeft;
|
||||||
private Button buttonRight;
|
private Button buttonRight;
|
||||||
private Button buttonDown;
|
private Button buttonDown;
|
||||||
|
private NumericUpDown countEngineBox;
|
||||||
|
private Label labelInformCountEngines;
|
||||||
|
private ToolStripStatusLabel toolStripStatusCountEngines;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -28,10 +28,12 @@ namespace AirBomber
|
|||||||
Random rnd = new();
|
Random rnd = new();
|
||||||
_airplane = new DrawningAirplane();
|
_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.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);
|
_airplane.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxCar.Width, pictureBoxCar.Height);
|
||||||
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_airplane.Airplane.Speed}";
|
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_airplane.Airplane.Speed}";
|
||||||
toolStripStatusLabelWeight.Text = $"Âåñ: {_airplane.Airplane.Weight}";
|
toolStripStatusLabelWeight.Text = $"Âåñ: {_airplane.Airplane.Weight}";
|
||||||
toolStripStatusLabelBodyColor.Text = $"Öâåò: {_airplane.Airplane.BodyColor.Name}";
|
toolStripStatusLabelBodyColor.Text = $"Öâåò: {_airplane.Airplane.BodyColor.Name}";
|
||||||
|
toolStripStatusCountEngines.Text = $"Êîëè÷åñòâî äâèãàòåëåé: {_airplane.DrawningEngines.CountEngines}";
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -70,10 +72,5 @@ namespace AirBomber
|
|||||||
_airplane?.ChangeBorders(pictureBoxCar.Width, pictureBoxCar.Height);
|
_airplane?.ChangeBorders(pictureBoxCar.Width, pictureBoxCar.Height);
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void pictureBoxCar_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user