Добавление родителей и ввод конструкторов

This commit is contained in:
Павел Ладягин 2024-03-01 19:55:24 +04:00
parent d221bfd6e4
commit a56656054b
7 changed files with 248 additions and 132 deletions

View File

@ -1,5 +1,4 @@
 namespace ProjectAirplaneWithRadar.Drawnings
namespace ProjectAirplaneWithRadar
{ {
/// <summary> /// <summary>
/// Направление перемещения /// Направление перемещения

View File

@ -0,0 +1,75 @@
using ProjectAirplaneWithRadar.Entities;
namespace ProjectAirplaneWithRadar.Drawnings
{
/// <summary>
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
/// </summary>
public class DrawingAirplaneWithRadar : DrawningAirplane
{
/// <summary>
/// Инициализация свойств
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес</param>
/// <param name="bodyColor">Основной цвет</param>
/// <param name="additionalColor">Дополнительный цвет</param>
/// <param name="wheels">Шасси</param>
/// <param name="rocket">Ракета</param>
public DrawingAirplaneWithRadar(int speed, double weight, Color bodyColor, Color additionalColor, bool wheels, bool rocket) : base(150, 85)
{
EntityAirplane = new EntityAirplaneWithRadar(speed, weight, bodyColor, additionalColor, wheels, rocket);
}
public override void DrawTransport(Graphics g)
{
if (EntityAirplane == null || EntityAirplane is not EntityAirplaneWithRadar airplaneWithRadar || !_startPosX.HasValue || !_startPosY.HasValue)
{
return;
}
Pen pen = new(Color.Black);
Brush additionalBrush = new SolidBrush(airplaneWithRadar.AdditionalColor);
if (airplaneWithRadar.Wheels)
{
//Задняя стойка
g.DrawRectangle(pen, _startPosX.Value + 30, _startPosY.Value + 80, 5, 10);
g.FillRectangle(additionalBrush, _startPosX.Value + 30, _startPosY.Value + 80, 5, 10);
g.DrawEllipse(pen, _startPosX.Value + 20, _startPosY.Value + 85, 10, 10);
g.FillEllipse(additionalBrush, _startPosX.Value + 20, _startPosY.Value + 85, 10, 10);
g.DrawEllipse(pen, _startPosX.Value + 35, _startPosY.Value + 85, 10, 10);
g.FillEllipse(additionalBrush, _startPosX.Value + 35, _startPosY.Value + 85, 10, 10);
//Передняя стойка
g.DrawRectangle(pen, _startPosX.Value + 95, _startPosY.Value + 80, 5, 10);
g.FillRectangle(additionalBrush, _startPosX.Value + 95, _startPosY.Value + 80, 5, 10);
g.DrawEllipse(pen, _startPosX.Value + 92, _startPosY.Value + 85, 10, 10);
g.FillEllipse(additionalBrush, _startPosX.Value + 92, _startPosY.Value + 85, 10, 10);
}
//_startPosY += 10;
base.DrawTransport(g);
//_startPosY -= 10;
//Ракета воздух-воздух
if (airplaneWithRadar.Rocket)
{
g.DrawRectangle(pen, _startPosX.Value + 50, _startPosY.Value + 70, 2, 5);
g.FillRectangle(additionalBrush, _startPosX.Value + 50, _startPosY.Value + 70, 2, 5);
g.DrawRectangle(pen, _startPosX.Value + 80, _startPosY.Value + 70, 2, 5);
g.FillRectangle(additionalBrush, _startPosX.Value + 80, _startPosY.Value + 70, 2, 5);
g.DrawRectangle(pen, _startPosX.Value + 40, _startPosY.Value + 75, 50, 5);
g.FillRectangle(additionalBrush, _startPosX.Value + 40, _startPosY.Value + 75, 50, 5);
}
}
}
}

View File

@ -1,14 +1,16 @@
namespace ProjectAirplaneWithRadar using System;
using ProjectAirplaneWithRadar.Entities;
namespace ProjectAirplaneWithRadar.Drawnings
{ {
/// <summary> public class DrawningAirplane
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
/// </summary>
public class DrawingAirplaneWithRadar
{ {
/// <summary> /// <summary>
/// Класс-сущность /// Класс-сущность
/// </summary> /// </summary>
public EntityAirplaneWithRadar? EntityAirplaneWithRadar { get; private set; } public EntityAirplane? EntityAirplane { get; protected set; }
/// <summary> /// <summary>
/// Ширина окна /// Ширина окна
@ -23,12 +25,12 @@
/// <summary> /// <summary>
/// Левая координата прорисовки /// Левая координата прорисовки
/// </summary> /// </summary>
private int? _startPosX; protected int? _startPosX;
/// <summary> /// <summary>
/// Верхняя кооридната прорисовки /// Верхняя кооридната прорисовки
/// </summary> /// </summary>
private int? _startPosY; protected int? _startPosY;
/// <summary> /// <summary>
/// Ширина прорисовки самолета /// Ширина прорисовки самолета
@ -38,28 +40,41 @@
/// <summary> /// <summary>
/// Высота прорисовки самолета /// Высота прорисовки самолета
/// </summary> /// </summary>
public readonly int PlaneHeight = 95; public readonly int PlaneHeight = 85;
/// <summary> /// <summary>
/// Инициализация свойств /// Пустой конструктор
/// </summary> /// </summary>
/// <param name="speed">Скорость</param> private DrawningAirplane()
/// <param name="weight">Вес</param>
/// <param name="bodyColor">Основной цвет</param>
/// <param name="additionalColor">Дополнительный цвет</param>
/// <param name="wheels">Шасси</param>
/// <param name="rocket">Ракета</param>
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool wheels, bool rocket)
{ {
EntityAirplaneWithRadar = new EntityAirplaneWithRadar();
EntityAirplaneWithRadar.Init(speed, weight, bodyColor, additionalColor, wheels, rocket);
_pictureWidth = null; _pictureWidth = null;
_pictureHeight = null; _pictureHeight = null;
_startPosX = null; _startPosX = null;
_startPosY = null; _startPosY = null;
} }
/// <summary>
/// Конструктор
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес</param>
/// <param name="bodyColor">Основной цвет</param>
public DrawningAirplane(int speed, double weight, Color bodyColor) : this()
{
EntityAirplane = new EntityAirplane(speed, weight, bodyColor);
}
/// <summary>
/// Конструктор для наследников
/// </summary>
/// <param name="planeWidth">Ширина прорисовки самолета</param>
/// <param name="planeHeight">Высота прорисовки самолета</param>
protected DrawningAirplane(int planeWidth, int planeHeight) : this()
{
PlaneWidth = planeWidth;
PlaneHeight = planeHeight;
}
/// <summary> /// <summary>
/// Установка границ поля /// Установка границ поля
/// </summary> /// </summary>
@ -72,18 +87,18 @@
{ {
_pictureWidth = width; _pictureWidth = width;
_pictureHeight = height; _pictureHeight = height;
if(_startPosX != null && _startPosY != null) if (_startPosX != null && _startPosY != null)
{ {
if(_startPosX.Value < 0) if (_startPosX.Value < 0)
{ {
_startPosX = 0; _startPosX = 0;
} }
if(_startPosY.Value < 0) if (_startPosY.Value < 0)
{ {
_startPosY = 0; _startPosY = 0;
} }
if(_startPosX.Value + PlaneWidth > _pictureWidth) if (_startPosX.Value + PlaneWidth > _pictureWidth)
{ {
_startPosX = _pictureWidth - PlaneWidth; _startPosX = _pictureWidth - PlaneWidth;
} }
@ -116,7 +131,7 @@
{ {
_startPosX = 0; _startPosX = 0;
} }
if(_startPosY.Value < 0) if (_startPosY.Value < 0)
{ {
_startPosY = 0; _startPosY = 0;
} }
@ -138,12 +153,12 @@
/// <returns>true - перемещене выполнено, false - перемещение невозможно</returns> /// <returns>true - перемещене выполнено, false - перемещение невозможно</returns>
public bool MoveTransport(DirectionType direction) public bool MoveTransport(DirectionType direction)
{ {
if (EntityAirplaneWithRadar == null || !_startPosX.HasValue || !_startPosY.HasValue) if (EntityAirplane == null || !_startPosX.HasValue || !_startPosY.HasValue)
{ {
return false; return false;
} }
int step = (int)EntityAirplaneWithRadar.Step; int step = (int)EntityAirplane.Step;
switch (direction) switch (direction)
{ {
//влево //влево
@ -184,53 +199,18 @@
/// Прорисовка объекта /// Прорисовка объекта
/// </summary> /// </summary>
/// <param name="g"></param> /// <param name="g"></param>
public void DrawTransport(Graphics g) public virtual void DrawTransport(Graphics g)
{ {
if (EntityAirplaneWithRadar == null || !_startPosX.HasValue || !_startPosY.HasValue) if (EntityAirplane == null || !_startPosX.HasValue || !_startPosY.HasValue)
{ {
return; return;
} }
Pen pen = new(Color.Black); Pen pen = new(Color.Black);
Brush additionalBrush = new SolidBrush(EntityAirplaneWithRadar.AdditionalColor);
//Шасси
if (EntityAirplaneWithRadar.Wheels)
{
//Задняя стойка
g.DrawRectangle(pen, _startPosX.Value + 30, _startPosY.Value + 80, 5, 10);
g.FillRectangle(additionalBrush, _startPosX.Value + 30, _startPosY.Value + 80, 5, 10);
g.DrawEllipse(pen, _startPosX.Value + 20, _startPosY.Value + 85, 10, 10);
g.FillEllipse(additionalBrush, _startPosX.Value + 20, _startPosY.Value + 85, 10, 10);
g.DrawEllipse(pen, _startPosX.Value + 35, _startPosY.Value + 85, 10, 10);
g.FillEllipse(additionalBrush, _startPosX.Value + 35, _startPosY.Value + 85, 10, 10);
//Передняя стойка
g.DrawRectangle(pen, _startPosX.Value + 95, _startPosY.Value + 80, 5, 10);
g.FillRectangle(additionalBrush, _startPosX.Value + 95, _startPosY.Value + 80, 5, 10);
g.DrawEllipse(pen, _startPosX.Value + 92, _startPosY.Value + 85, 10, 10);
g.FillEllipse(additionalBrush, _startPosX.Value + 92, _startPosY.Value + 85, 10, 10);
}
//Ракета воздух-воздух
if (EntityAirplaneWithRadar.Rocket)
{
g.DrawRectangle(pen, _startPosX.Value + 50, _startPosY.Value + 70, 2, 5);
g.FillRectangle(additionalBrush, _startPosX.Value + 50, _startPosY.Value + 70, 2, 5);
g.DrawRectangle(pen, _startPosX.Value + 80, _startPosY.Value + 70, 2, 5);
g.FillRectangle(additionalBrush, _startPosX.Value + 80, _startPosY.Value + 70, 2, 5);
g.DrawRectangle(pen, _startPosX.Value + 40, _startPosY.Value + 75, 50, 5);
g.FillRectangle(additionalBrush, _startPosX.Value + 40, _startPosY.Value + 75, 50, 5);
}
//Корпус //Корпус
g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 50,100,30); g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 50, 100, 30);
//Хвост //Хвост
Point[] points = { Point[] points = {
@ -266,3 +246,4 @@
} }
} }
} }

View File

@ -0,0 +1,45 @@
using System;
using System.Net.Sockets;
namespace ProjectAirplaneWithRadar.Entities
{
/// <summary>
/// Класс-сущность "Самолет"
/// </summary>
public class EntityAirplane
{
/// <summary>
/// Скорость
/// </summary>
public int Speed { get; private set; }
/// <summary>
/// Вес
/// </summary>
public double Weight { get; private set; }
/// <summary>
/// Основной цвет
/// </summary>
public Color BodyColor { get; private set; }
/// <summary>
/// Шаг перемещения автомобиля
/// </summary>
public double Step => Speed * 100 / Weight;
/// <summary>
/// Конструктор сущности
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес</param>
/// <param name="bodyColor">Основной цвет</param>
public EntityAirplane(int speed, double weight, Color bodyColor)
{
Speed = speed;
Weight = weight;
BodyColor = bodyColor;
}
}
}

View File

@ -1,25 +1,10 @@
namespace ProjectAirplaneWithRadar namespace ProjectAirplaneWithRadar.Entities
{ {
/// <summary> /// <summary>
/// Класс-сущность "Самолет с радаром" /// Класс-сущность "Самолет с радаром"
/// </summary> /// </summary>
public class EntityAirplaneWithRadar public class EntityAirplaneWithRadar : EntityAirplane
{ {
/// <summary>
/// Скорость
/// </summary>
public int Speed { get; private set; }
/// <summary>
/// Вес
/// </summary>
public double Weight { get; private set; }
/// <summary>
/// Основной цвет
/// </summary>
public Color BodyColor { get; private set; }
/// <summary> /// <summary>
/// Дополнительный цвет (для опциональных элементов) /// Дополнительный цвет (для опциональных элементов)
/// </summary> /// </summary>
@ -49,11 +34,8 @@
/// <param name="additionalColor">Дополнительный цвет</param> /// <param name="additionalColor">Дополнительный цвет</param>
/// <param name="wheels">Шасси</param> /// <param name="wheels">Шасси</param>
/// <param name="rocket">Ракета</param> /// <param name="rocket">Ракета</param>
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool wheels, bool rocket) public EntityAirplaneWithRadar(int speed, double weight, Color bodyColor, Color additionalColor, bool wheels, bool rocket) : base(speed, weight, bodyColor)
{ {
Speed = speed;
Weight = weight;
BodyColor = bodyColor;
AdditionalColor = additionalColor; AdditionalColor = additionalColor;
Wheels = wheels; Wheels = wheels;
Rocket = rocket; Rocket = rocket;

View File

@ -34,6 +34,7 @@
buttonRight = new Button(); buttonRight = new Button();
buttonDown = new Button(); buttonDown = new Button();
buttonUp = new Button(); buttonUp = new Button();
ButtonCreateAirplane = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxAirplaneWithRadar).BeginInit(); ((System.ComponentModel.ISupportInitialize)pictureBoxAirplaneWithRadar).BeginInit();
SuspendLayout(); SuspendLayout();
// //
@ -41,21 +42,19 @@
// //
pictureBoxAirplaneWithRadar.Dock = DockStyle.Fill; pictureBoxAirplaneWithRadar.Dock = DockStyle.Fill;
pictureBoxAirplaneWithRadar.Location = new Point(0, 0); pictureBoxAirplaneWithRadar.Location = new Point(0, 0);
pictureBoxAirplaneWithRadar.Margin = new Padding(3, 4, 3, 4);
pictureBoxAirplaneWithRadar.Name = "pictureBoxAirplaneWithRadar"; pictureBoxAirplaneWithRadar.Name = "pictureBoxAirplaneWithRadar";
pictureBoxAirplaneWithRadar.Size = new Size(1128, 636); pictureBoxAirplaneWithRadar.Size = new Size(987, 477);
pictureBoxAirplaneWithRadar.TabIndex = 0; pictureBoxAirplaneWithRadar.TabIndex = 0;
pictureBoxAirplaneWithRadar.TabStop = false; pictureBoxAirplaneWithRadar.TabStop = false;
// //
// buttonCreate // buttonCreate
// //
buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonCreate.Location = new Point(14, 589); buttonCreate.Location = new Point(12, 442);
buttonCreate.Margin = new Padding(3, 4, 3, 4);
buttonCreate.Name = "buttonCreate"; buttonCreate.Name = "buttonCreate";
buttonCreate.Size = new Size(86, 31); buttonCreate.Size = new Size(225, 23);
buttonCreate.TabIndex = 1; buttonCreate.TabIndex = 1;
buttonCreate.Text = "Создать"; buttonCreate.Text = "Создать Самолет с радаром";
buttonCreate.UseVisualStyleBackColor = true; buttonCreate.UseVisualStyleBackColor = true;
buttonCreate.Click += ButtonCreate_Click; buttonCreate.Click += ButtonCreate_Click;
// //
@ -64,10 +63,9 @@
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonLeft.BackgroundImage = Properties.Resources.Стрелка_влево; buttonLeft.BackgroundImage = Properties.Resources.Стрелка_влево;
buttonLeft.BackgroundImageLayout = ImageLayout.Stretch; buttonLeft.BackgroundImageLayout = ImageLayout.Stretch;
buttonLeft.Location = new Point(981, 573); buttonLeft.Location = new Point(858, 430);
buttonLeft.Margin = new Padding(3, 4, 3, 4);
buttonLeft.Name = "buttonLeft"; buttonLeft.Name = "buttonLeft";
buttonLeft.Size = new Size(40, 47); buttonLeft.Size = new Size(35, 35);
buttonLeft.TabIndex = 2; buttonLeft.TabIndex = 2;
buttonLeft.UseVisualStyleBackColor = true; buttonLeft.UseVisualStyleBackColor = true;
buttonLeft.Click += ButtonMove_Click; buttonLeft.Click += ButtonMove_Click;
@ -77,10 +75,9 @@
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonRight.BackgroundImage = Properties.Resources.Стрелка_вправо; buttonRight.BackgroundImage = Properties.Resources.Стрелка_вправо;
buttonRight.BackgroundImageLayout = ImageLayout.Stretch; buttonRight.BackgroundImageLayout = ImageLayout.Stretch;
buttonRight.Location = new Point(1074, 573); buttonRight.Location = new Point(940, 430);
buttonRight.Margin = new Padding(3, 4, 3, 4);
buttonRight.Name = "buttonRight"; buttonRight.Name = "buttonRight";
buttonRight.Size = new Size(40, 47); buttonRight.Size = new Size(35, 35);
buttonRight.TabIndex = 3; buttonRight.TabIndex = 3;
buttonRight.UseVisualStyleBackColor = true; buttonRight.UseVisualStyleBackColor = true;
buttonRight.Click += ButtonMove_Click; buttonRight.Click += ButtonMove_Click;
@ -90,10 +87,9 @@
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonDown.BackgroundImage = Properties.Resources.Стрелка_вниз; buttonDown.BackgroundImage = Properties.Resources.Стрелка_вниз;
buttonDown.BackgroundImageLayout = ImageLayout.Stretch; buttonDown.BackgroundImageLayout = ImageLayout.Stretch;
buttonDown.Location = new Point(1027, 573); buttonDown.Location = new Point(899, 430);
buttonDown.Margin = new Padding(3, 4, 3, 4);
buttonDown.Name = "buttonDown"; buttonDown.Name = "buttonDown";
buttonDown.Size = new Size(40, 47); buttonDown.Size = new Size(35, 35);
buttonDown.TabIndex = 4; buttonDown.TabIndex = 4;
buttonDown.UseVisualStyleBackColor = true; buttonDown.UseVisualStyleBackColor = true;
buttonDown.Click += ButtonMove_Click; buttonDown.Click += ButtonMove_Click;
@ -103,26 +99,36 @@
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonUp.BackgroundImage = Properties.Resources.Стрелка_вверх; buttonUp.BackgroundImage = Properties.Resources.Стрелка_вверх;
buttonUp.BackgroundImageLayout = ImageLayout.Stretch; buttonUp.BackgroundImageLayout = ImageLayout.Stretch;
buttonUp.Location = new Point(1027, 519); buttonUp.Location = new Point(899, 389);
buttonUp.Margin = new Padding(3, 4, 3, 4);
buttonUp.Name = "buttonUp"; buttonUp.Name = "buttonUp";
buttonUp.Size = new Size(40, 47); buttonUp.Size = new Size(35, 35);
buttonUp.TabIndex = 5; buttonUp.TabIndex = 5;
buttonUp.UseVisualStyleBackColor = true; buttonUp.UseVisualStyleBackColor = true;
buttonUp.Click += ButtonMove_Click; buttonUp.Click += ButtonMove_Click;
// //
// ButtonCreateAirplane
//
ButtonCreateAirplane.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
ButtonCreateAirplane.Location = new Point(268, 442);
ButtonCreateAirplane.Name = "ButtonCreateAirplane";
ButtonCreateAirplane.Size = new Size(225, 23);
ButtonCreateAirplane.TabIndex = 6;
ButtonCreateAirplane.Text = "Создать Самолет";
ButtonCreateAirplane.UseVisualStyleBackColor = true;
ButtonCreateAirplane.Click += ButtonCreateAirplane_Click;
//
// FormAirplaneWithRadar // FormAirplaneWithRadar
// //
AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1128, 636); ClientSize = new Size(987, 477);
Controls.Add(ButtonCreateAirplane);
Controls.Add(buttonUp); Controls.Add(buttonUp);
Controls.Add(buttonDown); Controls.Add(buttonDown);
Controls.Add(buttonRight); Controls.Add(buttonRight);
Controls.Add(buttonLeft); Controls.Add(buttonLeft);
Controls.Add(buttonCreate); Controls.Add(buttonCreate);
Controls.Add(pictureBoxAirplaneWithRadar); Controls.Add(pictureBoxAirplaneWithRadar);
Margin = new Padding(3, 4, 3, 4);
Name = "FormAirplaneWithRadar"; Name = "FormAirplaneWithRadar";
Text = "Самолет с радаром"; Text = "Самолет с радаром";
((System.ComponentModel.ISupportInitialize)pictureBoxAirplaneWithRadar).EndInit(); ((System.ComponentModel.ISupportInitialize)pictureBoxAirplaneWithRadar).EndInit();
@ -137,5 +143,6 @@
private Button buttonRight; private Button buttonRight;
private Button buttonDown; private Button buttonDown;
private Button buttonUp; private Button buttonUp;
private Button ButtonCreateAirplane;
} }
} }

View File

@ -1,4 +1,6 @@
namespace ProjectAirplaneWithRadar using ProjectAirplaneWithRadar.Drawnings;
namespace ProjectAirplaneWithRadar
{ {
/// <summary> /// <summary>
/// Форма работы с объектом "Самолет с радаром" /// Форма работы с объектом "Самолет с радаром"
@ -8,7 +10,7 @@
/// <summary> /// <summary>
/// Поле-объект для происовки объект /// Поле-объект для происовки объект
/// </summary> /// </summary>
private DrawingAirplaneWithRadar? _drawingAirplaneWithRadar; private DrawningAirplane? _drawingAirplane;
/// <summary> /// <summary>
/// Конструктор формы /// Конструктор формы
@ -19,36 +21,61 @@
} }
/// <summary> /// <summary>
/// Обработка нажатия кнопки "Создать" /// Создание объекта класса-перемещения
/// </summary> /// </summary>
/// <param name="sender"></param> /// <param name="type">Тип создаваемого объекта</param>
/// <param name="e"></param> private void CreateObject(string type)
private void ButtonCreate_Click(object sender, EventArgs e)
{ {
Random random = new(); Random random = new();
_drawingAirplaneWithRadar = new DrawingAirplaneWithRadar(); switch (type)
_drawingAirplaneWithRadar.Init(random.Next(100, 300), random.Next(1000, 3000), {
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), case nameof(DrawningAirplane):
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), _drawingAirplane = new DrawningAirplane(random.Next(100, 300), random.Next(1000, 3000),
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2))); Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)));
_drawingAirplaneWithRadar.SetPictureSize(pictureBoxAirplaneWithRadar.Width, pictureBoxAirplaneWithRadar.Height); break;
_drawingAirplaneWithRadar.SetPosition(random.Next(10, 100), random.Next(10, 100)); case nameof(DrawingAirplaneWithRadar):
_drawingAirplane = new DrawingAirplaneWithRadar(random.Next(100, 300), random.Next(1000, 3000),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
break;
default:
return;
}
_drawingAirplane.SetPictureSize(pictureBoxAirplaneWithRadar.Width, pictureBoxAirplaneWithRadar.Height);
_drawingAirplane.SetPosition(random.Next(10, 100), random.Next(10, 100));
UpdatePlane(); UpdatePlane();
} }
/// <summary>
/// Обработка нажатия кнопки "Создать Самолет с радаром"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonCreate_Click(object sender, EventArgs e) => CreateObject(nameof(DrawingAirplaneWithRadar));
/// <summary>
/// Обработка нажатия кнопки "Создать Самолет"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonCreateAirplane_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningAirplane));
/// <summary> /// <summary>
/// Метод прорисовки самолета /// Метод прорисовки самолета
/// </summary> /// </summary>
private void UpdatePlane() private void UpdatePlane()
{ {
if (_drawingAirplaneWithRadar == null) if (_drawingAirplane == null)
{ {
return; return;
} }
Bitmap bmp = new(pictureBoxAirplaneWithRadar.Width, pictureBoxAirplaneWithRadar.Height); Bitmap bmp = new(pictureBoxAirplaneWithRadar.Width, pictureBoxAirplaneWithRadar.Height);
Graphics gr = Graphics.FromImage(bmp); Graphics gr = Graphics.FromImage(bmp);
_drawingAirplaneWithRadar?.DrawTransport(gr); _drawingAirplane?.DrawTransport(gr);
pictureBoxAirplaneWithRadar.Image = bmp; pictureBoxAirplaneWithRadar.Image = bmp;
} }
@ -59,7 +86,7 @@
/// <param name="e"></param> /// <param name="e"></param>
private void ButtonMove_Click(object sender, EventArgs e) private void ButtonMove_Click(object sender, EventArgs e)
{ {
if (_drawingAirplaneWithRadar == null) if (_drawingAirplane == null)
{ {
return; return;
} }
@ -87,7 +114,7 @@
return; return;
} }
_drawingAirplaneWithRadar.MoveTransport(result); _drawingAirplane.MoveTransport(result);
UpdatePlane(); UpdatePlane();
} }