Putilin P. A. LabWork 2 Advanced #3
@ -9,32 +9,32 @@ namespace AirplaneWithRadar
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntityAirplane Airplane { private set; get; }
|
||||
public EntityAirplane Airplane { protected set; get; }
|
||||
public IAirplanePortholes DrawningPortholes { get; private set; }
|
||||
/// <summary>
|
||||
/// Левая координата отрисовки самолёта
|
||||
/// </summary>
|
||||
private float _startPosX;
|
||||
protected float _startPosX;
|
||||
/// <summary>
|
||||
/// Верхняя кооридната отрисовки самолёта
|
||||
/// </summary>
|
||||
private float _startPosY;
|
||||
protected float _startPosY;
|
||||
/// <summary>
|
||||
/// Ширина окна отрисовки
|
||||
/// </summary>
|
||||
private int? _pictureWidth = null;
|
||||
protected int? _pictureWidth = null;
|
||||
/// <summary>
|
||||
/// Высота окна отрисовки
|
||||
/// </summary>
|
||||
private int? _pictureHeight = null;
|
||||
protected int? _pictureHeight = null;
|
||||
/// <summary>
|
||||
/// Ширина отрисовки
|
||||
/// </summary>
|
||||
private readonly int _airplaneWidth = 100;
|
||||
protected readonly int _airplaneWidth = 100;
|
||||
/// <summary>
|
||||
/// Высота отрисовки самолёта
|
||||
/// </summary>
|
||||
private readonly int _airplaneHeight = 20;
|
||||
protected readonly int _airplaneHeight = 20;
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
@ -46,6 +46,22 @@ namespace AirplaneWithRadar
|
||||
Airplane = new EntityAirplane(speed, weight, bodyColor);
|
||||
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>
|
||||
@ -112,7 +128,7 @@ namespace AirplaneWithRadar
|
||||
/// Отрисовка самолёта
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public void DrawTransport(Graphics g)
|
||||
public virtual void DrawTransport(Graphics g)
|
||||
{
|
||||
if (_startPosX < 0 || _startPosY < 0
|
||||
|| !_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.comboBoxPortholes = new System.Windows.Forms.ComboBox();
|
||||
this.comboBoxTypePortholes = new System.Windows.Forms.ComboBox();
|
||||
this.buttonCreateModif = new System.Windows.Forms.Button();
|
||||
this.statusStrip1.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxAirplane)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
@ -180,11 +181,22 @@
|
||||
this.comboBoxTypePortholes.TabIndex = 9;
|
||||
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
|
||||
//
|
||||
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.buttonCreateModif);
|
||||
this.Controls.Add(this.comboBoxTypePortholes);
|
||||
this.Controls.Add(this.comboBoxPortholes);
|
||||
this.Controls.Add(this.labelPortholes);
|
||||
@ -220,5 +232,6 @@
|
||||
private Label labelPortholes;
|
||||
private ComboBox comboBoxPortholes;
|
||||
private ComboBox comboBoxTypePortholes;
|
||||
private Button buttonCreateModif;
|
||||
}
|
||||
}
|
@ -20,6 +20,18 @@ namespace AirplaneWithRadar
|
||||
_airplane?.DrawTransport(gr);
|
||||
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>
|
||||
@ -86,5 +98,28 @@ namespace AirplaneWithRadar
|
||||
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…
Reference in New Issue
Block a user