From a02a602dceeef2c38c2b81371b9448c42587856f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D1=8F=D1=80=20=D0=90=D0=B3=D0=BB?= =?UTF-8?q?=D0=B8=D1=83=D0=BB=D0=BB=D0=BE=D0=B2?= Date: Thu, 22 Sep 2022 07:50:53 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=20=D1=81=D0=BF=D0=BE=D1=81=D0=BE=D0=B1=20?= =?UTF-8?q?=D0=B8=D0=BD=D0=B8=D1=86=D0=B8=D0=B0=D0=BB=D0=B8=D0=B7=D0=B0?= =?UTF-8?q?=D1=86=D0=B8=D0=B8=20=D1=80=D0=B0=D0=B7=D0=BD=D1=8B=D1=85=20?= =?UTF-8?q?=D1=82=D0=B8=D0=BF=D0=BE=D0=B2=20=D0=B4=D0=B2=D0=B8=D0=B3=D0=B0?= =?UTF-8?q?=D1=82=D0=B5=D0=BB=D0=B5=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/DrawningAirBomber.cs | 5 +-- AirBomber/AirBomber/DrawningAirplane.cs | 18 +++++----- AirBomber/AirBomber/FormAirBomber.Designer.cs | 34 ++++++++++++++----- AirBomber/AirBomber/FormAirBomber.cs | 17 +++++++++- 4 files changed, 54 insertions(+), 20 deletions(-) diff --git a/AirBomber/AirBomber/DrawningAirBomber.cs b/AirBomber/AirBomber/DrawningAirBomber.cs index 2f5da52..b17f7c4 100644 --- a/AirBomber/AirBomber/DrawningAirBomber.cs +++ b/AirBomber/AirBomber/DrawningAirBomber.cs @@ -19,8 +19,9 @@ namespace AirBomber /// Дополнительный цвет /// Признак наличия бомб /// Признак наличия топливных баков - public DrawningAirBomber(int speed, float weight, Color bodyColor, Color dopColor, bool hasBombs, bool hasFuelTanks) - : base(speed, weight, bodyColor, 115, 155) + /// Какой будет двигатель самолета. null - двигатели отсутствуют + 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); } diff --git a/AirBomber/AirBomber/DrawningAirplane.cs b/AirBomber/AirBomber/DrawningAirplane.cs index 45e005b..754387a 100644 --- a/AirBomber/AirBomber/DrawningAirplane.cs +++ b/AirBomber/AirBomber/DrawningAirplane.cs @@ -10,7 +10,7 @@ /// public EntityAirplane Airplane { get; protected set; } - public IAirplaneEngines DrawningEngines { get; private set; } + public IAirplaneEngines? DrawningEngines { get; private set; } /// /// Левая координата отрисовки автомобиля /// @@ -30,21 +30,22 @@ /// /// Ширина отрисовки автомобиля /// - protected readonly int _airplaneWidth = 80; + protected readonly int _airplaneWidth = 90; /// /// Высота отрисовки автомобиля /// - protected readonly int _airplaneHeight = 90; + protected readonly int _airplaneHeight = 105; /// /// Инициализация свойств /// /// Скорость /// Вес самолета /// Цвет обшивки - public DrawningAirplane(int speed, float weight, Color bodyColor) + /// Какой будет двигатель самолета. null - двигатели отсутствуют + public DrawningAirplane(int speed, float weight, Color bodyColor, IAirplaneEngines? typeAirplaneEngines = null) { Airplane = new EntityAirplane(speed, weight, bodyColor); - DrawningEngines = new DrawningAirplaneEngines(); + DrawningEngines = typeAirplaneEngines; } /// @@ -55,8 +56,9 @@ /// Цвет обшивки /// Ширина отрисовки самолета /// Высота отрисовки самолета - protected DrawningAirplane(int speed, float weight, Color bodyColor, int airplaneWidth, int airplaneHeight) : - this(speed, weight, bodyColor) + /// Какой будет двигатель самолета. null - двигатели отсутствуют + protected DrawningAirplane(int speed, float weight, Color bodyColor, int airplaneWidth, int airplaneHeight, IAirplaneEngines? typeAirplaneEngines) : + this(speed, weight, bodyColor, typeAirplaneEngines) { _airplaneWidth = airplaneWidth; _airplaneHeight = airplaneHeight; @@ -169,7 +171,7 @@ // Конец хвоста 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); } diff --git a/AirBomber/AirBomber/FormAirBomber.Designer.cs b/AirBomber/AirBomber/FormAirBomber.Designer.cs index 52f71e3..e140578 100644 --- a/AirBomber/AirBomber/FormAirBomber.Designer.cs +++ b/AirBomber/AirBomber/FormAirBomber.Designer.cs @@ -33,6 +33,7 @@ this.toolStripStatusLabelSpeed = new System.Windows.Forms.ToolStripStatusLabel(); this.toolStripStatusLabelWeight = 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.buttonUp = new System.Windows.Forms.Button(); this.buttonLeft = new System.Windows.Forms.Button(); @@ -40,7 +41,7 @@ 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(); + this.comboTypeEngines = new System.Windows.Forms.ComboBox(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxCar)).BeginInit(); this.statusStrip.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.countEngineBox)).BeginInit(); @@ -87,10 +88,16 @@ this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(36, 17); this.toolStripStatusLabelBodyColor.Text = "Цвет:"; // + // toolStripStatusCountEngines + // + this.toolStripStatusCountEngines.Name = "toolStripStatusCountEngines"; + this.toolStripStatusCountEngines.Size = new System.Drawing.Size(139, 17); + this.toolStripStatusCountEngines.Text = "Количество двигателей:"; + // // 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(244, 390); + this.buttonCreate.Location = new System.Drawing.Point(372, 390); this.buttonCreate.Name = "buttonCreate"; this.buttonCreate.Size = new System.Drawing.Size(75, 23); this.buttonCreate.TabIndex = 2; @@ -149,37 +156,45 @@ // 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.Location = new System.Drawing.Point(306, 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.Size = new System.Drawing.Size(60, 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.Location = new System.Drawing.Point(161, 394); this.labelInformCountEngines.Name = "labelInformCountEngines"; this.labelInformCountEngines.Size = new System.Drawing.Size(139, 15); this.labelInformCountEngines.TabIndex = 8; this.labelInformCountEngines.Text = "Количество двигателей:"; // - // toolStripStatusCountEngines + // comboTypeEngines // - this.toolStripStatusCountEngines.Name = "toolStripStatusCountEngines"; - this.toolStripStatusCountEngines.Size = new System.Drawing.Size(139, 17); - this.toolStripStatusCountEngines.Text = "Количество двигателей:"; + this.comboTypeEngines.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.comboTypeEngines.FormattingEnabled = true; + 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 // 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.comboTypeEngines); this.Controls.Add(this.labelInformCountEngines); this.Controls.Add(this.countEngineBox); this.Controls.Add(this.buttonDown); @@ -215,5 +230,6 @@ private NumericUpDown countEngineBox; private Label labelInformCountEngines; private ToolStripStatusLabel toolStripStatusCountEngines; + private ComboBox comboTypeEngines; } } \ No newline at end of file diff --git a/AirBomber/AirBomber/FormAirBomber.cs b/AirBomber/AirBomber/FormAirBomber.cs index d57444b..4302b71 100644 --- a/AirBomber/AirBomber/FormAirBomber.cs +++ b/AirBomber/AirBomber/FormAirBomber.cs @@ -25,8 +25,23 @@ namespace AirBomber /// 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(); - _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.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxCar.Width, pictureBoxCar.Height); toolStripStatusLabelSpeed.Text = $": {_airplane.Airplane.Speed}";