Добавлен интерфейс для отрисовки иллюминаторов разной формы.
This commit is contained in:
parent
910d16250b
commit
d3ef8ea0e2
@ -10,7 +10,7 @@ namespace AirplaneWithRadar
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntityAirplane Airplane { private set; get; }
|
||||
public DrawningAirplanePortholes DrawningPortholes { get; private set; }
|
||||
public IAirplanePortholes DrawningPortholes { get; private set; }
|
||||
/// <summary>
|
||||
/// Левая координата отрисовки самолёта
|
||||
/// </summary>
|
||||
@ -41,12 +41,10 @@ namespace AirplaneWithRadar
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Цвет</param>
|
||||
public void Init(int speed, float weight, Color bodyColor)
|
||||
public DrawningAirplane(int speed, float weight, Color bodyColor, IAirplanePortholes typeAirplanePortholes)
|
||||
{
|
||||
Airplane = new EntityAirplane();
|
||||
Airplane.Init(speed, weight, bodyColor);
|
||||
DrawningPortholes = new();
|
||||
DrawningPortholes.CountPortholes = 10;
|
||||
Airplane = new EntityAirplane(speed, weight, bodyColor);
|
||||
DrawningPortholes = typeAirplanePortholes;
|
||||
}
|
||||
/// <summary>
|
||||
/// Установка позиции
|
||||
|
@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace AirplaneWithRadar
|
||||
{
|
||||
internal class DrawningAirplanePortholes
|
||||
internal class DrawningAirplanePortholes : IAirplanePortholes
|
||||
{
|
||||
private CountPortholes _countPortholes;
|
||||
|
||||
@ -33,7 +33,7 @@ namespace AirplaneWithRadar
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawPorthole(Graphics g, int _startPosX, int _startPosY)
|
||||
protected virtual void DrawPorthole(Graphics g, int _startPosX, int _startPosY)
|
||||
{
|
||||
Pen pen = new(Color.Black);
|
||||
g.DrawRectangle(pen, _startPosX, _startPosY, 2, 2);
|
||||
|
@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AirplaneWithRadar
|
||||
{
|
||||
internal class DrawningDeltaPortholes : DrawningAirplanePortholes
|
||||
{
|
||||
protected override void DrawPorthole(Graphics g, int _startPosX, int _startPosY)
|
||||
{
|
||||
Pen pen = new (Color.Black);
|
||||
PointF[] point = new PointF[3];
|
||||
point[0] = new PointF(_startPosX, _startPosY);
|
||||
point[1] = new PointF(_startPosX-2, _startPosY+2);
|
||||
point[2] = new PointF(_startPosX + 2, _startPosY + 2);
|
||||
g.DrawPolygon(pen, point);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AirplaneWithRadar
|
||||
{
|
||||
internal class DrawningRhombusPortholes : DrawningAirplanePortholes
|
||||
{
|
||||
protected override void DrawPorthole(Graphics g, int _startPosX, int _startPosY)
|
||||
{
|
||||
Pen pen = new(Color.Black);
|
||||
PointF[] point = new PointF[4];
|
||||
point[0] = new PointF(_startPosX, _startPosY);
|
||||
point[1] = new PointF(_startPosX - 2, _startPosY + 2);
|
||||
point[2] = new PointF(_startPosX, _startPosY + 4);
|
||||
point[3] = new PointF(_startPosX + 2, _startPosY + 2);
|
||||
g.DrawPolygon(pen, point);
|
||||
}
|
||||
}
|
||||
}
|
@ -29,7 +29,7 @@ namespace AirplaneWithRadar
|
||||
/// <param name="weight"></param>
|
||||
/// <param name="bodyColor"></param>
|
||||
/// <returns></returns>
|
||||
public void Init(int speed, float weight, Color bodyColor)
|
||||
public EntityAirplane(int speed, float weight, Color bodyColor)
|
||||
{
|
||||
Random rnd = new();
|
||||
Speed = speed <= 0 ? rnd.Next(50, 150) : speed;
|
||||
|
@ -40,6 +40,7 @@
|
||||
this.buttonRight = new System.Windows.Forms.Button();
|
||||
this.labelPortholes = new System.Windows.Forms.Label();
|
||||
this.comboBoxPortholes = new System.Windows.Forms.ComboBox();
|
||||
this.comboBoxTypePortholes = new System.Windows.Forms.ComboBox();
|
||||
this.statusStrip1.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxAirplane)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
@ -94,7 +95,7 @@
|
||||
this.buttonCreate.TabIndex = 2;
|
||||
this.buttonCreate.Text = "Создать";
|
||||
this.buttonCreate.UseVisualStyleBackColor = true;
|
||||
this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click);
|
||||
this.buttonCreate.Click += new System.EventHandler(this.ButtonCreate_Click);
|
||||
//
|
||||
// buttonUp
|
||||
//
|
||||
@ -166,11 +167,25 @@
|
||||
this.comboBoxPortholes.TabIndex = 8;
|
||||
this.comboBoxPortholes.Text = "10";
|
||||
//
|
||||
// comboBoxTypePortholes
|
||||
//
|
||||
this.comboBoxTypePortholes.FormattingEnabled = true;
|
||||
this.comboBoxTypePortholes.Items.AddRange(new object[] {
|
||||
"Квадратные",
|
||||
"Треугольные",
|
||||
"Ромбовидные"});
|
||||
this.comboBoxTypePortholes.Location = new System.Drawing.Point(12, 338);
|
||||
this.comboBoxTypePortholes.Name = "comboBoxTypePortholes";
|
||||
this.comboBoxTypePortholes.Size = new System.Drawing.Size(121, 23);
|
||||
this.comboBoxTypePortholes.TabIndex = 9;
|
||||
this.comboBoxTypePortholes.Text = "Квадратные";
|
||||
//
|
||||
// FormAirplane
|
||||
//
|
||||
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.comboBoxTypePortholes);
|
||||
this.Controls.Add(this.comboBoxPortholes);
|
||||
this.Controls.Add(this.labelPortholes);
|
||||
this.Controls.Add(this.buttonRight);
|
||||
@ -204,5 +219,6 @@
|
||||
private Button buttonRight;
|
||||
private Label labelPortholes;
|
||||
private ComboBox comboBoxPortholes;
|
||||
private ComboBox comboBoxTypePortholes;
|
||||
}
|
||||
}
|
@ -27,11 +27,20 @@ namespace AirplaneWithRadar
|
||||
/// <param name="e"></param>
|
||||
///
|
||||
|
||||
private void buttonCreate_Click(object sender, EventArgs e)
|
||||
private void ButtonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
IAirplanePortholes typeAirplanePortholes = new DrawningAirplanePortholes();
|
||||
switch (comboBoxTypePortholes.Text)
|
||||
{
|
||||
case "Òðåóãîëüíûå":
|
||||
typeAirplanePortholes = new DrawningDeltaPortholes();
|
||||
break;
|
||||
case "Ðîìáîâèäíûå":
|
||||
typeAirplanePortholes = new DrawningRhombusPortholes();
|
||||
break;
|
||||
}
|
||||
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 = new DrawningAirplane(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), typeAirplanePortholes);
|
||||
_airplane.DrawningPortholes.CountPortholes = Convert.ToInt32(comboBoxPortholes.Text);
|
||||
_airplane.SetPosition(rnd.Next(20, 100), rnd.Next(20, 100), pictureBoxAirplane.Width, pictureBoxAirplane.Height);
|
||||
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_airplane.Airplane.Speed}";
|
||||
@ -76,5 +85,6 @@ namespace AirplaneWithRadar
|
||||
_airplane?.ChangeBorders(pictureBoxAirplane.Width, pictureBoxAirplane.Height);
|
||||
Draw();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
14
AirplaneWithRadar/AirplaneWithRadar/IAirplanePortholes.cs
Normal file
14
AirplaneWithRadar/AirplaneWithRadar/IAirplanePortholes.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AirplaneWithRadar
|
||||
{
|
||||
internal interface IAirplanePortholes
|
||||
{
|
||||
int CountPortholes { set; }
|
||||
public void DrawPortholes(Graphics g, int _startPosX, int _startPosY, int _airplaneWidth);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user