Добавление родителей и ввод конструкторов
This commit is contained in:
parent
d221bfd6e4
commit
a56656054b
@ -1,5 +1,4 @@
|
||||
|
||||
namespace ProjectAirplaneWithRadar
|
||||
namespace ProjectAirplaneWithRadar.Drawnings
|
||||
{
|
||||
/// <summary>
|
||||
/// Направление перемещения
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -1,14 +1,16 @@
|
||||
namespace ProjectAirplaneWithRadar
|
||||
using System;
|
||||
using ProjectAirplaneWithRadar.Entities;
|
||||
|
||||
|
||||
namespace ProjectAirplaneWithRadar.Drawnings
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||
/// </summary>
|
||||
public class DrawingAirplaneWithRadar
|
||||
public class DrawningAirplane
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntityAirplaneWithRadar? EntityAirplaneWithRadar { get; private set; }
|
||||
public EntityAirplane? EntityAirplane { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// Ширина окна
|
||||
@ -23,12 +25,12 @@
|
||||
/// <summary>
|
||||
/// Левая координата прорисовки
|
||||
/// </summary>
|
||||
private int? _startPosX;
|
||||
protected int? _startPosX;
|
||||
|
||||
/// <summary>
|
||||
/// Верхняя кооридната прорисовки
|
||||
/// </summary>
|
||||
private int? _startPosY;
|
||||
protected int? _startPosY;
|
||||
|
||||
/// <summary>
|
||||
/// Ширина прорисовки самолета
|
||||
@ -38,28 +40,41 @@
|
||||
/// <summary>
|
||||
/// Высота прорисовки самолета
|
||||
/// </summary>
|
||||
public readonly int PlaneHeight = 95;
|
||||
|
||||
public readonly int PlaneHeight = 85;
|
||||
|
||||
/// <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 void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool wheels, bool rocket)
|
||||
private DrawningAirplane()
|
||||
{
|
||||
EntityAirplaneWithRadar = new EntityAirplaneWithRadar();
|
||||
EntityAirplaneWithRadar.Init(speed, weight, bodyColor, additionalColor, wheels, rocket);
|
||||
_pictureWidth = null;
|
||||
_pictureHeight = null;
|
||||
_startPosX = 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>
|
||||
@ -72,18 +87,18 @@
|
||||
{
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
if(_startPosX != null && _startPosY != null)
|
||||
if (_startPosX != null && _startPosY != null)
|
||||
{
|
||||
if(_startPosX.Value < 0)
|
||||
if (_startPosX.Value < 0)
|
||||
{
|
||||
_startPosX = 0;
|
||||
}
|
||||
if(_startPosY.Value < 0)
|
||||
if (_startPosY.Value < 0)
|
||||
{
|
||||
_startPosY = 0;
|
||||
}
|
||||
|
||||
if(_startPosX.Value + PlaneWidth > _pictureWidth)
|
||||
if (_startPosX.Value + PlaneWidth > _pictureWidth)
|
||||
{
|
||||
_startPosX = _pictureWidth - PlaneWidth;
|
||||
}
|
||||
@ -116,7 +131,7 @@
|
||||
{
|
||||
_startPosX = 0;
|
||||
}
|
||||
if(_startPosY.Value < 0)
|
||||
if (_startPosY.Value < 0)
|
||||
{
|
||||
_startPosY = 0;
|
||||
}
|
||||
@ -138,12 +153,12 @@
|
||||
/// <returns>true - перемещене выполнено, false - перемещение невозможно</returns>
|
||||
public bool MoveTransport(DirectionType direction)
|
||||
{
|
||||
if (EntityAirplaneWithRadar == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
if (EntityAirplane == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int step = (int)EntityAirplaneWithRadar.Step;
|
||||
int step = (int)EntityAirplane.Step;
|
||||
switch (direction)
|
||||
{
|
||||
//влево
|
||||
@ -162,7 +177,7 @@
|
||||
break;
|
||||
// вправо
|
||||
case DirectionType.Right:
|
||||
if (_startPosX.Value + step < _pictureWidth - PlaneWidth)
|
||||
if (_startPosX.Value + step < _pictureWidth - PlaneWidth)
|
||||
{
|
||||
_startPosX += step;
|
||||
}
|
||||
@ -184,54 +199,19 @@
|
||||
/// Прорисовка объекта
|
||||
/// </summary>
|
||||
/// <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;
|
||||
}
|
||||
|
||||
|
||||
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 = {
|
||||
new Point(_startPosX.Value + 10, _startPosY.Value + 10),
|
||||
@ -266,3 +246,4 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,25 +1,10 @@
|
||||
namespace ProjectAirplaneWithRadar
|
||||
namespace ProjectAirplaneWithRadar.Entities
|
||||
{
|
||||
/// <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>
|
||||
@ -33,7 +18,7 @@
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия ракеты
|
||||
/// </summary>
|
||||
public bool Rocket { get; private set; }
|
||||
public bool Rocket { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Шаг перемещения автомобиля
|
||||
@ -49,14 +34,11 @@
|
||||
/// <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)
|
||||
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;
|
||||
Wheels = wheels;
|
||||
Rocket = rocket;
|
||||
Rocket = rocket;
|
||||
}
|
||||
}
|
||||
}
|
@ -34,6 +34,7 @@
|
||||
buttonRight = new Button();
|
||||
buttonDown = new Button();
|
||||
buttonUp = new Button();
|
||||
ButtonCreateAirplane = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxAirplaneWithRadar).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
@ -41,21 +42,19 @@
|
||||
//
|
||||
pictureBoxAirplaneWithRadar.Dock = DockStyle.Fill;
|
||||
pictureBoxAirplaneWithRadar.Location = new Point(0, 0);
|
||||
pictureBoxAirplaneWithRadar.Margin = new Padding(3, 4, 3, 4);
|
||||
pictureBoxAirplaneWithRadar.Name = "pictureBoxAirplaneWithRadar";
|
||||
pictureBoxAirplaneWithRadar.Size = new Size(1128, 636);
|
||||
pictureBoxAirplaneWithRadar.Size = new Size(987, 477);
|
||||
pictureBoxAirplaneWithRadar.TabIndex = 0;
|
||||
pictureBoxAirplaneWithRadar.TabStop = false;
|
||||
//
|
||||
// buttonCreate
|
||||
//
|
||||
buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreate.Location = new Point(14, 589);
|
||||
buttonCreate.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonCreate.Location = new Point(12, 442);
|
||||
buttonCreate.Name = "buttonCreate";
|
||||
buttonCreate.Size = new Size(86, 31);
|
||||
buttonCreate.Size = new Size(225, 23);
|
||||
buttonCreate.TabIndex = 1;
|
||||
buttonCreate.Text = "Создать";
|
||||
buttonCreate.Text = "Создать Самолет с радаром";
|
||||
buttonCreate.UseVisualStyleBackColor = true;
|
||||
buttonCreate.Click += ButtonCreate_Click;
|
||||
//
|
||||
@ -64,10 +63,9 @@
|
||||
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonLeft.BackgroundImage = Properties.Resources.Стрелка_влево;
|
||||
buttonLeft.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonLeft.Location = new Point(981, 573);
|
||||
buttonLeft.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonLeft.Location = new Point(858, 430);
|
||||
buttonLeft.Name = "buttonLeft";
|
||||
buttonLeft.Size = new Size(40, 47);
|
||||
buttonLeft.Size = new Size(35, 35);
|
||||
buttonLeft.TabIndex = 2;
|
||||
buttonLeft.UseVisualStyleBackColor = true;
|
||||
buttonLeft.Click += ButtonMove_Click;
|
||||
@ -77,10 +75,9 @@
|
||||
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonRight.BackgroundImage = Properties.Resources.Стрелка_вправо;
|
||||
buttonRight.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonRight.Location = new Point(1074, 573);
|
||||
buttonRight.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonRight.Location = new Point(940, 430);
|
||||
buttonRight.Name = "buttonRight";
|
||||
buttonRight.Size = new Size(40, 47);
|
||||
buttonRight.Size = new Size(35, 35);
|
||||
buttonRight.TabIndex = 3;
|
||||
buttonRight.UseVisualStyleBackColor = true;
|
||||
buttonRight.Click += ButtonMove_Click;
|
||||
@ -90,10 +87,9 @@
|
||||
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonDown.BackgroundImage = Properties.Resources.Стрелка_вниз;
|
||||
buttonDown.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonDown.Location = new Point(1027, 573);
|
||||
buttonDown.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonDown.Location = new Point(899, 430);
|
||||
buttonDown.Name = "buttonDown";
|
||||
buttonDown.Size = new Size(40, 47);
|
||||
buttonDown.Size = new Size(35, 35);
|
||||
buttonDown.TabIndex = 4;
|
||||
buttonDown.UseVisualStyleBackColor = true;
|
||||
buttonDown.Click += ButtonMove_Click;
|
||||
@ -103,26 +99,36 @@
|
||||
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonUp.BackgroundImage = Properties.Resources.Стрелка_вверх;
|
||||
buttonUp.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonUp.Location = new Point(1027, 519);
|
||||
buttonUp.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonUp.Location = new Point(899, 389);
|
||||
buttonUp.Name = "buttonUp";
|
||||
buttonUp.Size = new Size(40, 47);
|
||||
buttonUp.Size = new Size(35, 35);
|
||||
buttonUp.TabIndex = 5;
|
||||
buttonUp.UseVisualStyleBackColor = true;
|
||||
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
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(1128, 636);
|
||||
ClientSize = new Size(987, 477);
|
||||
Controls.Add(ButtonCreateAirplane);
|
||||
Controls.Add(buttonUp);
|
||||
Controls.Add(buttonDown);
|
||||
Controls.Add(buttonRight);
|
||||
Controls.Add(buttonLeft);
|
||||
Controls.Add(buttonCreate);
|
||||
Controls.Add(pictureBoxAirplaneWithRadar);
|
||||
Margin = new Padding(3, 4, 3, 4);
|
||||
Name = "FormAirplaneWithRadar";
|
||||
Text = "Самолет с радаром";
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxAirplaneWithRadar).EndInit();
|
||||
@ -137,5 +143,6 @@
|
||||
private Button buttonRight;
|
||||
private Button buttonDown;
|
||||
private Button buttonUp;
|
||||
private Button ButtonCreateAirplane;
|
||||
}
|
||||
}
|
@ -1,4 +1,6 @@
|
||||
namespace ProjectAirplaneWithRadar
|
||||
using ProjectAirplaneWithRadar.Drawnings;
|
||||
|
||||
namespace ProjectAirplaneWithRadar
|
||||
{
|
||||
/// <summary>
|
||||
/// Форма работы с объектом "Самолет с радаром"
|
||||
@ -8,7 +10,7 @@
|
||||
/// <summary>
|
||||
/// Поле-объект для происовки объект
|
||||
/// </summary>
|
||||
private DrawingAirplaneWithRadar? _drawingAirplaneWithRadar;
|
||||
private DrawningAirplane? _drawingAirplane;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор формы
|
||||
@ -19,38 +21,63 @@
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Обработка нажатия кнопки "Создать"
|
||||
/// Создание объекта класса-перемещения
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonCreate_Click(object sender, EventArgs e)
|
||||
/// <param name="type">Тип создаваемого объекта</param>
|
||||
private void CreateObject(string type)
|
||||
{
|
||||
Random random = new();
|
||||
_drawingAirplaneWithRadar = new DrawingAirplaneWithRadar();
|
||||
_drawingAirplaneWithRadar.Init(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)));
|
||||
_drawingAirplaneWithRadar.SetPictureSize(pictureBoxAirplaneWithRadar.Width, pictureBoxAirplaneWithRadar.Height);
|
||||
_drawingAirplaneWithRadar.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
switch (type)
|
||||
{
|
||||
case nameof(DrawningAirplane):
|
||||
_drawingAirplane = new DrawningAirplane(random.Next(100, 300), random.Next(1000, 3000),
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)));
|
||||
break;
|
||||
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();
|
||||
}
|
||||
|
||||
/// <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>
|
||||
private void UpdatePlane()
|
||||
{
|
||||
if (_drawingAirplaneWithRadar == null)
|
||||
if (_drawingAirplane == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Bitmap bmp = new(pictureBoxAirplaneWithRadar.Width, pictureBoxAirplaneWithRadar.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_drawingAirplaneWithRadar?.DrawTransport(gr);
|
||||
_drawingAirplane?.DrawTransport(gr);
|
||||
pictureBoxAirplaneWithRadar.Image = bmp;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Перемещение объекта по форме (нажатие кнопок навигации)
|
||||
@ -59,7 +86,7 @@
|
||||
/// <param name="e"></param>
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawingAirplaneWithRadar == null)
|
||||
if (_drawingAirplane == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -87,10 +114,10 @@
|
||||
return;
|
||||
|
||||
}
|
||||
_drawingAirplaneWithRadar.MoveTransport(result);
|
||||
_drawingAirplane.MoveTransport(result);
|
||||
|
||||
UpdatePlane();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user