From 65dd5d529535f3d540fec7c2442f47571c4b3d54 Mon Sep 17 00:00:00 2001 From: PIBD14CHERTOVANDREY Date: Thu, 29 Feb 2024 09:46:34 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BB=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=201=20finish?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ProjectRoadTrain/DrawningRoadTrain.cs | 69 +++++++++++++------ 1 file changed, 48 insertions(+), 21 deletions(-) diff --git a/ProjectRoadTrain/ProjectRoadTrain/DrawningRoadTrain.cs b/ProjectRoadTrain/ProjectRoadTrain/DrawningRoadTrain.cs index 7ed02de..1b481d7 100644 --- a/ProjectRoadTrain/ProjectRoadTrain/DrawningRoadTrain.cs +++ b/ProjectRoadTrain/ProjectRoadTrain/DrawningRoadTrain.cs @@ -18,9 +18,9 @@ public class DrawningRoadTrain private int? _startPosY; - private readonly int _drawningRoadWidth = 270; + private readonly int _drawningRoadWidth = 230; - private readonly int _drawningRoadHeight = 120; + private readonly int _drawningRoadHeight = 115; public void Init(int speed, double weight, Color bodycolor, Color bodytankcolor, bool watertank, bool cleanbrush) { @@ -32,24 +32,51 @@ public class DrawningRoadTrain _startPosY = null; } - public bool SetPictureSize(int width, int height) + public bool SetPictureSize(int width, int hight) { - _pictureWidth = width; - _pictureHight = height; - return true; - } + if (width >= _drawningRoadWidth && hight >= _drawningRoadHeight) + { + _pictureWidth = width; + _pictureHight = hight; + if (_startPosX.HasValue && _startPosY.HasValue) + { + SetPosition(_startPosX.Value, _startPosY.Value); + } + return true; + } + + return false; + } public void SetPosition(int x, int y) { - if (!_pictureHight.HasValue || !_pictureWidth.HasValue) + if (!_pictureHight.HasValue || !_pictureWidth.HasValue) { return; } + + if (x < 0) + { + x = 0; + } + else if (x > _pictureWidth.Value - _drawningRoadWidth) + { + x = _pictureWidth.Value - _drawningRoadWidth; + } + + if (y < 0) + { + y = 0; + } + else if (y > _pictureHight.Value - _drawningRoadHeight) + { + y = _pictureHight.Value - _drawningRoadHeight; + } + _startPosX = x; _startPosY = y; } - public bool MoveTransport(DirectionType direction) { if (EntityRoadTrain == null || !_startPosX.HasValue || @@ -114,20 +141,20 @@ public class DrawningRoadTrain if (EntityRoadTrain.WaterTank || EntityRoadTrain.CleanBrush) { - g.FillRectangle(bodytankcolor, _startPosX.Value + 140, _startPosY.Value + 70, 100, 2); - g.FillRectangle(bodytankcolor, _startPosX.Value + 140, _startPosY.Value + 75, 100, 2); - g.FillRectangle(bodytankcolor, _startPosX.Value + 140, _startPosY.Value + 65, 100, 2); - g.FillEllipse(bodytankcolor, _startPosX.Value + 20, _startPosY.Value + 10, 100, 50); + g.FillRectangle(bodytankcolor, _startPosX.Value + 130, _startPosY.Value + 70, 100, 2); + g.FillRectangle(bodytankcolor, _startPosX.Value + 130, _startPosY.Value + 75, 100, 2); + g.FillRectangle(bodytankcolor, _startPosX.Value + 130, _startPosY.Value + 65, 100, 2); + g.FillEllipse(bodytankcolor, _startPosX.Value + 10, _startPosY.Value + 10, 100, 50); } - g.DrawRectangle(pen, _startPosX.Value + 20, _startPosY.Value + 60, 170, 20); - g.DrawRectangle(pen, _startPosX.Value + 140, _startPosY.Value, 50, 60); - g.DrawEllipse(pen, _startPosX.Value + 20, _startPosY.Value + 10, 100, 50); + g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + 60, 170, 20); + g.DrawRectangle(pen, _startPosX.Value + 120, _startPosY.Value, 50, 60); + g.DrawEllipse(pen, _startPosX.Value + 10, _startPosY.Value + 10, 100, 50); // 120 высота // 270 ширина - g.FillRectangle(blackcolor, _startPosX.Value + 20, _startPosY.Value + 60, 170, 20); - g.FillRectangle(bodycolor, _startPosX.Value + 140, _startPosY.Value, 50, 60); - g.FillEllipse(blackcolor, _startPosX.Value + 140, _startPosY.Value + 77, 48, 40); - g.FillEllipse(blackcolor, _startPosX.Value + 69, _startPosY.Value + 77, 48, 40); - g.FillEllipse(blackcolor, _startPosX.Value + 20, _startPosY.Value + 77, 48, 40); + g.FillRectangle(blackcolor, _startPosX.Value, _startPosY.Value + 60, 170, 20); + g.FillRectangle(bodycolor, _startPosX.Value + 120, _startPosY.Value, 50, 60); + g.FillEllipse(blackcolor, _startPosX.Value + 120, _startPosY.Value + 77, 48, 40); + g.FillEllipse(blackcolor, _startPosX.Value + 49, _startPosY.Value + 77, 48, 40); + g.FillEllipse(blackcolor, _startPosX.Value, _startPosY.Value + 77, 48, 40); } }