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); } }