From afb87d1e2f11a89e234f5e87cd9792405c5674d9 Mon Sep 17 00:00:00 2001 From: Evgehil Date: Mon, 5 Feb 2024 11:14:31 +0400 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=BA=D0=B0=20LabWork01?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Project_airbus/DrawingAirbus.cs | 67 ++++++++++++++++--- 1 file changed, 57 insertions(+), 10 deletions(-) diff --git a/Project_airbus/Project_airbus/DrawingAirbus.cs b/Project_airbus/Project_airbus/DrawingAirbus.cs index efc24c3..20e7e1d 100644 --- a/Project_airbus/Project_airbus/DrawingAirbus.cs +++ b/Project_airbus/Project_airbus/DrawingAirbus.cs @@ -38,12 +38,12 @@ public class DrawingAirbus /// /// Ширина прорисовки самолета(аэробуса) /// - private readonly int _drawingCarWidth = 130; + private readonly int _drawingAirbusWidth = 130; /// /// Высота прорисовки самолета(аэробуса) /// - private readonly int _drawingCarHeight = 60; + private readonly int _drawingAirbusHeight = 60; @@ -56,8 +56,8 @@ public class DrawingAirbus /// Вес самолета /// Основной цвет /// Дополнительный цвет - /// ПРизнак наличия отсека - /// ПРизнак наличия дополнительных двигателей + /// Признак наличия отсека + /// Признак наличия дополнительных двигателей public void Init(int speed, double weight, Color bodyAirbus, Color additionalColor, bool bodySection, bool motor) { EntityAirbus = new EntityAirbus(); @@ -78,9 +78,31 @@ public class DrawingAirbus /// true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах public bool SetPictureSize(int wigth, int height) { - _pictureWidth = wigth; - _pictureHeight = height; + + if(wigth < _drawingAirbusWidth || height < _drawingAirbusHeight) { return false; }; + _pictureWidth = wigth; + _pictureHeight = height; + if(_startPosX !=null || _startPosY != null) + { + if(_startPosX + _drawingAirbusWidth > _pictureWidth) + { + _startPosX = -_drawingAirbusWidth + _pictureWidth; + } + else if(_startPosX < 0) + { + _startPosX = 0; + } + if(_startPosY + _drawingAirbusHeight > _pictureHeight) + { + _startPosY = - _drawingAirbusHeight + _pictureHeight; + } + else if(_startPosY < 0) + { + _startPosY = 0; + } + } return true; + } @@ -95,8 +117,33 @@ public class DrawingAirbus { return; } - _startPosX = x; - _startPosY = y; + + if (x+_drawingAirbusWidth > _pictureWidth) + { + _startPosX = _pictureWidth - _drawingAirbusWidth; + } + else if(x < 0) + { + _startPosX = 0; + } + else + { + _startPosX = x; + } + + if(y + _drawingAirbusHeight > _pictureHeight) + { + _startPosY = _pictureHeight - _drawingAirbusHeight; + } + else if(y < 0) + { + _startPosY = 0; + } + else + { + _startPosY = y; + } + } /// @@ -119,13 +166,13 @@ public class DrawingAirbus } return true; case DirectionType.Right: - if (_startPosX.Value + _drawingCarWidth + EntityAirbus.step < _pictureWidth) + if (_startPosX.Value + _drawingAirbusWidth + EntityAirbus.step < _pictureWidth) { _startPosX += (int)EntityAirbus.step; } return true; case DirectionType.Down: - if (_startPosY.Value + _drawingCarHeight + EntityAirbus.step < _pictureHeight) + if (_startPosY.Value + _drawingAirbusHeight + EntityAirbus.step < _pictureHeight) { _startPosY += (int)EntityAirbus.step; }