Добавлен продвинутый объект
This commit is contained in:
parent
d3ef8ea0e2
commit
307b802e23
@ -9,32 +9,32 @@ namespace AirplaneWithRadar
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Класс-сущность
|
/// Класс-сущность
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public EntityAirplane Airplane { private set; get; }
|
public EntityAirplane Airplane { protected set; get; }
|
||||||
public IAirplanePortholes DrawningPortholes { get; private set; }
|
public IAirplanePortholes DrawningPortholes { get; private set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Левая координата отрисовки самолёта
|
/// Левая координата отрисовки самолёта
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private float _startPosX;
|
protected float _startPosX;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Верхняя кооридната отрисовки самолёта
|
/// Верхняя кооридната отрисовки самолёта
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private float _startPosY;
|
protected float _startPosY;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ширина окна отрисовки
|
/// Ширина окна отрисовки
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private int? _pictureWidth = null;
|
protected int? _pictureWidth = null;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Высота окна отрисовки
|
/// Высота окна отрисовки
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private int? _pictureHeight = null;
|
protected int? _pictureHeight = null;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ширина отрисовки
|
/// Ширина отрисовки
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly int _airplaneWidth = 100;
|
protected readonly int _airplaneWidth = 100;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Высота отрисовки самолёта
|
/// Высота отрисовки самолёта
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly int _airplaneHeight = 20;
|
protected readonly int _airplaneHeight = 20;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Инициализация свойств
|
/// Инициализация свойств
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -46,6 +46,22 @@ namespace AirplaneWithRadar
|
|||||||
Airplane = new EntityAirplane(speed, weight, bodyColor);
|
Airplane = new EntityAirplane(speed, weight, bodyColor);
|
||||||
DrawningPortholes = typeAirplanePortholes;
|
DrawningPortholes = typeAirplanePortholes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Инициализация свойств
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="speed">Скорость</param>
|
||||||
|
/// <param name="weight">Вес самолёта</param>
|
||||||
|
/// <param name="bodyColor">Цвет кузова</param>
|
||||||
|
/// <param name="airplaneWidth">Ширина отрисовки самолёта</param>
|
||||||
|
/// <param name="airplaneHeight">Высота отрисовки самолёта</param>
|
||||||
|
protected DrawningAirplane(int speed, float weight, Color bodyColor, int airplaneWidth, int airplaneHeight, IAirplanePortholes typeAirplanePortholes) :
|
||||||
|
this(speed, weight, bodyColor, typeAirplanePortholes)
|
||||||
|
{
|
||||||
|
_airplaneWidth = airplaneWidth;
|
||||||
|
_airplaneHeight = airplaneHeight;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Установка позиции
|
/// Установка позиции
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -112,7 +128,7 @@ namespace AirplaneWithRadar
|
|||||||
/// Отрисовка самолёта
|
/// Отрисовка самолёта
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="g"></param>
|
/// <param name="g"></param>
|
||||||
public void DrawTransport(Graphics g)
|
public virtual void DrawTransport(Graphics g)
|
||||||
{
|
{
|
||||||
if (_startPosX < 0 || _startPosY < 0
|
if (_startPosX < 0 || _startPosY < 0
|
||||||
|| !_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
|| !_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
||||||
|
@ -0,0 +1,48 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
|
||||||
|
|
||||||
|
namespace AirplaneWithRadar
|
||||||
|
{
|
||||||
|
internal class DrawningAirplaneWithRadar : DrawningAirplane
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Инициализация свойств
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="speed">Скорость</param>
|
||||||
|
/// <param name="weight">Вес автомобиля</param>
|
||||||
|
/// <param name="bodyColor">Цвет кузова</param>
|
||||||
|
/// <param name="dopColor">Дополнительный цвет</param>
|
||||||
|
/// <param name="radar">Признак наличия радара</param>
|
||||||
|
/// <param name="fuelTanks">Признак наличия дополнительных топливных баков</param>
|
||||||
|
public DrawningAirplaneWithRadar(int speed, float weight, Color bodyColor, Color dopColor, bool radar, bool fuelTanks, IAirplanePortholes typeAirplanePortholes) :
|
||||||
|
base(speed, weight, bodyColor, 100, 20, typeAirplanePortholes)
|
||||||
|
{
|
||||||
|
Airplane = new EntityAirplaneWithRadar(speed, weight, bodyColor, dopColor, radar, fuelTanks);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void DrawTransport(Graphics g)
|
||||||
|
{
|
||||||
|
if (Airplane is not EntityAirplaneWithRadar airplaneWithRadar)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Pen pen = new(Color.Black);
|
||||||
|
Brush dopBrush = new SolidBrush(airplaneWithRadar.DopColor);
|
||||||
|
if (airplaneWithRadar.Radar)
|
||||||
|
{
|
||||||
|
g.FillEllipse(dopBrush, _startPosX + 30, _startPosY, 20, 5);
|
||||||
|
g.DrawLine(pen, _startPosX + 33, _startPosY + 4, _startPosX + 33, _startPosY + 7);
|
||||||
|
g.DrawLine(pen, _startPosX + 47, _startPosY + 4, _startPosX + 47, _startPosY + 7);
|
||||||
|
}
|
||||||
|
base.DrawTransport(g);
|
||||||
|
if (airplaneWithRadar.FuelTanks)
|
||||||
|
{
|
||||||
|
g.FillEllipse(dopBrush, _startPosX + 25, _startPosY + 15, 30, 5);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AirplaneWithRadar
|
||||||
|
{
|
||||||
|
internal class EntityAirplaneWithRadar : EntityAirplane
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Дополнительный цвет
|
||||||
|
/// </summary>
|
||||||
|
public Color DopColor { get; private set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Признак наличия радара
|
||||||
|
/// </summary>
|
||||||
|
public bool Radar { get; private set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Признак наличия дополнительного топливного бака
|
||||||
|
/// </summary>
|
||||||
|
public bool FuelTanks { get; private set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Инициализация свойств
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="speed">Скорость</param>
|
||||||
|
/// <param name="weight">Вес самолёта</param>
|
||||||
|
/// <param name="bodyColor">Цвет кузова</param>
|
||||||
|
/// <param name="dopColor">Дополнительный цвет</param>
|
||||||
|
/// <param name="radar">Признак наличия радара</param>
|
||||||
|
/// <param name="fuelTanks">Признак наличия дополнительных топливных баков</param>
|
||||||
|
public EntityAirplaneWithRadar(int speed, float weight, Color bodyColor, Color
|
||||||
|
dopColor, bool radar, bool fuelTanks) :
|
||||||
|
base(speed, weight, bodyColor)
|
||||||
|
{
|
||||||
|
DopColor = dopColor;
|
||||||
|
Radar = radar;
|
||||||
|
FuelTanks = fuelTanks;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -41,6 +41,7 @@
|
|||||||
this.labelPortholes = new System.Windows.Forms.Label();
|
this.labelPortholes = new System.Windows.Forms.Label();
|
||||||
this.comboBoxPortholes = new System.Windows.Forms.ComboBox();
|
this.comboBoxPortholes = new System.Windows.Forms.ComboBox();
|
||||||
this.comboBoxTypePortholes = new System.Windows.Forms.ComboBox();
|
this.comboBoxTypePortholes = new System.Windows.Forms.ComboBox();
|
||||||
|
this.buttonCreateModif = new System.Windows.Forms.Button();
|
||||||
this.statusStrip1.SuspendLayout();
|
this.statusStrip1.SuspendLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxAirplane)).BeginInit();
|
((System.ComponentModel.ISupportInitialize)(this.pictureBoxAirplane)).BeginInit();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
@ -180,11 +181,22 @@
|
|||||||
this.comboBoxTypePortholes.TabIndex = 9;
|
this.comboBoxTypePortholes.TabIndex = 9;
|
||||||
this.comboBoxTypePortholes.Text = "Квадратные";
|
this.comboBoxTypePortholes.Text = "Квадратные";
|
||||||
//
|
//
|
||||||
|
// buttonCreateModif
|
||||||
|
//
|
||||||
|
this.buttonCreateModif.Location = new System.Drawing.Point(93, 395);
|
||||||
|
this.buttonCreateModif.Name = "buttonCreateModif";
|
||||||
|
this.buttonCreateModif.Size = new System.Drawing.Size(115, 23);
|
||||||
|
this.buttonCreateModif.TabIndex = 10;
|
||||||
|
this.buttonCreateModif.Text = "Модификация";
|
||||||
|
this.buttonCreateModif.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_Click);
|
||||||
|
//
|
||||||
// FormAirplane
|
// FormAirplane
|
||||||
//
|
//
|
||||||
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.buttonCreateModif);
|
||||||
this.Controls.Add(this.comboBoxTypePortholes);
|
this.Controls.Add(this.comboBoxTypePortholes);
|
||||||
this.Controls.Add(this.comboBoxPortholes);
|
this.Controls.Add(this.comboBoxPortholes);
|
||||||
this.Controls.Add(this.labelPortholes);
|
this.Controls.Add(this.labelPortholes);
|
||||||
@ -220,5 +232,6 @@
|
|||||||
private Label labelPortholes;
|
private Label labelPortholes;
|
||||||
private ComboBox comboBoxPortholes;
|
private ComboBox comboBoxPortholes;
|
||||||
private ComboBox comboBoxTypePortholes;
|
private ComboBox comboBoxTypePortholes;
|
||||||
|
private Button buttonCreateModif;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -20,6 +20,18 @@ namespace AirplaneWithRadar
|
|||||||
_airplane?.DrawTransport(gr);
|
_airplane?.DrawTransport(gr);
|
||||||
pictureBoxAirplane.Image = bmp;
|
pictureBoxAirplane.Image = bmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Ìåòîä óñòàíîâêè äàííûõ
|
||||||
|
/// </summary>
|
||||||
|
private void SetData()
|
||||||
|
{
|
||||||
|
Random rnd = new();
|
||||||
|
_airplane.SetPosition(rnd.Next(20, 100), rnd.Next(20, 100), pictureBoxAirplane.Width, pictureBoxAirplane.Height);
|
||||||
|
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_airplane.Airplane.Speed}";
|
||||||
|
toolStripStatusLabelWeight.Text = $"Âåñ: {_airplane.Airplane.Weight}";
|
||||||
|
toolStripStatusLabelBodyColor.Text = $"Öâåò: {_airplane.Airplane.BodyColor.Name}";
|
||||||
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Обработка нажатия кнопки "Создать"
|
/// Обработка нажатия кнопки "Создать"
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -86,5 +98,28 @@ namespace AirplaneWithRadar
|
|||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ButtonCreateModif_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 DrawningAirplaneWithRadar(rnd.Next(100, 300), rnd.Next(1000, 2000),
|
||||||
|
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
|
||||||
|
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
|
||||||
|
Convert.ToBoolean(rnd.Next(0, 2)),
|
||||||
|
Convert.ToBoolean(rnd.Next(0, 2)),
|
||||||
|
typeAirplanePortholes);
|
||||||
|
_airplane.DrawningPortholes.CountPortholes = Convert.ToInt32(comboBoxPortholes.Text);
|
||||||
|
SetData();
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user