From dd086e5c0bf0a2a1daa0c98d310552442e76b6d4 Mon Sep 17 00:00:00 2001 From: ArtemEmelyanov Date: Sat, 15 Oct 2022 18:37:59 +0400 Subject: [PATCH] LabWork01 --- Airbus/Airbus/DrawningPlane.cs | 41 +++++++++++++++++----------------- Airbus/Airbus/FormPlane.cs | 29 ++++++++++++------------ 2 files changed, 35 insertions(+), 35 deletions(-) diff --git a/Airbus/Airbus/DrawningPlane.cs b/Airbus/Airbus/DrawningPlane.cs index b6f61ed..88d7b81 100644 --- a/Airbus/Airbus/DrawningPlane.cs +++ b/Airbus/Airbus/DrawningPlane.cs @@ -11,7 +11,7 @@ namespace Airbus /// /// Класс-сущность /// - public EntityPlane Airbus { get; private set; } + public EntityPlane Plane { get; private set; } /// /// Левая координата отрисовки самолета @@ -34,20 +34,21 @@ namespace Airbus /// /// Ширина отрисовки самолета /// - private readonly int _AirbusWidth = 130; + private readonly int _PlaneWidth = 130; /// /// Высота отрисовки самолета /// - private readonly int _AirbusHeight = 70; + private readonly int _PlaneHeight = 70; /// /// Инициализация свойств /// /// Скорость /// Вес самолета /// Цвет кузова - public void Init(EntityPlane Airbus) + public void Init(int speed, float weight, Color bodyColor) { - this.Airbus = Airbus; + Plane = new EntityPlane(); + Plane.Init(speed, weight, bodyColor); } /// /// Установка позиции самолета @@ -58,7 +59,7 @@ namespace Airbus /// Высота картинки public void SetPosition(int x, int y, int width, int height) { - if (x >= 0 && x + _AirbusWidth <= width && y >= 0 && y + _AirbusHeight <= height) + if (x >= 0 && x + _PlaneWidth <= width && y >= 0 && y + _PlaneHeight <= height) { _startPosX = x; _startPosY = y; @@ -81,30 +82,30 @@ namespace Airbus { // вправо case Direction.Right: - if (_startPosX + _AirbusWidth + Airbus.Step < _pictureWidth) + if (_startPosX + _PlaneWidth + Plane.Step < _pictureWidth) { - _startPosX += Airbus.Step; + _startPosX += Plane.Step; } break; //влево case Direction.Left: - if (_startPosX - Airbus.Step > 0) + if (_startPosX - Plane.Step > 0) { - _startPosX -= Airbus.Step; + _startPosX -= Plane.Step; } break; //вверх case Direction.Up: - if (_startPosY - Airbus.Step > 0) + if (_startPosY - Plane.Step > 0) { - _startPosY -= Airbus.Step; + _startPosY -= Plane.Step; } break; //вниз case Direction.Down: - if (_startPosY + _AirbusHeight + Airbus.Step < _pictureHeight) + if (_startPosY + _PlaneHeight + Plane.Step < _pictureHeight) { - _startPosY += Airbus.Step; + _startPosY += Plane.Step; } break; } @@ -140,7 +141,7 @@ namespace Airbus g.DrawEllipse(pen, _startPosX + 29, _startPosY + 55, 10, 10); g.DrawEllipse(pen, _startPosX + 41, _startPosY + 55, 10, 10); - Brush br = new SolidBrush(Airbus?.BodyColor ?? Color.Black); + Brush br = new SolidBrush(Plane?.BodyColor ?? Color.Black); g.FillEllipse(br, _startPosX, _startPosY + 31, 20, 19); g.FillRectangle(br, _startPosX + 10, _startPosY + 31, 100, 19); @@ -158,19 +159,19 @@ namespace Airbus { _pictureWidth = width; _pictureHeight = height; - if (_pictureWidth <= _AirbusWidth || _pictureHeight <= _AirbusHeight) + if (_pictureWidth <= _PlaneWidth || _pictureHeight <= _PlaneHeight) { _pictureWidth = null; _pictureHeight = null; return; } - if (_startPosX + _AirbusWidth > _pictureWidth) + if (_startPosX + _PlaneWidth > _pictureWidth) { - _startPosX = _pictureWidth.Value - _AirbusWidth; + _startPosX = _pictureWidth.Value - _PlaneWidth; } - if (_startPosY + _AirbusHeight > _pictureHeight) + if (_startPosY + _PlaneHeight > _pictureHeight) { - _startPosY = _pictureHeight.Value - _AirbusHeight; + _startPosY = _pictureHeight.Value - _PlaneHeight; } } } diff --git a/Airbus/Airbus/FormPlane.cs b/Airbus/Airbus/FormPlane.cs index 5507460..c0fee1f 100644 --- a/Airbus/Airbus/FormPlane.cs +++ b/Airbus/Airbus/FormPlane.cs @@ -12,7 +12,7 @@ namespace Airbus { public partial class FormPlane : Form { - private DrawningPlane _airbus; + private DrawningPlane _plane; public FormPlane() { @@ -25,7 +25,7 @@ namespace Airbus { Bitmap bmp = new(pictureBoxAirbus.Width, pictureBoxAirbus.Height); Graphics gr = Graphics.FromImage(bmp); - _airbus?.DrawTransport(gr); + _plane?.DrawTransport(gr); pictureBoxAirbus.Image = bmp; } /// @@ -35,15 +35,14 @@ namespace Airbus /// private void ButtonCreate_Click(object sender, EventArgs e) { + Random rnd = new(); - _airbus = new DrawningPlane(); - EntityPlane Airbus = new EntityPlane(); - Airbus.Init(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); - _airbus.Init(Airbus); - _airbus.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxAirbus.Width, pictureBoxAirbus.Height); - toolStripStatusLabelSpeed.Text = $"Скорость: {_airbus.Airbus.Speed}"; - toolStripStatusLabelWeight.Text = $"Вес: {_airbus.Airbus.Weight}"; - toolStripStatusLabelBodyColor.Text = $"Цвет: {_airbus.Airbus.BodyColor.Name}"; + _plane = new DrawningPlane(); + _plane.Init(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); + _plane.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxAirbus.Width, pictureBoxAirbus.Height); + toolStripStatusLabelSpeed.Text = $"Скорость: {_plane.Plane.Speed}"; + toolStripStatusLabelWeight.Text = $"Вес: {_plane.Plane.Weight}"; + toolStripStatusLabelBodyColor.Text = $"Цвет: {_plane.Plane.BodyColor.Name}"; Draw(); } /// @@ -58,16 +57,16 @@ namespace Airbus switch (name) { case "buttonUp": - _airbus?.MoveTransport(Direction.Up); + _plane?.MoveTransport(Direction.Up); break; case "buttonDown": - _airbus?.MoveTransport(Direction.Down); + _plane?.MoveTransport(Direction.Down); break; case "buttonLeft": - _airbus?.MoveTransport(Direction.Left); + _plane?.MoveTransport(Direction.Left); break; case "buttonRight": - _airbus?.MoveTransport(Direction.Right); + _plane?.MoveTransport(Direction.Right); break; } Draw(); @@ -79,7 +78,7 @@ namespace Airbus /// private void PictureBoxAirbus_Resize(object sender, EventArgs e) { - _airbus?.ChangeBorders(pictureBoxAirbus.Width, pictureBoxAirbus.Height); + _plane?.ChangeBorders(pictureBoxAirbus.Width, pictureBoxAirbus.Height); Draw(); }