Добавление родителей и ввод конструкторов
This commit is contained in:
parent
05d58c9452
commit
493ffef69c
@ -1,5 +1,4 @@
|
||||
|
||||
namespace ProjectAirbus;
|
||||
namespace ProjectAirbus.Drawning;
|
||||
|
||||
/// <summary>
|
||||
/// Направление перемещения
|
69
ProjectAirbus/ProjectAirbus/Drawning/DrawningAirbus.cs
Normal file
69
ProjectAirbus/ProjectAirbus/Drawning/DrawningAirbus.cs
Normal file
@ -0,0 +1,69 @@
|
||||
using ProjectAirbus.Entities;
|
||||
|
||||
namespace ProjectAirbus.Drawning;
|
||||
|
||||
/// <summary>
|
||||
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||
/// </summary>
|
||||
public class DrawningAirbus : DrawningBus
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Ширина прорисовки аэробуса
|
||||
/// </summary>
|
||||
private readonly int _drawningAirbusWidth = 133;
|
||||
|
||||
/// <summary>
|
||||
/// Высота прорисовки аэробуса
|
||||
/// </summary>
|
||||
private readonly int _drawningAirbusHeight = 60;
|
||||
|
||||
/// <summary>
|
||||
/// Конструтор
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodycolor">Основной цвет</param>
|
||||
/// <param name="additionalcolor">Дополнительный цвет</param>
|
||||
/// <param name="compartment">Признак наличия дополнительного отсека для пассажиров</param>
|
||||
/// <param name="engine">Признак наличия дополнительных двигателей</param>
|
||||
public DrawningAirbus(int speed, double weight, Color bodycolor, Color additionalcolor, bool compartment, bool engine) : base(133, 60)
|
||||
{
|
||||
EntityBus = new EntityAirbus(speed, weight, bodycolor, additionalcolor, compartment, engine);
|
||||
}
|
||||
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityBus == null || EntityBus is not EntityAirbus airbus || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Pen pen = new(Color.Black);
|
||||
Brush additionalBrush = new SolidBrush(airbus.AdditionalColor);
|
||||
|
||||
base.DrawTransport(g);
|
||||
|
||||
if (airbus.Engine)
|
||||
{
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 30, _startPosY.Value + 33, 13, 5);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 45, _startPosY.Value + 33, 15, 5);
|
||||
}
|
||||
|
||||
Brush brBlue = new SolidBrush(Color.LightBlue);
|
||||
if (airbus.Compartment)
|
||||
{
|
||||
//g.FillEllipse(brBlue, _startPosX.Value + 37, _startPosY.Value + 13, 49, 15);
|
||||
|
||||
g.FillPolygon(brBlue, new Point[]
|
||||
{
|
||||
new Point(_startPosX.Value + 35, _startPosY.Value + 20), new Point(_startPosX.Value + 60, _startPosY.Value + 12),
|
||||
new Point(_startPosX.Value + 80, _startPosY.Value + 12), new Point(_startPosX.Value + 95, _startPosY.Value + 20)});
|
||||
|
||||
g.DrawLine(pen, _startPosX.Value + 35, _startPosY.Value + 20, _startPosX.Value + 60, _startPosY.Value + 12);
|
||||
g.DrawLine(pen, _startPosX.Value + 60, _startPosY.Value + 12, _startPosX.Value + 80, _startPosY.Value + 12);
|
||||
g.DrawLine(pen, _startPosX.Value + 80, _startPosY.Value + 12, _startPosX.Value + 95, _startPosY.Value + 20);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +1,18 @@
|
||||
|
||||
namespace ProjectAirbus;
|
||||
using ProjectAirbus.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
/// <summary>
|
||||
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||
/// </summary>
|
||||
public class DrawningAirbus
|
||||
namespace ProjectAirbus.Drawning;
|
||||
|
||||
public class DrawningBus
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntityAirbus? EntityAirbus { get; private set; }
|
||||
public EntityBus? EntityBus { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// Ширина окна
|
||||
@ -24,42 +27,82 @@ public class DrawningAirbus
|
||||
/// <summary>
|
||||
/// Левая координата прорисовки аэробуса
|
||||
/// </summary>
|
||||
private int? _startPosX;
|
||||
protected int? _startPosX;
|
||||
|
||||
/// <summary>
|
||||
/// Верхняя кооридната прорисовки аэробуса
|
||||
/// </summary>
|
||||
private int? _startPosY;
|
||||
protected int? _startPosY;
|
||||
|
||||
/// <summary>
|
||||
/// Ширина прорисовки аэробуса
|
||||
/// </summary>
|
||||
private readonly int _drawningAirbusWidth = 133;
|
||||
private readonly int _drawningBusWidth = 133;
|
||||
|
||||
/// <summary>
|
||||
/// Высота прорисовки аэробуса
|
||||
/// </summary>
|
||||
private readonly int _drawningAirbusHeight = 60;
|
||||
private readonly int _drawningBusHeight = 60;
|
||||
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// Координата X объекта
|
||||
/// </summary>
|
||||
public int? GetPosX => _startPosX;
|
||||
|
||||
/// <summary>
|
||||
/// Координата Y объекта
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodycolor">Основной цвет</param>
|
||||
/// <param name="additionalcolor">Дополнительный цвет</param>
|
||||
/// <param name="compartment">Признак наличия дополнительного отсека для пассажиров</param>
|
||||
/// <param name="engine">Признак наличия дополнительных двигателей</param>
|
||||
public void Init(int speed, double weight, Color bodycolor, Color additionalcolor, bool compartment, bool engine)
|
||||
public int? GetPosY => _startPosY;
|
||||
|
||||
/// <summary>
|
||||
/// Ширина объекта
|
||||
/// </summary>
|
||||
public int GetWidth => _drawningBusWidth;
|
||||
|
||||
/// <summary>
|
||||
/// Высота объекта
|
||||
/// </summary>
|
||||
public int GetHeight => _drawningBusHeight;
|
||||
|
||||
/// <summary>
|
||||
/// Пустой конструктор
|
||||
/// </summary>
|
||||
private DrawningBus()
|
||||
{
|
||||
EntityAirbus = new EntityAirbus();
|
||||
EntityAirbus.Init(speed, weight, bodycolor, additionalcolor, compartment, engine);
|
||||
_pictureWidth = null;
|
||||
_pictureHeight = null;
|
||||
_startPosX = null;
|
||||
_startPosY = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodycolor">Основной цвет</param>
|
||||
|
||||
public DrawningBus(int speed, double weight, Color bodycolor) : this()
|
||||
{
|
||||
EntityBus = new EntityBus(speed, weight, bodycolor);
|
||||
_pictureWidth = null;
|
||||
_pictureHeight = null;
|
||||
_startPosX = null;
|
||||
_startPosY = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор для наследников
|
||||
/// </summary>
|
||||
/// <param name="drawningBusWidth">Ширина прорисовки аэробуса</param>
|
||||
/// <param name="drawningBusHeight">Высота прорисовки аэробуса</param>
|
||||
|
||||
protected DrawningBus(int drawningAirbusWidth, int drawningAirbusHeight) : this()
|
||||
{
|
||||
_drawningBusWidth = drawningAirbusWidth;
|
||||
_drawningBusHeight = drawningAirbusHeight;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Установка границ поля
|
||||
/// </summary>
|
||||
@ -71,7 +114,7 @@ public class DrawningAirbus
|
||||
// TODO проверка, что объект "влезает" в размеры поля
|
||||
// если влезает, сохраняем границы и корректируем позицию объекта,если она была уже установлена
|
||||
|
||||
if (width >= _drawningAirbusWidth || height >= _drawningAirbusHeight)
|
||||
if (width >= _drawningBusWidth || height >= _drawningBusHeight)
|
||||
{
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
@ -102,17 +145,17 @@ public class DrawningAirbus
|
||||
{
|
||||
x = 0;
|
||||
}
|
||||
else if (x > _pictureWidth - _drawningAirbusWidth)
|
||||
else if (x > _pictureWidth - _drawningBusWidth)
|
||||
{
|
||||
x = _pictureWidth.Value - _drawningAirbusWidth;
|
||||
x = _pictureWidth.Value - _drawningBusWidth;
|
||||
}
|
||||
if (y < 0)
|
||||
{
|
||||
y = 0;
|
||||
}
|
||||
else if (y > _pictureHeight - _drawningAirbusHeight)
|
||||
else if (y > _pictureHeight - _drawningBusHeight)
|
||||
{
|
||||
y = _pictureHeight.Value - _drawningAirbusHeight;
|
||||
y = _pictureHeight.Value - _drawningBusHeight;
|
||||
}
|
||||
|
||||
_startPosX = x;
|
||||
@ -125,7 +168,7 @@ public class DrawningAirbus
|
||||
/// <returns></returns>
|
||||
public bool MoveTransport(DirectionType direction)
|
||||
{
|
||||
if (EntityAirbus == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
if (EntityBus == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -133,33 +176,33 @@ public class DrawningAirbus
|
||||
{
|
||||
// Влево
|
||||
case DirectionType.Left:
|
||||
if (_startPosX.Value - EntityAirbus.Step > 0)
|
||||
if (_startPosX.Value - EntityBus.Step > 0)
|
||||
{
|
||||
_startPosX -= (int)EntityAirbus.Step;
|
||||
_startPosX -= (int)EntityBus.Step;
|
||||
}
|
||||
return true;
|
||||
//Вверх
|
||||
case DirectionType.Up:
|
||||
if (_startPosY.Value - EntityAirbus.Step > 0)
|
||||
if (_startPosY.Value - EntityBus.Step > 0)
|
||||
{
|
||||
_startPosY -= (int)EntityAirbus.Step;
|
||||
_startPosY -= (int)EntityBus.Step;
|
||||
}
|
||||
return true;
|
||||
//Вправо
|
||||
case DirectionType.Right:
|
||||
{
|
||||
if (_startPosX.Value + _drawningAirbusWidth + EntityAirbus.Step < _pictureWidth)
|
||||
if (_startPosX.Value + _drawningBusWidth + EntityBus.Step < _pictureWidth)
|
||||
{
|
||||
_startPosX += (int)EntityAirbus.Step;
|
||||
_startPosX += (int)EntityBus.Step;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
//Вниз
|
||||
case DirectionType.Down:
|
||||
{
|
||||
if (_startPosY.Value + _drawningAirbusHeight + EntityAirbus.Step < _pictureHeight)
|
||||
if (_startPosY.Value + _drawningBusHeight + EntityBus.Step < _pictureHeight)
|
||||
{
|
||||
_startPosY += (int)EntityAirbus.Step;
|
||||
_startPosY += (int)EntityBus.Step;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
@ -171,23 +214,15 @@ public class DrawningAirbus
|
||||
/// Прорисовка объекта
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public void DrawTransport(Graphics g)
|
||||
public virtual void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityAirbus == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
if (EntityBus == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Pen pen = new(Color.Black);
|
||||
Brush bodyColorBrush = new SolidBrush(EntityAirbus.BodyColor);
|
||||
Brush additionalBrush = new SolidBrush(EntityAirbus.AdditionalColor);
|
||||
|
||||
//Дополнительный отсек
|
||||
Brush brBlue = new SolidBrush(Color.LightBlue);
|
||||
if (EntityAirbus.Compartment)
|
||||
{
|
||||
g.FillEllipse(brBlue, _startPosX.Value + 37, _startPosY.Value + 13, 49, 15);
|
||||
}
|
||||
Brush bodyColorBrush = new SolidBrush(EntityBus.BodyColor);
|
||||
|
||||
//корпус
|
||||
g.FillRectangle(bodyColorBrush, _startPosX.Value, _startPosY.Value + 20, 100, 20);
|
||||
@ -224,12 +259,5 @@ public class DrawningAirbus
|
||||
g.DrawLine(pen, _startPosX.Value + 90, _startPosY.Value + 40, _startPosX.Value + 90, _startPosY.Value + 45);
|
||||
g.FillEllipse(darkBrush, _startPosX.Value + 87, _startPosY.Value + 45, 6, 6);
|
||||
|
||||
// Двигатели
|
||||
if (EntityAirbus.Engine)
|
||||
{
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 30, _startPosY.Value + 33, 13, 5);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 45, _startPosY.Value + 33, 15, 5);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,26 +1,10 @@
|
||||
|
||||
namespace ProjectAirbus;
|
||||
namespace ProjectAirbus.Entities;
|
||||
|
||||
/// <summary>
|
||||
/// Класс-сущность "Аэробус"
|
||||
/// </summary>
|
||||
public class EntityAirbus
|
||||
public class EntityAirbus : EntityBus
|
||||
{
|
||||
/// <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>
|
||||
@ -50,11 +34,8 @@ public class EntityAirbus
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="compartment">Признак наличия дополнительного отсека для пассажиров</param>
|
||||
/// <param name="engine">Признак наличия дополнительных двигателей</param>
|
||||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool compartment, bool engine)
|
||||
public EntityAirbus(int speed, double weight, Color bodyColor, Color additionalColor, bool compartment, bool engine) : base (speed, weight, bodyColor)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
AdditionalColor = additionalColor;
|
||||
Compartment = compartment;
|
||||
Engine = engine;
|
46
ProjectAirbus/ProjectAirbus/Entities/EntityBus.cs
Normal file
46
ProjectAirbus/ProjectAirbus/Entities/EntityBus.cs
Normal file
@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectAirbus.Entities;
|
||||
|
||||
/// <summary>
|
||||
/// Класс-сущность "Аэробус2"
|
||||
/// </summary>
|
||||
public class EntityBus
|
||||
{
|
||||
/// <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>m>
|
||||
public EntityBus(int speed, double weight, Color bodyColor)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
}
|
||||
}
|
20
ProjectAirbus/ProjectAirbus/FormAirbus.Designer.cs
generated
20
ProjectAirbus/ProjectAirbus/FormAirbus.Designer.cs
generated
@ -34,6 +34,7 @@
|
||||
buttonRight = new Button();
|
||||
buttonUp = new Button();
|
||||
pictureBoxAirbus = new PictureBox();
|
||||
buttonCreateBus = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxAirbus).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
@ -42,9 +43,9 @@
|
||||
buttonCreateAirbus.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreateAirbus.Location = new Point(12, 498);
|
||||
buttonCreateAirbus.Name = "buttonCreateAirbus";
|
||||
buttonCreateAirbus.Size = new Size(75, 23);
|
||||
buttonCreateAirbus.Size = new Size(193, 23);
|
||||
buttonCreateAirbus.TabIndex = 1;
|
||||
buttonCreateAirbus.Text = "Создать";
|
||||
buttonCreateAirbus.Text = "Создать аэробус";
|
||||
buttonCreateAirbus.UseVisualStyleBackColor = true;
|
||||
buttonCreateAirbus.Click += ButtonCreateAirbus_Click;
|
||||
//
|
||||
@ -54,7 +55,7 @@
|
||||
ButtonLeft.BackgroundImage = Properties.Resources.free_icon_left_arrow_10696518;
|
||||
ButtonLeft.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
ButtonLeft.Location = new Point(927, 491);
|
||||
ButtonLeft.Name = "buttonLeft";
|
||||
ButtonLeft.Name = "ButtonLeft";
|
||||
ButtonLeft.Size = new Size(35, 35);
|
||||
ButtonLeft.TabIndex = 2;
|
||||
ButtonLeft.UseVisualStyleBackColor = true;
|
||||
@ -105,10 +106,22 @@
|
||||
pictureBoxAirbus.TabIndex = 6;
|
||||
pictureBoxAirbus.TabStop = false;
|
||||
//
|
||||
// buttonCreateBus
|
||||
//
|
||||
buttonCreateBus.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreateBus.Location = new Point(229, 498);
|
||||
buttonCreateBus.Name = "buttonCreateBus";
|
||||
buttonCreateBus.Size = new Size(193, 23);
|
||||
buttonCreateBus.TabIndex = 7;
|
||||
buttonCreateBus.Text = "Создать автобус";
|
||||
buttonCreateBus.UseVisualStyleBackColor = true;
|
||||
buttonCreateBus.Click += ButtonCreateBus_Click;
|
||||
//
|
||||
// FormAirbus
|
||||
//
|
||||
AutoScaleMode = AutoScaleMode.None;
|
||||
ClientSize = new Size(1059, 533);
|
||||
Controls.Add(buttonCreateBus);
|
||||
Controls.Add(buttonCreateAirbus);
|
||||
Controls.Add(buttonRight);
|
||||
Controls.Add(buttonDown);
|
||||
@ -128,5 +141,6 @@
|
||||
private Button buttonRight;
|
||||
private Button buttonUp;
|
||||
private PictureBox pictureBoxAirbus;
|
||||
private Button buttonCreateBus;
|
||||
}
|
||||
}
|
@ -1,4 +1,6 @@
|
||||
|
||||
using ProjectAirbus.Drawning;
|
||||
|
||||
namespace ProjectAirbus
|
||||
{
|
||||
/// <summary>
|
||||
@ -9,7 +11,7 @@ namespace ProjectAirbus
|
||||
/// <summary>
|
||||
/// Поле-объект для прорисовки объекта
|
||||
/// </summary>
|
||||
private DrawningAirbus? _drawningAirbus;
|
||||
private DrawningBus? _drawningBus;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор формы
|
||||
@ -24,7 +26,7 @@ namespace ProjectAirbus
|
||||
/// </summary>
|
||||
private void Draw()
|
||||
{
|
||||
if (_drawningAirbus == null)
|
||||
if (_drawningBus == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -32,28 +34,50 @@ namespace ProjectAirbus
|
||||
Bitmap bmp = new(pictureBoxAirbus.Width,
|
||||
pictureBoxAirbus.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_drawningAirbus.DrawTransport(gr);
|
||||
_drawningBus.DrawTransport(gr);
|
||||
pictureBoxAirbus.Image = bmp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Обработка нажатия кнопки "Создать"
|
||||
/// Создание объекта класса-перемещения
|
||||
/// </summary>
|
||||
/// <param name="type">Тип создаваемого объекта</param>
|
||||
private void CreateObject(string type)
|
||||
{
|
||||
Random random = new();
|
||||
switch (type)
|
||||
{
|
||||
case nameof(DrawningBus):
|
||||
_drawningBus = new DrawningBus(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(DrawningAirbus):
|
||||
_drawningBus = new DrawningAirbus(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;
|
||||
}
|
||||
_drawningBus.SetPictureSize(pictureBoxAirbus.Width, pictureBoxAirbus.Height);
|
||||
_drawningBus.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
Draw();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Обработка нажатия кнопки "Создать Аэробус"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonCreateAirbus_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
_drawningAirbus = new DrawningAirbus();
|
||||
_drawningAirbus.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)));
|
||||
_drawningAirbus.SetPictureSize(pictureBoxAirbus.Width, pictureBoxAirbus.Height);
|
||||
_drawningAirbus.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
private void ButtonCreateAirbus_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningAirbus));
|
||||
|
||||
Draw();
|
||||
}
|
||||
/// <summary>
|
||||
/// Обработка нажатия кнопки "Создать автобус"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonCreateBus_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningBus));
|
||||
|
||||
/// <summary>
|
||||
/// Перемещение объекта по форме (нажатие кнопок навигации)
|
||||
@ -62,7 +86,7 @@ namespace ProjectAirbus
|
||||
/// <param name="e"></param>
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawningAirbus == null)
|
||||
if (_drawningBus == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -72,19 +96,19 @@ namespace ProjectAirbus
|
||||
{
|
||||
case "buttonUp":
|
||||
result =
|
||||
_drawningAirbus.MoveTransport(DirectionType.Up);
|
||||
_drawningBus.MoveTransport(DirectionType.Up);
|
||||
break;
|
||||
case "buttonDown":
|
||||
result =
|
||||
_drawningAirbus.MoveTransport(DirectionType.Down);
|
||||
_drawningBus.MoveTransport(DirectionType.Down);
|
||||
break;
|
||||
case "buttonLeft":
|
||||
result =
|
||||
_drawningAirbus.MoveTransport(DirectionType.Left);
|
||||
_drawningBus.MoveTransport(DirectionType.Left);
|
||||
break;
|
||||
case "buttonRight":
|
||||
result =
|
||||
_drawningAirbus.MoveTransport(DirectionType.Right);
|
||||
_drawningBus.MoveTransport(DirectionType.Right);
|
||||
break;
|
||||
}
|
||||
if (result)
|
||||
@ -92,5 +116,6 @@ namespace ProjectAirbus
|
||||
Draw();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user