From cc18d95546062270efd7c3eff4c7eb80434eecd4 Mon Sep 17 00:00:00 2001 From: Melkij_R_D Date: Tue, 17 Dec 2024 15:04:50 +0400 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D1=80=D0=BE=D0=B4=D0=B8=D1=82=D0=B5=D0=BB?= =?UTF-8?q?=D0=B5=D0=B9=20=D0=B8=20=D0=B2=D0=B2=D0=BE=D0=B4=20=D0=BA=D0=BE?= =?UTF-8?q?=D0=BD=D1=81=D1=82=D1=80=D1=83=D0=BA=D1=82=D0=BE=D1=80=D0=BE?= =?UTF-8?q?=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBus/AirBus/{ => Drawings}/DirectionType.cs | 2 +- AirBus/AirBus/Drawings/DrawingAirBus.cs | 75 +++++++++++++ .../DrawingPlane.cs} | 103 ++++++++---------- AirBus/AirBus/{ => Entities}/EntityAirBus.cs | 41 ++----- AirBus/AirBus/Entities/EntityPlane.cs | 49 +++++++++ AirBus/AirBus/FormAirBus.Designer.cs | 18 ++- AirBus/AirBus/FormAirBus.cs | 59 +++++++--- 7 files changed, 239 insertions(+), 108 deletions(-) rename AirBus/AirBus/{ => Drawings}/DirectionType.cs (95%) create mode 100644 AirBus/AirBus/Drawings/DrawingAirBus.cs rename AirBus/AirBus/{DrawingAirBus.cs => Drawings/DrawingPlane.cs} (70%) rename AirBus/AirBus/{ => Entities}/EntityAirBus.cs (64%) create mode 100644 AirBus/AirBus/Entities/EntityPlane.cs diff --git a/AirBus/AirBus/DirectionType.cs b/AirBus/AirBus/Drawings/DirectionType.cs similarity index 95% rename from AirBus/AirBus/DirectionType.cs rename to AirBus/AirBus/Drawings/DirectionType.cs index 73cb7b3..5bad0b0 100644 --- a/AirBus/AirBus/DirectionType.cs +++ b/AirBus/AirBus/Drawings/DirectionType.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace AirBus +namespace AirBus.Drawings { /// /// Направление перемещения diff --git a/AirBus/AirBus/Drawings/DrawingAirBus.cs b/AirBus/AirBus/Drawings/DrawingAirBus.cs new file mode 100644 index 0000000..7a495dc --- /dev/null +++ b/AirBus/AirBus/Drawings/DrawingAirBus.cs @@ -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 +{ + /// + /// Класс отвечающий за прорисовку и перемещение объекта-сущности + /// + public class DrawingAirBus : DrawingPlane + { + + /// + /// Конструктор + /// + /// Скорость + /// Вес + /// Основной цвет + /// Дополнительный цвет + /// Признак наличия дополнительных пары двигателей + /// Признак наличия второго этажа + 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); + + + } + } + + + + + + + + + } +} diff --git a/AirBus/AirBus/DrawingAirBus.cs b/AirBus/AirBus/Drawings/DrawingPlane.cs similarity index 70% rename from AirBus/AirBus/DrawingAirBus.cs rename to AirBus/AirBus/Drawings/DrawingPlane.cs index 090d81f..01af9a3 100644 --- a/AirBus/AirBus/DrawingAirBus.cs +++ b/AirBus/AirBus/Drawings/DrawingPlane.cs @@ -3,18 +3,16 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using AirBus.Entities; -namespace AirBus +namespace AirBus.Drawings { - /// - /// Класс отвечающий за прорисовку и перемещение объекта-сущности - /// - public class DrawingAirBus + public class DrawingPlane { /// /// Класс-сущность /// - public EntityAirBus? EntityAirBus { get; set; } + public EntityPlane? EntityPlane { get; protected set; } /// /// Ширина окна @@ -29,12 +27,12 @@ namespace AirBus /// /// Левая координата прорисовки самолёта /// - private int? _startPosX; + protected int? _startPosX; /// /// Верхняя координата прорисовки самолёта /// - private int? _startPosY; + protected int? _startPosY; /// /// Ширина прорисовки самолёта @@ -47,26 +45,40 @@ namespace AirBus private readonly int _drawingAirBusHeight = 72; /// - /// Инициализация свойств + /// Пустой конструктор /// - /// Скорость - /// Вес - /// Основной цвет - /// Дополнительный цвет - /// Признак наличия дополнительных пары двигателей - /// Признак наличия второго этажа - /// Признак наличия линии на крыле - public void Init(int speed, double weight, Color bodyColor, Color additionalColor, - bool extraEngine, bool secondFloor) + private DrawingPlane() { - EntityAirBus = new EntityAirBus(); - EntityAirBus.Init(speed, weight, bodyColor, additionalColor, extraEngine, secondFloor); _pictureHeight = null; _pictureWidth = null; _startPosX = null; _startPosY = null; } + /// + /// Конструктор + /// + /// Ширина прорисовки + /// Высота прорисовки + protected DrawingPlane(int drawingAirBusWidth, int drawingAirBusHeight) : this() + { + _drawingAirBusWidth = drawingAirBusWidth; + _drawingAirBusHeight = drawingAirBusHeight; + + } + + /// + /// Конструктор + /// + /// Скорость + /// Вес + /// Основной цвет + public DrawingPlane(int speed, double weight, Color bodyColor) : this() + { + EntityPlane = new EntityPlane(speed, weight, bodyColor); + + } + /// /// Установка границ поля /// @@ -114,37 +126,37 @@ namespace AirBus /// true - перемещение выполнено, false - перемещение невозможно public bool MoveTransport(DirectionType direction) { - if (EntityAirBus == null || !_startPosX.HasValue || !_startPosY.HasValue) + if (EntityPlane == null || !_startPosX.HasValue || !_startPosY.HasValue) { return false; } - switch(direction) + switch (direction) { 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; 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; 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; 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; default: @@ -156,16 +168,15 @@ namespace AirBus /// Прорисовка объекта /// /// - 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; } Pen pen = new(Color.Black, 1); - Brush additionalBrush = new SolidBrush(EntityAirBus.AdditionalColor); - Brush br = new SolidBrush(EntityAirBus.BodyColor); + Brush br = new SolidBrush(EntityPlane.BodyColor); Brush brBlack = new SolidBrush(Color.Black); //точки для заднего крыла @@ -205,7 +216,7 @@ namespace AirBus g.DrawLine(pen, new Point(_startPosX.Value + 38, _startPosY.Value + 60), new Point(_startPosX.Value + 38, _startPosY.Value + 70)); // стойка заднего шасси g.DrawLine(pen, new Point(_startPosX.Value + 39, _startPosY.Value + 60), new Point(_startPosX.Value + 39, _startPosY.Value + 70)); // стойка заднего шасси g.DrawLine(pen, new Point(_startPosX.Value + 144, _startPosY.Value + 60), new Point(_startPosX.Value + 144, _startPosY.Value + 65)); // стойка переднего шасси - + // чёрные заливки g.FillEllipse(brBlack, _startPosX.Value, _startPosY.Value + 30, 10, 10); // заднее крыло g.FillEllipse(brBlack, _startPosX.Value + 15, _startPosY.Value + 30, 10, 10); @@ -214,28 +225,6 @@ namespace AirBus g.FillEllipse(brBlack, _startPosX.Value + 50, _startPosY.Value + 45, 7, 7); //крыло g.FillRectangle(brBlack, _startPosX.Value + 54, _startPosY.Value + 45, 55, 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); - - - } - - } } } diff --git a/AirBus/AirBus/EntityAirBus.cs b/AirBus/AirBus/Entities/EntityAirBus.cs similarity index 64% rename from AirBus/AirBus/EntityAirBus.cs rename to AirBus/AirBus/Entities/EntityAirBus.cs index c3d4a69..31e1c03 100644 --- a/AirBus/AirBus/EntityAirBus.cs +++ b/AirBus/AirBus/Entities/EntityAirBus.cs @@ -4,50 +4,27 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace AirBus +namespace AirBus.Entities { /// /// Класс-сущность "Аэробус" /// - public class EntityAirBus + public class EntityAirBus : EntityPlane { - /// - /// Скорость - /// - public int Speed { get; private set; } - - /// - /// Вес - /// - public double Weight { get; private set; } - - /// - /// Цвет корпуса - /// - public Color BodyColor { get; private set; } - /// /// Дополнительный цвет для опциональных элементов /// public Color AdditionalColor { get; private set; } - + /// /// Признак (опция) наличия дополнительной пары двигателей /// public bool ExtraEngine { get; private set; } - + /// /// Признак (опция) наличия второго этажа /// public bool SecondFloor { get; private set; } - - - - - /// - /// Шаг перемещения самолёта - /// - public double Step => Speed * 100 / Weight; /// /// Инициализация полей объекта-класса самолёта "Аэробус" @@ -58,13 +35,9 @@ namespace AirBus /// Дополнительный цвет /// Признак наличия дополнительных пары двигателей /// Признак наличия второго этажа - - public void Init(int speed, double weight, Color bodyColor, Color additionalColor, - bool extraEngine, bool secondFloor) - { - Speed = speed; - Weight = weight; - BodyColor = bodyColor; + public EntityAirBus(int speed, double weight, Color bodyColor, Color additionalColor, + bool extraEngine, bool secondFloor) : base(speed, weight, bodyColor) + { AdditionalColor = additionalColor; ExtraEngine = extraEngine; SecondFloor = secondFloor; diff --git a/AirBus/AirBus/Entities/EntityPlane.cs b/AirBus/AirBus/Entities/EntityPlane.cs new file mode 100644 index 0000000..c22503d --- /dev/null +++ b/AirBus/AirBus/Entities/EntityPlane.cs @@ -0,0 +1,49 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AirBus.Entities +{ + /// + /// Класс-сущность "Самолёт" + /// + public class EntityPlane + { + /// + /// Скорость + /// + public int Speed { get; protected set; } + + /// + /// Вес + /// + public double Weight { get; protected set; } + + /// + /// Цвет корпуса + /// + public Color BodyColor { get; protected set; } + + /// + /// Шаг перемещения самолёта + /// + public double Step => Speed * 100 / Weight; + + + /// + /// Конструктор сущности Plane + /// + /// Скорость + /// Вес + /// Основной цвет + public EntityPlane(int speed, double weight, Color bodyColor) + { + Speed = speed; + Weight = weight; + BodyColor = bodyColor; + + } + } +} diff --git a/AirBus/AirBus/FormAirBus.Designer.cs b/AirBus/AirBus/FormAirBus.Designer.cs index b8f5577..4b36d44 100644 --- a/AirBus/AirBus/FormAirBus.Designer.cs +++ b/AirBus/AirBus/FormAirBus.Designer.cs @@ -35,6 +35,7 @@ buttonUp = new Button(); buttonDown = new Button(); buttonRight = new Button(); + buttonCreatePlane = new Button(); ((System.ComponentModel.ISupportInitialize)pictureBoxAirBus).BeginInit(); SuspendLayout(); // @@ -52,9 +53,9 @@ buttonCreateAirBus.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; buttonCreateAirBus.Location = new Point(12, 427); buttonCreateAirBus.Name = "buttonCreateAirBus"; - buttonCreateAirBus.Size = new Size(94, 29); + buttonCreateAirBus.Size = new Size(305, 29); buttonCreateAirBus.TabIndex = 1; - buttonCreateAirBus.Text = "Создать"; + buttonCreateAirBus.Text = "Создать AirBus"; buttonCreateAirBus.UseVisualStyleBackColor = true; buttonCreateAirBus.Click += buttonCreateAirBus_Click; // @@ -109,6 +110,17 @@ buttonRight.UseVisualStyleBackColor = true; 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 // AutoScaleDimensions = new SizeF(8F, 20F); @@ -118,6 +130,7 @@ Controls.Add(buttonDown); Controls.Add(buttonUp); Controls.Add(buttonLeft); + Controls.Add(buttonCreatePlane); Controls.Add(buttonCreateAirBus); Controls.Add(pictureBoxAirBus); Name = "FormAirBus"; @@ -134,5 +147,6 @@ private Button buttonUp; private Button buttonDown; private Button buttonRight; + private Button buttonCreatePlane; } } \ No newline at end of file diff --git a/AirBus/AirBus/FormAirBus.cs b/AirBus/AirBus/FormAirBus.cs index 9c193aa..5b5d0e9 100644 --- a/AirBus/AirBus/FormAirBus.cs +++ b/AirBus/AirBus/FormAirBus.cs @@ -7,12 +7,13 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using AirBus.Drawings; namespace AirBus; public partial class FormAirBus : Form { - private DrawingAirBus? _drawingAirBus; + private DrawingPlane? _drawingPlane; public FormAirBus() { InitializeComponent(); @@ -20,33 +21,63 @@ public partial class FormAirBus : Form private void Draw() { - if (_drawingAirBus == null) + if (_drawingPlane == null) { return; } Bitmap bmp = new(pictureBoxAirBus.Width, pictureBoxAirBus.Height); Graphics gr = Graphics.FromImage(bmp); - _drawingAirBus.DrawTransport(gr); + _drawingPlane.DrawTransport(gr); pictureBoxAirBus.Image = bmp; } - private void buttonCreateAirBus_Click(object sender, EventArgs e) + + private void CreateObject(string type) { Random random = new(); - _drawingAirBus = new DrawingAirBus(); - _drawingAirBus.Init(random.Next(100, 300), random.Next(1000, 3000), + switch (type) + { + 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)), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2))); - _drawingAirBus.SetPictureSize(pictureBoxAirBus.Width, pictureBoxAirBus.Height); - _drawingAirBus.SetPosition(random.Next(10, 100), random.Next(10, 100)); - + break; + default: + return; + } + _drawingPlane.SetPictureSize(pictureBoxAirBus.Width, pictureBoxAirBus.Height); + _drawingPlane.SetPosition(random.Next(10, 100), random.Next(10, 100)); Draw(); } + + /// + /// Обработка нажатия кнопки "Создать Аеробус" + /// + /// + /// + private void buttonCreateAirBus_Click(object sender, EventArgs e) + { + CreateObject(nameof(DrawingAirBus)); + } + + /// + /// Обработка нажатия кнопки "Создать самолёт" + /// + /// + /// + private void buttonCreatePlane_Click(object sender, EventArgs e) + { + CreateObject(nameof(DrawingPlane)); + } private void ButtonMove_Click(object sender, EventArgs e) { - if (_drawingAirBus == null) + if (_drawingPlane == null) { return; } @@ -56,16 +87,16 @@ public partial class FormAirBus : Form switch (name) { case "buttonUp": - result = _drawingAirBus.MoveTransport(DirectionType.Up); + result = _drawingPlane.MoveTransport(DirectionType.Up); break; case "buttonDown": - result = _drawingAirBus.MoveTransport(DirectionType.Down); + result = _drawingPlane.MoveTransport(DirectionType.Down); break; case "buttonLeft": - result = _drawingAirBus.MoveTransport(DirectionType.Left); + result = _drawingPlane.MoveTransport(DirectionType.Left); break; case "buttonRight": - result = _drawingAirBus.MoveTransport(DirectionType.Right); + result = _drawingPlane.MoveTransport(DirectionType.Right); break; }