diff --git a/PrLaba1/PrLaba1/Drawnings/DrawningDiselLoko.cs b/PrLaba1/PrLaba1/Drawnings/DrawningDiselLoko.cs index a9b92a6..b6d776c 100644 --- a/PrLaba1/PrLaba1/Drawnings/DrawningDiselLoko.cs +++ b/PrLaba1/PrLaba1/Drawnings/DrawningDiselLoko.cs @@ -22,7 +22,6 @@ public class DrawningDiselLoko : DrawningLoko } - /// /// Прорисовка объекта /// @@ -36,6 +35,9 @@ public class DrawningDiselLoko : DrawningLoko Pen pen = new(Color.Black); Brush additionalBrush = new SolidBrush(diselLoko.ColorComportament); + Brush blackBrush = new SolidBrush(Color.Black); + + // труба if (diselLoko.IsTube) @@ -45,28 +47,26 @@ public class DrawningDiselLoko : DrawningLoko Point[] chimney = { new Point(_startPosX.Value + 20, _startPosY.Value - 20), new Point(_startPosX.Value + 35, _startPosY.Value - 20), - new Point(_startPosX.Value + 35, _startPosY.Value), - new Point(_startPosX.Value + 20, _startPosY.Value) + new Point(_startPosX.Value + 35, _startPosY.Value+5), + new Point(_startPosX.Value + 20, _startPosY.Value+5) }; + g.FillPolygon(blackBrush, chimney); g.DrawPolygon(pen, chimney); } - _startPosX += 10;//change - _startPosY += 5; base.DrawTransport(g); - _startPosX -= 10; - _startPosY -= 5; - + // отсек if (diselLoko.IsComportament) { //Топливный отсек(полигон) Point[] fuelTank = { - new Point(_startPosX.Value + 110, _startPosY.Value ), // Верхний левый угол - new Point(_startPosX.Value + 130, _startPosY.Value ), // Верхний правый угол - new Point(_startPosX.Value +130 , _startPosY.Value ), // Нижний правый угол - new Point(_startPosX.Value + 110, _startPosY.Value ) // Нижний левый угол + new Point(_startPosX.Value + 110, _startPosY.Value + GetHeight - 20 ), // Верхний левый угол + new Point(_startPosX.Value + 130, _startPosY.Value + GetHeight - 20 ), // Верхний правый угол + new Point(_startPosX.Value + 130, _startPosY.Value + GetHeight - 5 ), // Нижний правый угол + new Point(_startPosX.Value + 110, _startPosY.Value + GetHeight - 5 ) // Нижний левый угол }; + g.FillPolygon(additionalBrush, fuelTank); g.DrawPolygon(pen, fuelTank); } diff --git a/PrLaba1/PrLaba1/Drawnings/DrawningLoko.cs b/PrLaba1/PrLaba1/Drawnings/DrawningLoko.cs index 6c7b1d9..f690f8e 100644 --- a/PrLaba1/PrLaba1/Drawnings/DrawningLoko.cs +++ b/PrLaba1/PrLaba1/Drawnings/DrawningLoko.cs @@ -15,12 +15,12 @@ public class DrawningLoko /// ///Ширина окна /// - private int? _pictureWidth; + protected int? _pictureWidth; /// ///Высота окна /// - private int? _pictureHeight; + protected int? _pictureHeight; /// ///Левая координата прорисовки тепловоза @@ -35,27 +35,27 @@ public class DrawningLoko /// ///Ширина прорисовки тепловоза /// - private readonly int _drawingCarWidth = 140;//поменять + private readonly int _drawingCarWidth = 140; /// ///Высота прорисовки тепловоза /// - private readonly int _drawingCarHeight = 60;//поменять + private readonly int _drawingCarHeight = 60; /// ///Высота прорисовки тепловоза с трубой /// - private int _drawingCarHeightWithKit = 0; - - /// - ///Высота прорисовки тепловоза с трубой - /// - private int _WheelHeight = 25; + protected int _TubeHeight = 20; /// ///ширина вставки сбоку /// - private int _InsertWidth = 10; + protected int _InsertWidth = 10; + + /// + ///ширина вставки сбоку + /// + protected int _WheelHeight = 18; /// /// Координата X объекта @@ -77,16 +77,26 @@ public class DrawningLoko /// public int GetHeight => _drawingCarHeight; + /// + ///Высота прорисовки тепловоза с трубой + /// + public int GetWheelHeight => _TubeHeight; + + /// + ///ширина вставки сбоку + /// + public int GetInsertWidth => _InsertWidth; /// /// Пустой конструктор /// - private DrawningLoko() + public DrawningLoko() { _pictureWidth = null; _pictureHeight = null; _startPosX = null; _startPosY = null; + _InsertWidth = 10; } /// @@ -174,12 +184,12 @@ public class DrawningLoko { return false; } - + switch (direction) { //влево case Direction.Left: - if (_startPosX.Value - EntityLoko.Step > 0) + if (_startPosX.Value - EntityLoko.Step - _InsertWidth > 0) { _startPosX -= (int)EntityLoko.Step; } @@ -187,7 +197,7 @@ public class DrawningLoko //вверх case Direction.Up: - if (_startPosY.Value - _drawingCarHeightWithKit >= 0) + if (_startPosY.Value - EntityLoko.Step >= 0) { _startPosY = _startPosY - (int)EntityLoko.Step; } @@ -201,7 +211,7 @@ public class DrawningLoko return true; //вниз case Direction.Down: - if (_startPosY.Value + _WheelHeight + _drawingCarHeight < _pictureHeight.Value) + if (_startPosY.Value + _WheelHeight + _drawingCarHeight < _pictureHeight.Value) { _startPosY += (int)EntityLoko.Step; } diff --git a/PrLaba1/PrLaba1/Entities/DiselLoko.cs b/PrLaba1/PrLaba1/Entities/DiselLoko.cs index 83bc9bf..21ad352 100644 --- a/PrLaba1/PrLaba1/Entities/DiselLoko.cs +++ b/PrLaba1/PrLaba1/Entities/DiselLoko.cs @@ -24,7 +24,7 @@ public class DiselLoko : EntityLoko /// цвет отсека /// признак наличия трубы /// признак наличия отсека - public DiselLoko(int speed, double weight, Color bodyColor, Color Comportament, bool isTube, bool isComportament) : base(0, 0, Color.Black) + public DiselLoko(int speed, double weight, Color bodyColor, Color Comportament, bool isTube, bool isComportament) : base(speed, weight, bodyColor) { ColorComportament = Comportament; IsTube = isTube; diff --git a/PrLaba1/PrLaba1/MovementStrategy/MoveToBoarder.cs b/PrLaba1/PrLaba1/MovementStrategy/MoveToBoarder.cs index 2e0866d..75e94d8 100644 --- a/PrLaba1/PrLaba1/MovementStrategy/MoveToBoarder.cs +++ b/PrLaba1/PrLaba1/MovementStrategy/MoveToBoarder.cs @@ -4,11 +4,49 @@ public class MoveToBoarder : AbstractStrategy { protected override bool IsTargetDestinaion() { - throw new NotImplementedException(); + ObjectParameters? objParams = GetObjectParameters; + if (objParams == null) + { + return false; + } + + return objParams.RightBorder + GetStep() >= FieldWidth && + objParams.DownBorder + GetStep() >= FieldHeight ; } protected override void MoveToTarget() { - throw new NotImplementedException(); + ObjectParameters? objParams = GetObjectParameters; + if (objParams == null) + { + return; + } + + int diffX = objParams.RightBorder - FieldWidth; + if (Math.Abs(diffX) > GetStep()) + { + if (diffX > 0) + { + MoveLeft(); + } + else + { + MoveRight(); + } + } + + int diffY = objParams.DownBorder - FieldHeight; + if (Math.Abs(diffY) > GetStep()) + { + if (diffY > 0) + { + MoveUp(); + } + else + { + MoveDown(); + } + } } } + diff --git a/PrLaba1/PrLaba1/MovementStrategy/MoveableLoko.cs b/PrLaba1/PrLaba1/MovementStrategy/MoveableLoko.cs index 4180b1f..cfa9867 100644 --- a/PrLaba1/PrLaba1/MovementStrategy/MoveableLoko.cs +++ b/PrLaba1/PrLaba1/MovementStrategy/MoveableLoko.cs @@ -14,12 +14,13 @@ public class MoveableLoko : IMoveableObject /// /// Конструктор /// - /// Объект класса DrawningCar + /// Объект класса DrawningLoko public MoveableLoko(DrawningLoko loko) { _loko = loko; } + public ObjectParameters? GetObjectPosition { get diff --git a/PrLaba1/PrLaba1/MovementStrategy/ObjectParameters.cs b/PrLaba1/PrLaba1/MovementStrategy/ObjectParameters.cs index be06eac..c6a544d 100644 --- a/PrLaba1/PrLaba1/MovementStrategy/ObjectParameters.cs +++ b/PrLaba1/PrLaba1/MovementStrategy/ObjectParameters.cs @@ -5,6 +5,17 @@ /// public class ObjectParameters { + + /// + /// Длина колеса + /// + private readonly int _wheelHeight = 18; + + /// + /// Ширина вставки сзади + /// + private readonly int _insertWidth = 10; + /// /// Координата X /// @@ -38,12 +49,12 @@ public class ObjectParameters /// /// Правая граница /// - public int RightBorder => _x + _width; + public int RightBorder => _x + _width + _insertWidth; /// /// Нижняя граница /// - public int DownBorder => _y + _height; + public int DownBorder => _y + _height + _wheelHeight; /// /// Середина объекта