Добавление родителей и ввод конструкторов
This commit is contained in:
parent
9e549db077
commit
cc18d95546
@ -4,7 +4,7 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace AirBus
|
namespace AirBus.Drawings
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Направление перемещения
|
/// Направление перемещения
|
75
AirBus/AirBus/Drawings/DrawingAirBus.cs
Normal file
75
AirBus/AirBus/Drawings/DrawingAirBus.cs
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using AirBus.Entities;
|
||||||
|
|
||||||
|
namespace AirBus.Drawings
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Класс отвечающий за прорисовку и перемещение объекта-сущности
|
||||||
|
/// </summary>
|
||||||
|
public class DrawingAirBus : DrawingPlane
|
||||||
|
{
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="speed">Скорость</param>
|
||||||
|
/// <param name="weight">Вес</param>
|
||||||
|
/// <param name="bodyColor">Основной цвет</param>
|
||||||
|
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||||
|
/// <param name="extraEngine">Признак наличия дополнительных пары двигателей</param>
|
||||||
|
/// <param name="secondFloor">Признак наличия второго этажа</param>
|
||||||
|
public DrawingAirBus(int speed, double weight, Color bodyColor, Color additionalColor,
|
||||||
|
bool extraEngine, bool secondFloor) : base(175, 72)
|
||||||
|
{
|
||||||
|
EntityPlane = new EntityAirBus(speed, weight, bodyColor, additionalColor, extraEngine, secondFloor);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void DrawTransport(Graphics g)
|
||||||
|
{
|
||||||
|
if (EntityPlane == null || EntityPlane is not EntityAirBus airBus || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Pen pen = new(Color.Black, 1);
|
||||||
|
Brush additionalBrush = new SolidBrush(airBus.AdditionalColor);
|
||||||
|
Brush br = new SolidBrush(airBus.BodyColor);
|
||||||
|
Brush brBlack = new SolidBrush(Color.Black);
|
||||||
|
|
||||||
|
base.DrawTransport(g);
|
||||||
|
|
||||||
|
if (airBus.ExtraEngine) // двигатели опционально
|
||||||
|
{
|
||||||
|
|
||||||
|
g.FillEllipse(additionalBrush, _startPosX.Value + 75, _startPosY.Value + 51, 10, 10);
|
||||||
|
g.FillEllipse(additionalBrush, _startPosX.Value + 80, _startPosY.Value + 51, 10, 10);
|
||||||
|
g.DrawArc(pen, _startPosX.Value + 75, _startPosY.Value + 51, 10, 10, 90, 180);
|
||||||
|
g.DrawArc(pen, _startPosX.Value + 80, _startPosY.Value + 51, 10, 10, -90, 180);
|
||||||
|
g.DrawLine(pen, new Point(_startPosX.Value + 80, _startPosY.Value + 51), new Point(_startPosX.Value + 85, _startPosY.Value + 51));
|
||||||
|
g.DrawLine(pen, new Point(_startPosX.Value + 80, _startPosY.Value + 61), new Point(_startPosX.Value + 85, _startPosY.Value + 61));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (airBus.SecondFloor) // пассажирский второй этаж
|
||||||
|
{
|
||||||
|
|
||||||
|
g.FillRectangle(additionalBrush, _startPosX.Value + 90, _startPosY.Value + 25, 50, 10);
|
||||||
|
g.DrawRectangle(pen, _startPosX.Value + 90, _startPosY.Value + 25, 50, 10);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -3,18 +3,16 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using AirBus.Entities;
|
||||||
|
|
||||||
namespace AirBus
|
namespace AirBus.Drawings
|
||||||
{
|
{
|
||||||
/// <summary>
|
public class DrawingPlane
|
||||||
/// Класс отвечающий за прорисовку и перемещение объекта-сущности
|
|
||||||
/// </summary>
|
|
||||||
public class DrawingAirBus
|
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Класс-сущность
|
/// Класс-сущность
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public EntityAirBus? EntityAirBus { get; set; }
|
public EntityPlane? EntityPlane { get; protected set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ширина окна
|
/// Ширина окна
|
||||||
@ -29,12 +27,12 @@ namespace AirBus
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Левая координата прорисовки самолёта
|
/// Левая координата прорисовки самолёта
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private int? _startPosX;
|
protected int? _startPosX;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Верхняя координата прорисовки самолёта
|
/// Верхняя координата прорисовки самолёта
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private int? _startPosY;
|
protected int? _startPosY;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ширина прорисовки самолёта
|
/// Ширина прорисовки самолёта
|
||||||
@ -47,26 +45,40 @@ namespace AirBus
|
|||||||
private readonly int _drawingAirBusHeight = 72;
|
private readonly int _drawingAirBusHeight = 72;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Инициализация свойств
|
/// Пустой конструктор
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="speed">Скорость</param>
|
private DrawingPlane()
|
||||||
/// <param name="weight">Вес</param>
|
|
||||||
/// <param name="bodyColor">Основной цвет</param>
|
|
||||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
|
||||||
/// <param name="extraEngine">Признак наличия дополнительных пары двигателей</param>
|
|
||||||
/// <param name="secondFloor">Признак наличия второго этажа</param>
|
|
||||||
/// <param name="wingLine">Признак наличия линии на крыле</param>
|
|
||||||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor,
|
|
||||||
bool extraEngine, bool secondFloor)
|
|
||||||
{
|
{
|
||||||
EntityAirBus = new EntityAirBus();
|
|
||||||
EntityAirBus.Init(speed, weight, bodyColor, additionalColor, extraEngine, secondFloor);
|
|
||||||
_pictureHeight = null;
|
_pictureHeight = null;
|
||||||
_pictureWidth = null;
|
_pictureWidth = null;
|
||||||
_startPosX = null;
|
_startPosX = null;
|
||||||
_startPosY = null;
|
_startPosY = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="drawingAirBusWidth">Ширина прорисовки</param>
|
||||||
|
/// <param name="drawingAirBusHeight">Высота прорисовки</param>
|
||||||
|
protected DrawingPlane(int drawingAirBusWidth, int drawingAirBusHeight) : this()
|
||||||
|
{
|
||||||
|
_drawingAirBusWidth = drawingAirBusWidth;
|
||||||
|
_drawingAirBusHeight = drawingAirBusHeight;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="speed">Скорость</param>
|
||||||
|
/// <param name="weight">Вес</param>
|
||||||
|
/// <param name="bodyColor">Основной цвет</param>
|
||||||
|
public DrawingPlane(int speed, double weight, Color bodyColor) : this()
|
||||||
|
{
|
||||||
|
EntityPlane = new EntityPlane(speed, weight, bodyColor);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Установка границ поля
|
/// Установка границ поля
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -114,7 +126,7 @@ namespace AirBus
|
|||||||
/// <returns>true - перемещение выполнено, false - перемещение невозможно</returns>
|
/// <returns>true - перемещение выполнено, false - перемещение невозможно</returns>
|
||||||
public bool MoveTransport(DirectionType direction)
|
public bool MoveTransport(DirectionType direction)
|
||||||
{
|
{
|
||||||
if (EntityAirBus == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
if (EntityPlane == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -122,29 +134,29 @@ namespace AirBus
|
|||||||
switch (direction)
|
switch (direction)
|
||||||
{
|
{
|
||||||
case DirectionType.Left:
|
case DirectionType.Left:
|
||||||
if(_startPosX.Value - EntityAirBus.Step > 0)
|
if (_startPosX.Value - EntityPlane.Step > 0)
|
||||||
{
|
{
|
||||||
_startPosX -= (int)EntityAirBus.Step;
|
_startPosX -= (int)EntityPlane.Step;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case DirectionType.Up:
|
case DirectionType.Up:
|
||||||
if(_startPosY.Value - EntityAirBus.Step > 0)
|
if (_startPosY.Value - EntityPlane.Step > 0)
|
||||||
{
|
{
|
||||||
_startPosY -= (int)EntityAirBus.Step;
|
_startPosY -= (int)EntityPlane.Step;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case DirectionType.Right:
|
case DirectionType.Right:
|
||||||
if(_startPosX.Value + EntityAirBus.Step + _drawingAirBusWidth < _pictureWidth.Value )
|
if (_startPosX.Value + EntityPlane.Step + _drawingAirBusWidth < _pictureWidth.Value)
|
||||||
{
|
{
|
||||||
_startPosX += (int)EntityAirBus.Step;
|
_startPosX += (int)EntityPlane.Step;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
case DirectionType.Down:
|
case DirectionType.Down:
|
||||||
if(_startPosY + EntityAirBus.Step + _drawingAirBusHeight < _pictureHeight.Value )
|
if (_startPosY + EntityPlane.Step + _drawingAirBusHeight < _pictureHeight.Value)
|
||||||
{
|
{
|
||||||
_startPosY += (int)EntityAirBus.Step;
|
_startPosY += (int)EntityPlane.Step;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
@ -156,16 +168,15 @@ namespace AirBus
|
|||||||
/// Прорисовка объекта
|
/// Прорисовка объекта
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="g"></param>
|
/// <param name="g"></param>
|
||||||
public void DrawTransport(Graphics g)
|
public virtual void DrawTransport(Graphics g)
|
||||||
{
|
{
|
||||||
if (EntityAirBus == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
if (EntityPlane == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Pen pen = new(Color.Black, 1);
|
Pen pen = new(Color.Black, 1);
|
||||||
Brush additionalBrush = new SolidBrush(EntityAirBus.AdditionalColor);
|
Brush br = new SolidBrush(EntityPlane.BodyColor);
|
||||||
Brush br = new SolidBrush(EntityAirBus.BodyColor);
|
|
||||||
Brush brBlack = new SolidBrush(Color.Black);
|
Brush brBlack = new SolidBrush(Color.Black);
|
||||||
|
|
||||||
//точки для заднего крыла
|
//точки для заднего крыла
|
||||||
@ -214,28 +225,6 @@ namespace AirBus
|
|||||||
g.FillEllipse(brBlack, _startPosX.Value + 50, _startPosY.Value + 45, 7, 7); //крыло
|
g.FillEllipse(brBlack, _startPosX.Value + 50, _startPosY.Value + 45, 7, 7); //крыло
|
||||||
g.FillRectangle(brBlack, _startPosX.Value + 54, _startPosY.Value + 45, 55, 7);
|
g.FillRectangle(brBlack, _startPosX.Value + 54, _startPosY.Value + 45, 55, 7);
|
||||||
g.FillEllipse(brBlack, _startPosX.Value + 105, _startPosY.Value + 45, 7, 7);
|
g.FillEllipse(brBlack, _startPosX.Value + 105, _startPosY.Value + 45, 7, 7);
|
||||||
|
|
||||||
if(EntityAirBus.ExtraEngine) // двигатели опционально
|
|
||||||
{
|
|
||||||
|
|
||||||
g.FillEllipse(additionalBrush, _startPosX.Value + 75, _startPosY.Value + 51, 10, 10);
|
|
||||||
g.FillEllipse(additionalBrush, _startPosX.Value + 80, _startPosY.Value + 51, 10, 10);
|
|
||||||
g.DrawArc(pen, _startPosX.Value + 75, _startPosY.Value + 51, 10, 10, 90, 180);
|
|
||||||
g.DrawArc(pen, _startPosX.Value + 80, _startPosY.Value + 51, 10, 10, -90, 180);
|
|
||||||
g.DrawLine(pen, new Point(_startPosX.Value + 80, _startPosY.Value + 51), new Point(_startPosX.Value + 85, _startPosY.Value + 51));
|
|
||||||
g.DrawLine(pen, new Point(_startPosX.Value + 80, _startPosY.Value + 61), new Point(_startPosX.Value + 85, _startPosY.Value + 61));
|
|
||||||
}
|
|
||||||
|
|
||||||
if(EntityAirBus.SecondFloor) // пассажирский второй этаж
|
|
||||||
{
|
|
||||||
|
|
||||||
g.FillRectangle(additionalBrush, _startPosX.Value + 90, _startPosY.Value + 25, 50, 10);
|
|
||||||
g.DrawRectangle(pen, _startPosX.Value + 90, _startPosY.Value + 25, 50, 10);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -4,28 +4,13 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace AirBus
|
namespace AirBus.Entities
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Класс-сущность "Аэробус"
|
/// Класс-сущность "Аэробус"
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class EntityAirBus
|
public class EntityAirBus : EntityPlane
|
||||||
{
|
{
|
||||||
/// <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>
|
||||||
@ -41,14 +26,6 @@ namespace AirBus
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public bool SecondFloor { get; private set; }
|
public bool SecondFloor { get; private set; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Шаг перемещения самолёта
|
|
||||||
/// </summary>
|
|
||||||
public double Step => Speed * 100 / Weight;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Инициализация полей объекта-класса самолёта "Аэробус"
|
/// Инициализация полей объекта-класса самолёта "Аэробус"
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -58,13 +35,9 @@ namespace AirBus
|
|||||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||||
/// <param name="extraEngine">Признак наличия дополнительных пары двигателей</param>
|
/// <param name="extraEngine">Признак наличия дополнительных пары двигателей</param>
|
||||||
/// <param name="secondFloor">Признак наличия второго этажа</param>
|
/// <param name="secondFloor">Признак наличия второго этажа</param>
|
||||||
|
public EntityAirBus(int speed, double weight, Color bodyColor, Color additionalColor,
|
||||||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor,
|
bool extraEngine, bool secondFloor) : base(speed, weight, bodyColor)
|
||||||
bool extraEngine, bool secondFloor)
|
|
||||||
{
|
{
|
||||||
Speed = speed;
|
|
||||||
Weight = weight;
|
|
||||||
BodyColor = bodyColor;
|
|
||||||
AdditionalColor = additionalColor;
|
AdditionalColor = additionalColor;
|
||||||
ExtraEngine = extraEngine;
|
ExtraEngine = extraEngine;
|
||||||
SecondFloor = secondFloor;
|
SecondFloor = secondFloor;
|
49
AirBus/AirBus/Entities/EntityPlane.cs
Normal file
49
AirBus/AirBus/Entities/EntityPlane.cs
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AirBus.Entities
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Класс-сущность "Самолёт"
|
||||||
|
/// </summary>
|
||||||
|
public class EntityPlane
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Скорость
|
||||||
|
/// </summary>
|
||||||
|
public int Speed { get; protected set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Вес
|
||||||
|
/// </summary>
|
||||||
|
public double Weight { get; protected set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Цвет корпуса
|
||||||
|
/// </summary>
|
||||||
|
public Color BodyColor { get; protected set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Шаг перемещения самолёта
|
||||||
|
/// </summary>
|
||||||
|
public double Step => Speed * 100 / Weight;
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор сущности Plane
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="speed">Скорость</param>
|
||||||
|
/// <param name="weight">Вес</param>
|
||||||
|
/// <param name="bodyColor">Основной цвет</param>
|
||||||
|
public EntityPlane(int speed, double weight, Color bodyColor)
|
||||||
|
{
|
||||||
|
Speed = speed;
|
||||||
|
Weight = weight;
|
||||||
|
BodyColor = bodyColor;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
18
AirBus/AirBus/FormAirBus.Designer.cs
generated
18
AirBus/AirBus/FormAirBus.Designer.cs
generated
@ -35,6 +35,7 @@
|
|||||||
buttonUp = new Button();
|
buttonUp = new Button();
|
||||||
buttonDown = new Button();
|
buttonDown = new Button();
|
||||||
buttonRight = new Button();
|
buttonRight = new Button();
|
||||||
|
buttonCreatePlane = new Button();
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBoxAirBus).BeginInit();
|
((System.ComponentModel.ISupportInitialize)pictureBoxAirBus).BeginInit();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
@ -52,9 +53,9 @@
|
|||||||
buttonCreateAirBus.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
buttonCreateAirBus.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||||
buttonCreateAirBus.Location = new Point(12, 427);
|
buttonCreateAirBus.Location = new Point(12, 427);
|
||||||
buttonCreateAirBus.Name = "buttonCreateAirBus";
|
buttonCreateAirBus.Name = "buttonCreateAirBus";
|
||||||
buttonCreateAirBus.Size = new Size(94, 29);
|
buttonCreateAirBus.Size = new Size(305, 29);
|
||||||
buttonCreateAirBus.TabIndex = 1;
|
buttonCreateAirBus.TabIndex = 1;
|
||||||
buttonCreateAirBus.Text = "Создать";
|
buttonCreateAirBus.Text = "Создать AirBus";
|
||||||
buttonCreateAirBus.UseVisualStyleBackColor = true;
|
buttonCreateAirBus.UseVisualStyleBackColor = true;
|
||||||
buttonCreateAirBus.Click += buttonCreateAirBus_Click;
|
buttonCreateAirBus.Click += buttonCreateAirBus_Click;
|
||||||
//
|
//
|
||||||
@ -109,6 +110,17 @@
|
|||||||
buttonRight.UseVisualStyleBackColor = true;
|
buttonRight.UseVisualStyleBackColor = true;
|
||||||
buttonRight.Click += ButtonMove_Click;
|
buttonRight.Click += ButtonMove_Click;
|
||||||
//
|
//
|
||||||
|
// buttonCreatePlane
|
||||||
|
//
|
||||||
|
buttonCreatePlane.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||||
|
buttonCreatePlane.Location = new Point(333, 427);
|
||||||
|
buttonCreatePlane.Name = "buttonCreatePlane";
|
||||||
|
buttonCreatePlane.Size = new Size(305, 29);
|
||||||
|
buttonCreatePlane.TabIndex = 1;
|
||||||
|
buttonCreatePlane.Text = "Создать самолёт";
|
||||||
|
buttonCreatePlane.UseVisualStyleBackColor = true;
|
||||||
|
buttonCreatePlane.Click += buttonCreateAirBus_Click;
|
||||||
|
//
|
||||||
// FormAirBus
|
// FormAirBus
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
@ -118,6 +130,7 @@
|
|||||||
Controls.Add(buttonDown);
|
Controls.Add(buttonDown);
|
||||||
Controls.Add(buttonUp);
|
Controls.Add(buttonUp);
|
||||||
Controls.Add(buttonLeft);
|
Controls.Add(buttonLeft);
|
||||||
|
Controls.Add(buttonCreatePlane);
|
||||||
Controls.Add(buttonCreateAirBus);
|
Controls.Add(buttonCreateAirBus);
|
||||||
Controls.Add(pictureBoxAirBus);
|
Controls.Add(pictureBoxAirBus);
|
||||||
Name = "FormAirBus";
|
Name = "FormAirBus";
|
||||||
@ -134,5 +147,6 @@
|
|||||||
private Button buttonUp;
|
private Button buttonUp;
|
||||||
private Button buttonDown;
|
private Button buttonDown;
|
||||||
private Button buttonRight;
|
private Button buttonRight;
|
||||||
|
private Button buttonCreatePlane;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -7,12 +7,13 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
using AirBus.Drawings;
|
||||||
|
|
||||||
namespace AirBus;
|
namespace AirBus;
|
||||||
|
|
||||||
public partial class FormAirBus : Form
|
public partial class FormAirBus : Form
|
||||||
{
|
{
|
||||||
private DrawingAirBus? _drawingAirBus;
|
private DrawingPlane? _drawingPlane;
|
||||||
public FormAirBus()
|
public FormAirBus()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
@ -20,33 +21,63 @@ public partial class FormAirBus : Form
|
|||||||
|
|
||||||
private void Draw()
|
private void Draw()
|
||||||
{
|
{
|
||||||
if (_drawingAirBus == null)
|
if (_drawingPlane == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Bitmap bmp = new(pictureBoxAirBus.Width, pictureBoxAirBus.Height);
|
Bitmap bmp = new(pictureBoxAirBus.Width, pictureBoxAirBus.Height);
|
||||||
Graphics gr = Graphics.FromImage(bmp);
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
_drawingAirBus.DrawTransport(gr);
|
_drawingPlane.DrawTransport(gr);
|
||||||
pictureBoxAirBus.Image = bmp;
|
pictureBoxAirBus.Image = bmp;
|
||||||
}
|
}
|
||||||
private void buttonCreateAirBus_Click(object sender, EventArgs e)
|
|
||||||
|
private void CreateObject(string type)
|
||||||
{
|
{
|
||||||
Random random = new();
|
Random random = new();
|
||||||
_drawingAirBus = new DrawingAirBus();
|
switch (type)
|
||||||
_drawingAirBus.Init(random.Next(100, 300), random.Next(1000, 3000),
|
{
|
||||||
|
case nameof(DrawingPlane):
|
||||||
|
_drawingPlane = new DrawingPlane(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(DrawingAirBus):
|
||||||
|
_drawingPlane = new DrawingAirBus(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)),
|
||||||
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)));
|
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
|
||||||
_drawingAirBus.SetPictureSize(pictureBoxAirBus.Width, pictureBoxAirBus.Height);
|
break;
|
||||||
_drawingAirBus.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
default:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_drawingPlane.SetPictureSize(pictureBoxAirBus.Width, pictureBoxAirBus.Height);
|
||||||
|
_drawingPlane.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Обработка нажатия кнопки "Создать Аеробус"
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void buttonCreateAirBus_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
CreateObject(nameof(DrawingAirBus));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Обработка нажатия кнопки "Создать самолёт"
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void buttonCreatePlane_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
CreateObject(nameof(DrawingPlane));
|
||||||
|
}
|
||||||
|
|
||||||
private void ButtonMove_Click(object sender, EventArgs e)
|
private void ButtonMove_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (_drawingAirBus == null)
|
if (_drawingPlane == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -56,16 +87,16 @@ public partial class FormAirBus : Form
|
|||||||
switch (name)
|
switch (name)
|
||||||
{
|
{
|
||||||
case "buttonUp":
|
case "buttonUp":
|
||||||
result = _drawingAirBus.MoveTransport(DirectionType.Up);
|
result = _drawingPlane.MoveTransport(DirectionType.Up);
|
||||||
break;
|
break;
|
||||||
case "buttonDown":
|
case "buttonDown":
|
||||||
result = _drawingAirBus.MoveTransport(DirectionType.Down);
|
result = _drawingPlane.MoveTransport(DirectionType.Down);
|
||||||
break;
|
break;
|
||||||
case "buttonLeft":
|
case "buttonLeft":
|
||||||
result = _drawingAirBus.MoveTransport(DirectionType.Left);
|
result = _drawingPlane.MoveTransport(DirectionType.Left);
|
||||||
break;
|
break;
|
||||||
case "buttonRight":
|
case "buttonRight":
|
||||||
result = _drawingAirBus.MoveTransport(DirectionType.Right);
|
result = _drawingPlane.MoveTransport(DirectionType.Right);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user