From 83216e0433e603298e0b2d6283a9b19869f2fae7 Mon Sep 17 00:00:00 2001 From: sqdselo Date: Mon, 19 Feb 2024 13:55:12 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9B=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=20=E2=84=961?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../HoistingCrane/DrawningHoistingCrane.cs | 86 ++++++++++++------- .../HoistingCrane/EntityHoistingCrane.cs | 17 +++- .../HoistingCrane/FormHoistingCrane.cs | 9 +- 3 files changed, 78 insertions(+), 34 deletions(-) diff --git a/HoistingCrane/HoistingCrane/DrawningHoistingCrane.cs b/HoistingCrane/HoistingCrane/DrawningHoistingCrane.cs index c4c834c..0bf8c35 100644 --- a/HoistingCrane/HoistingCrane/DrawningHoistingCrane.cs +++ b/HoistingCrane/HoistingCrane/DrawningHoistingCrane.cs @@ -15,7 +15,7 @@ public class DrawningHoistingCrane private int? _pictureWidth; /// - /// Длина окна + /// Высота окна /// private int? _pictureHeight; @@ -31,17 +31,17 @@ public class DrawningHoistingCrane /// /// Ширина прорисовки автомобиля /// - private readonly int _drawingCarWidth = 80; + private readonly int _drawingCarWidth = 115; /// /// Высота прорисовки автомобиля /// - private readonly int _drawingCarHeight = 67; + private readonly int _drawingCarHeight = 63; - public void Init(int speed, double weight, Color bodyColor, Color additionalColor) + public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool counterweight, bool platform) { EntityHoistingCrane = new EntityHoistingCrane(); - EntityHoistingCrane.Init(speed, weight, bodyColor, additionalColor); + EntityHoistingCrane.Init(speed, weight, bodyColor, additionalColor, counterweight, platform); _pictureWidth = null; _pictureHeight = null; _startPosX = null; @@ -61,18 +61,28 @@ public class DrawningHoistingCrane public bool SetPictureSize(int width, int height) { - if ((width < _drawingCarWidth) || (height < _drawingCarHeight)) + // TODO проверка, что объект "влезает" в размеры поля + // если влезает, сохраняем границы и корректируем позицию объекта, если она была уже установлена ✔ + + if (_drawingCarHeight > height || _drawingCarWidth > width) { return false; } - // TODO проверка, что объект "влезает" в размеры поля - // если влезает, сохраняем границы и корректируем позицию объекта, если она была уже установлена - _pictureWidth = width; + _pictureHeight = height; + _pictureWidth = width; - - + if(_startPosX.HasValue && (_startPosX.Value + _drawingCarWidth > _pictureWidth)) + { + _startPosX =_pictureWidth - _drawingCarWidth; + } + + if(_startPosY.HasValue && (_startPosY.Value + _drawingCarHeight > _pictureHeight)) + { + _startPosY = _pictureHeight - _drawingCarHeight; + } return true; + } @@ -85,35 +95,29 @@ public class DrawningHoistingCrane public void SetPosition(int x, int y) { //Если размеры были заданы, то присваиваем х и у, иначе выходим из метода - if (!_pictureHeight.HasValue || !_pictureWidth.HasValue) - { - return; - } - if ((x + _drawingCarWidth > _pictureWidth) && (y + _drawingCarHeight > _pictureHeight)) + if (x < 0) + x = -x; + if (y < 0) + y = -y; + if(x + _drawingCarWidth > _pictureWidth) { - _startPosX = x - _drawingCarWidth; - _startPosY = y - _drawingCarHeight; - } - else if ((x + _drawingCarWidth <= _pictureWidth) && (y + _drawingCarHeight > _pictureHeight)) - { - _startPosX = x; - _startPosY = y - _drawingCarHeight; - } - else if ((x + _drawingCarWidth > _pictureWidth) && (y + _drawingCarHeight <= _pictureHeight)) - { - _startPosX = x - _drawingCarWidth; - _startPosY = y; + _startPosX = _pictureWidth - _drawingCarWidth; } else { _startPosX = x; + } + if (y + _drawingCarHeight > _pictureHeight) + { + _startPosY = _pictureHeight - _drawingCarHeight; + } + else + { _startPosY = y; } - - } /// @@ -215,7 +219,11 @@ public class DrawningHoistingCrane gr.FillRectangle(br, _startPosX.Value, _startPosY.Value + 25, 75, 25); gr.FillRectangle(br, _startPosX.Value, _startPosY.Value, 25, 25); - + //кран + Brush bb = new SolidBrush(EntityHoistingCrane.BodyColor); + gr.FillRectangle(bb, _startPosX.Value + 65, _startPosY.Value, 7, 25); + gr.FillRectangle(br, _startPosX.Value + 62, _startPosY.Value + 2, 45, 5); + gr.DrawLine(pen, _startPosX.Value + 105, _startPosY.Value + 2, _startPosX.Value + 107, _startPosY.Value + 40); //окно @@ -243,6 +251,22 @@ public class DrawningHoistingCrane gr.FillEllipse(brq, _startPosX.Value + 50, _startPosY.Value + 53, 10, 10); gr.FillRectangle(brq, _startPosX.Value + 30, _startPosY.Value + 45, 4, 6); gr.FillRectangle(brq, _startPosX.Value + 45, _startPosY.Value + 45, 4, 6); + + //противовес + if (EntityHoistingCrane.Counterweight) + { + Brush b = new SolidBrush(EntityHoistingCrane.AdditionalColor); + gr.FillRectangle(b, _startPosX.Value + 68, _startPosY.Value + 5, 10, 10); + } + + + //Наличие спусковой платформы + if (EntityHoistingCrane.Platform) + { + Pen n = new Pen(EntityHoistingCrane.AdditionalColor); + gr.DrawRectangle(pen, _startPosX.Value + 101, _startPosY.Value + 40, 15, 5); + } + } diff --git a/HoistingCrane/HoistingCrane/EntityHoistingCrane.cs b/HoistingCrane/HoistingCrane/EntityHoistingCrane.cs index 1be6030..3fce867 100644 --- a/HoistingCrane/HoistingCrane/EntityHoistingCrane.cs +++ b/HoistingCrane/HoistingCrane/EntityHoistingCrane.cs @@ -21,6 +21,19 @@ public class EntityHoistingCrane /// public Color AdditionalColor { get; private set; } + /// + /// + /// + public bool Counterweight { get; private set; } + /// + /// + /// + public bool Platform{ get; private set; } + + + /// + /// + /// public double Step => Speed * 100 / Weight; @@ -37,12 +50,14 @@ public class EntityHoistingCrane - public void Init(int Speed, double Weight, Color BodyColor, Color AdditionalColor) + public void Init(int Speed, double Weight, Color BodyColor, Color AdditionalColor, bool Counterweight, bool Platform) { this.Speed = Speed; this.Weight = Weight; this.BodyColor = BodyColor; this.AdditionalColor = AdditionalColor; + this.Counterweight = Counterweight; + this.Platform = Platform; } } \ No newline at end of file diff --git a/HoistingCrane/HoistingCrane/FormHoistingCrane.cs b/HoistingCrane/HoistingCrane/FormHoistingCrane.cs index 3bf841b..7250345 100644 --- a/HoistingCrane/HoistingCrane/FormHoistingCrane.cs +++ b/HoistingCrane/HoistingCrane/FormHoistingCrane.cs @@ -23,9 +23,14 @@ Random rand = new(); _drawningHoistingCrane = new DrawningHoistingCrane(); - _drawningHoistingCrane.Init(rand.Next(100, 300), rand.Next(1000, 3000), + _drawningHoistingCrane.Init( + rand.Next(100, 300), + rand.Next(1000, 3000), Color.FromArgb(rand.Next(0, 256), rand.Next(0, 256), rand.Next(0, 256)), - Color.FromArgb(rand.Next(0, 256), rand.Next(0, 256), rand.Next(0, 256))); + Color.FromArgb(rand.Next(0, 256), rand.Next(0, 256), rand.Next(0, 256)), + Convert.ToBoolean(rand.Next(0,2)), + Convert.ToBoolean(rand.Next(0,2)) + ); _drawningHoistingCrane.SetPictureSize(pictureBoxHoistingCrane.Width, pictureBoxHoistingCrane.Height); _drawningHoistingCrane.SetPosition(rand.Next(0, 100), rand.Next(0, 100)); Draw();