diff --git a/AirplaneWithRadar/ProjectAirplaneWithRadar/DirectionType.cs b/AirplaneWithRadar/ProjectAirplaneWithRadar/Drawnings/DirectionType.cs similarity index 90% rename from AirplaneWithRadar/ProjectAirplaneWithRadar/DirectionType.cs rename to AirplaneWithRadar/ProjectAirplaneWithRadar/Drawnings/DirectionType.cs index 46519a9..65cc84f 100644 --- a/AirplaneWithRadar/ProjectAirplaneWithRadar/DirectionType.cs +++ b/AirplaneWithRadar/ProjectAirplaneWithRadar/Drawnings/DirectionType.cs @@ -1,5 +1,4 @@ - -namespace ProjectAirplaneWithRadar +namespace ProjectAirplaneWithRadar.Drawnings { /// /// Направление перемещения diff --git a/AirplaneWithRadar/ProjectAirplaneWithRadar/Drawnings/DrawingAirplaneWithRadar.cs b/AirplaneWithRadar/ProjectAirplaneWithRadar/Drawnings/DrawingAirplaneWithRadar.cs new file mode 100644 index 0000000..8ba2e38 --- /dev/null +++ b/AirplaneWithRadar/ProjectAirplaneWithRadar/Drawnings/DrawingAirplaneWithRadar.cs @@ -0,0 +1,75 @@ +using ProjectAirplaneWithRadar.Entities; + +namespace ProjectAirplaneWithRadar.Drawnings +{ + /// + /// Класс, отвечающий за прорисовку и перемещение объекта-сущности + /// + public class DrawingAirplaneWithRadar : DrawningAirplane + { + /// + /// Инициализация свойств + /// + /// Скорость + /// Вес + /// Основной цвет + /// Дополнительный цвет + /// Шасси + /// Радар + public DrawingAirplaneWithRadar(int speed, double weight, Color bodyColor, Color additionalColor, bool wheels, bool radar) : base(150, 93) + { + EntityAirplane = new EntityAirplaneWithRadar(speed, weight, bodyColor, additionalColor, wheels, radar); + } + + /// + /// Прорисовка объекта + /// + /// + public override void DrawTransport(Graphics g) + { + if (EntityAirplane == null || EntityAirplane is not EntityAirplaneWithRadar airplaneWithRadar || !_startPosX.HasValue || !_startPosY.HasValue) + { + return; + } + + Pen pen = new(Color.Black); + Brush additionalBrush = new SolidBrush(airplaneWithRadar.AdditionalColor); + + if (airplaneWithRadar.Wheels) + { + //Задняя стойка + g.DrawRectangle(pen, _startPosX.Value + 30, _startPosY.Value + 80, 5, 10); + g.FillRectangle(additionalBrush, _startPosX.Value + 30, _startPosY.Value + 80, 5, 10); + + g.DrawEllipse(pen, _startPosX.Value + 20, _startPosY.Value + 85, 10, 10); + g.FillEllipse(additionalBrush, _startPosX.Value + 20, _startPosY.Value + 85, 10, 10); + + g.DrawEllipse(pen, _startPosX.Value + 35, _startPosY.Value + 85, 10, 10); + g.FillEllipse(additionalBrush, _startPosX.Value + 35, _startPosY.Value + 85, 10, 10); + + //Передняя стойка + g.DrawRectangle(pen, _startPosX.Value + 95, _startPosY.Value + 80, 5, 10); + g.FillRectangle(additionalBrush, _startPosX.Value + 95, _startPosY.Value + 80, 5, 10); + + g.DrawEllipse(pen, _startPosX.Value + 92, _startPosY.Value + 85, 10, 10); + g.FillEllipse(additionalBrush, _startPosX.Value + 92, _startPosY.Value + 85, 10, 10); + } + + _startPosY += 10; + base.DrawTransport(g); + _startPosY -= 10; + + + //Радар + if (airplaneWithRadar.Radar) + { + g.DrawRectangle(pen, _startPosX.Value + 70, _startPosY.Value + 40, 10, 10); + g.FillRectangle(additionalBrush, _startPosX.Value + 70, _startPosY.Value + 40, 10, 10); + + g.DrawEllipse(pen, _startPosX.Value + 50, _startPosY.Value + 30, 50, 10); + g.FillEllipse(additionalBrush, _startPosX.Value + 50, _startPosY.Value + 30, 50, 10); + } + + } + } +} \ No newline at end of file diff --git a/AirplaneWithRadar/ProjectAirplaneWithRadar/DrawingAirplaneWithRadar.cs b/AirplaneWithRadar/ProjectAirplaneWithRadar/Drawnings/DrawningAirplane.cs similarity index 66% rename from AirplaneWithRadar/ProjectAirplaneWithRadar/DrawingAirplaneWithRadar.cs rename to AirplaneWithRadar/ProjectAirplaneWithRadar/Drawnings/DrawningAirplane.cs index 36f61b6..63981d4 100644 --- a/AirplaneWithRadar/ProjectAirplaneWithRadar/DrawingAirplaneWithRadar.cs +++ b/AirplaneWithRadar/ProjectAirplaneWithRadar/Drawnings/DrawningAirplane.cs @@ -1,14 +1,15 @@ -namespace ProjectAirplaneWithRadar.Entities +using ProjectAirplaneWithRadar.Entities; + + +namespace ProjectAirplaneWithRadar.Drawnings { - /// - /// Класс, отвечающий за прорисовку и перемещение объекта-сущности - /// - public class DrawingAirplaneWithRadar + public class DrawningAirplane { + /// /// Класс-сущность /// - public EntityAirplaneWithRadar? EntityAirplaneWithRadar { get; private set; } + public EntityAirplane? EntityAirplane { get; protected set; } /// /// Ширина окна @@ -23,43 +24,76 @@ /// /// Левая координата прорисовки /// - private int? _startPosX; + protected int? _startPosX; /// /// Верхняя кооридната прорисовки /// - private int? _startPosY; + protected int? _startPosY; /// /// Ширина прорисовки самолета /// - public readonly int PlaneWidth = 150; + private readonly int PlaneWidth = 150; /// /// Высота прорисовки самолета /// - public readonly int PlaneHeight = 95; - + private readonly int PlaneHeight = 85; /// - /// Инициализация свойств + /// Координата X объекта /// - /// Скорость - /// Вес - /// Основной цвет - /// Дополнительный цвет - /// Шасси - /// Радар - public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool wheels, bool radar) + public int? GetPosX => _startPosX; + + /// + /// Координата Y объекта + /// + public int? GetPosY => _startPosY; + + /// + /// Ширина объекта + /// + public int GetWidth => PlaneWidth; + + /// + /// Высота объекта + /// + public int GetHeight => PlaneHeight; + + /// + /// Пустой конструктор + /// + private DrawningAirplane() { - EntityAirplaneWithRadar = new EntityAirplaneWithRadar(); - EntityAirplaneWithRadar.Init(speed, weight, bodyColor, additionalColor, wheels, radar); _pictureWidth = null; _pictureHeight = null; _startPosX = null; _startPosY = null; } + /// + /// Конструктор + /// + /// Скорость + /// Вес + /// Основной цвет + public DrawningAirplane(int speed, double weight, Color bodyColor) : this() + { + EntityAirplane = new EntityAirplane(speed, weight, bodyColor); + } + + /// + /// Конструктор для наследников + /// + /// Ширина прорисовки самолета + /// Высота прорисовки самолета + protected DrawningAirplane(int planeWidth, int planeHeight) : this() + { + PlaneWidth = planeWidth; + PlaneHeight = planeHeight; + } + /// /// Установка границ поля /// @@ -138,12 +172,12 @@ /// true - перемещене выполнено, false - перемещение невозможно public bool MoveTransport(DirectionType direction) { - if (EntityAirplaneWithRadar == null || !_startPosX.HasValue || !_startPosY.HasValue) + if (EntityAirplane == null || !_startPosX.HasValue || !_startPosY.HasValue) { return false; } - int step = (int)EntityAirplaneWithRadar.Step; + int step = (int)EntityAirplane.Step; switch (direction) { //влево @@ -184,82 +218,51 @@ /// Прорисовка объекта /// /// - public void DrawTransport(Graphics g) + public virtual void DrawTransport(Graphics g) { - if (EntityAirplaneWithRadar == null || !_startPosX.HasValue || !_startPosY.HasValue) + if (EntityAirplane == null || !_startPosX.HasValue || !_startPosY.HasValue) { return; } Pen pen = new(Color.Black); - Brush additionalBrush = new SolidBrush(EntityAirplaneWithRadar.AdditionalColor); - //Шасси - if (EntityAirplaneWithRadar.Wheels) - { - //Задняя стойка - g.DrawRectangle(pen, _startPosX.Value + 30, _startPosY.Value + 80, 5, 10); - g.FillRectangle(additionalBrush, _startPosX.Value + 30, _startPosY.Value + 80, 5, 10); - - g.DrawEllipse(pen, _startPosX.Value + 20, _startPosY.Value + 85, 10, 10); - g.FillEllipse(additionalBrush, _startPosX.Value + 20, _startPosY.Value + 85, 10, 10); - - g.DrawEllipse(pen, _startPosX.Value + 35, _startPosY.Value + 85, 10, 10); - g.FillEllipse(additionalBrush, _startPosX.Value + 35, _startPosY.Value + 85, 10, 10); - - //Передняя стойка - g.DrawRectangle(pen, _startPosX.Value + 95, _startPosY.Value + 80, 5, 10); - g.FillRectangle(additionalBrush, _startPosX.Value + 95, _startPosY.Value + 80, 5, 10); - - g.DrawEllipse(pen, _startPosX.Value + 92, _startPosY.Value + 85, 10, 10); - g.FillEllipse(additionalBrush, _startPosX.Value + 92, _startPosY.Value + 85, 10, 10); - } - - //Радар - if (EntityAirplaneWithRadar.Radar) - { - g.DrawRectangle(pen, _startPosX.Value + 70, _startPosY.Value + 40, 10, 10); - g.FillRectangle(additionalBrush, _startPosX.Value + 70, _startPosY.Value + 40, 10, 10); - - g.DrawEllipse(pen, _startPosX.Value + 50, _startPosY.Value + 30, 50, 10); - g.FillEllipse(additionalBrush, _startPosX.Value + 50, _startPosY.Value + 30, 50, 10); - } //Корпус - g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 50, 100, 30); + g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 40, 100, 30); //Хвост Point[] points = { - new Point(_startPosX.Value + 10, _startPosY.Value + 10), - new Point(_startPosX.Value + 10, _startPosY.Value + 50), - new Point(_startPosX.Value + 50, _startPosY.Value + 50) + new Point(_startPosX.Value + 10, _startPosY.Value), + new Point(_startPosX.Value + 10, _startPosY.Value + 40), + new Point(_startPosX.Value + 50, _startPosY.Value + 40) }; g.DrawPolygon(pen, points); //Кабина Point[] points2 = { - new Point(_startPosX.Value + 110, _startPosY.Value + 45), - new Point(_startPosX.Value + 110, _startPosY.Value + 65), - new Point(_startPosX.Value + 150, _startPosY.Value + 65) + new Point(_startPosX.Value + 110, _startPosY.Value + 35), + new Point(_startPosX.Value + 110, _startPosY.Value + 55), + new Point(_startPosX.Value + 150, _startPosY.Value + 55) }; g.DrawPolygon(pen, points2); Point[] points3 = { - new Point(_startPosX.Value + 110, _startPosY.Value + 65), - new Point(_startPosX.Value + 110, _startPosY.Value + 85), - new Point(_startPosX.Value + 150, _startPosY.Value + 65) + new Point(_startPosX.Value + 110, _startPosY.Value + 55), + new Point(_startPosX.Value + 110, _startPosY.Value + 75), + new Point(_startPosX.Value + 150, _startPosY.Value + 55) }; g.DrawPolygon(pen, points3); //Крыло - Brush brBlack = new SolidBrush(Color.Black); - g.DrawEllipse(pen, _startPosX.Value + 30, _startPosY.Value + 60, 70, 10); - g.FillEllipse(brBlack, _startPosX.Value + 30, _startPosY.Value + 60, 70, 10); + Brush brBlack = new SolidBrush(EntityAirplane.BodyColor); + g.DrawEllipse(pen, _startPosX.Value + 30, _startPosY.Value + 50, 70, 10); + g.FillEllipse(brBlack, _startPosX.Value + 30, _startPosY.Value + 50, 70, 10); //Хвостовой элерон - g.DrawEllipse(pen, _startPosX.Value, _startPosY.Value + 45, 30, 10); - g.FillEllipse(brBlack, _startPosX.Value, _startPosY.Value + 45, 30, 10); + g.DrawEllipse(pen, _startPosX.Value, _startPosY.Value + 35, 30, 10); + g.FillEllipse(brBlack, _startPosX.Value, _startPosY.Value + 35, 30, 10); } } -} +} \ No newline at end of file diff --git a/AirplaneWithRadar/ProjectAirplaneWithRadar/Entities/EntityAirplane.cs b/AirplaneWithRadar/ProjectAirplaneWithRadar/Entities/EntityAirplane.cs index 868b609..6abeb89 100644 --- a/AirplaneWithRadar/ProjectAirplaneWithRadar/Entities/EntityAirplane.cs +++ b/AirplaneWithRadar/ProjectAirplaneWithRadar/Entities/EntityAirplane.cs @@ -1,11 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using static System.Windows.Forms.VisualStyles.VisualStyleElement; - -namespace ProjectAirplaneWithRadar.Entities +namespace ProjectAirplaneWithRadar.Entities { /// /// Класс-сущность "Самолет" diff --git a/AirplaneWithRadar/ProjectAirplaneWithRadar/FormAirplaneWithRadar.cs b/AirplaneWithRadar/ProjectAirplaneWithRadar/FormAirplaneWithRadar.cs index 2b353ba..c399391 100644 --- a/AirplaneWithRadar/ProjectAirplaneWithRadar/FormAirplaneWithRadar.cs +++ b/AirplaneWithRadar/ProjectAirplaneWithRadar/FormAirplaneWithRadar.cs @@ -1,4 +1,5 @@ -using ProjectAirplaneWithRadar.Entities; +using ProjectAirplaneWithRadar.Drawnings; +using ProjectAirplaneWithRadar.Entities; namespace ProjectAirplaneWithRadar {