From d1f9a5eead22ee368af8d82286ccda4ab6000de9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=B3=D0=BE=D1=80=D1=8C=20=D0=93=D0=BE=D1=80=D0=B4?= =?UTF-8?q?=D0=B5=D0=B5=D0=B2?= <89176335310x@gmail.com> Date: Fri, 6 Oct 2023 12:54:51 +0400 Subject: [PATCH] Sdano --- .../DrawningElectricLocomotive.cs | 102 +++++++++--------- .../ElectricLocomotive/ElectricLocomotive.cs | 4 +- .../EntityElectricLocomotive.cs | 43 ++++++-- 3 files changed, 89 insertions(+), 60 deletions(-) diff --git a/ElectricLocomotive/ElectricLocomotive/DrawningElectricLocomotive.cs b/ElectricLocomotive/ElectricLocomotive/DrawningElectricLocomotive.cs index 6c76064..5ea4c7c 100644 --- a/ElectricLocomotive/ElectricLocomotive/DrawningElectricLocomotive.cs +++ b/ElectricLocomotive/ElectricLocomotive/DrawningElectricLocomotive.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Drawing; using System.Linq; +using System.Net.NetworkInformation; using System.Text; using System.Threading.Tasks; using System.Windows.Forms.VisualStyles; @@ -10,35 +11,38 @@ namespace ElectricLocomotive { public class DrawningElectricLocomotive { - private EntityElectricLocomotive enitity_electric_locomotive = new EntityElectricLocomotive(); + public EntityElectricLocomotive? _ElectricLocomotive { get; private set; } + + private int _pictureWidth; + + private int _pictureHeight; private int _startPosX; private int _startPosY; - private const int _LengthLocomotive = 120; + private readonly int _LocomotiveWidth = 100; - private const int _HeightLocomorive=90; + private readonly int _LocomoriveHeight =50; - public bool Init(int speed, double weight, Color bodyColor, Color additionalColor) + public bool Init(int speed, double weight, Color bodyColor, Color additionalColor, bool horns, int width, int height) { - if (speed < 0 || bodyColor == additionalColor) + _pictureWidth = width; + _pictureHeight = height; + if ((_pictureHeight < _LocomoriveHeight) || (_pictureWidth < _LocomotiveWidth)) { return false; } - else - { - enitity_electric_locomotive.Init(speed, weight, bodyColor, additionalColor); - - return true; - } + _ElectricLocomotive = new EntityElectricLocomotive(); + _ElectricLocomotive.Init(speed, weight, bodyColor, additionalColor, horns); + return true; } public void SetPosition(int x, int y) { - if (x < 0 || y < 0 || x + _LengthLocomotive > ElectricLocomotive.ActiveForm.Size.Width || y + _HeightLocomorive > ElectricLocomotive.ActiveForm.Size.Height) + if (x < 0 || y < 0 || x + _LocomotiveWidth > _pictureWidth || y + _LocomoriveHeight > _pictureHeight) { return ; } @@ -52,7 +56,7 @@ namespace ElectricLocomotive public void MoveTransport(DirectionType direction) { - if (enitity_electric_locomotive == null) + if (_ElectricLocomotive == null) { return; } @@ -61,33 +65,33 @@ namespace ElectricLocomotive { //влево case DirectionType.Left: - if (_startPosX - enitity_electric_locomotive.Step > 0) + if (_startPosX - _ElectricLocomotive.Step > 0) { - _startPosX -= (int)enitity_electric_locomotive.Step; + _startPosX -= (int)_ElectricLocomotive.Step; } break; //вверх case DirectionType.Up: - if (_startPosY - enitity_electric_locomotive.Step > 0) + if (_startPosY - _ElectricLocomotive.Step > 0) { - _startPosY -= (int)enitity_electric_locomotive.Step; + _startPosY -= (int)_ElectricLocomotive.Step; } break; // вправо case DirectionType.Right: // TODO: Продумать логику - if (_startPosX+_LengthLocomotive+(int)enitity_electric_locomotive.Step < ElectricLocomotive.ActiveForm.Size.Width) + if (_startPosX+ _LocomotiveWidth + (int)_ElectricLocomotive.Step < _pictureWidth) { - _startPosX += (int)enitity_electric_locomotive.Step; + _startPosX += (int)_ElectricLocomotive.Step; } break; //вниз case DirectionType.Down: // TODO: Продумать логику - if (_startPosY + _HeightLocomorive + (int)enitity_electric_locomotive.Step < ElectricLocomotive.ActiveForm.Size.Height) + if (_startPosY + _LocomoriveHeight + (int)_ElectricLocomotive.Step < _pictureHeight) { - _startPosY += (int)enitity_electric_locomotive.Step; + _startPosY += (int)_ElectricLocomotive.Step; } break; } @@ -98,13 +102,13 @@ namespace ElectricLocomotive public void DrawTransport(Graphics g) { - if (enitity_electric_locomotive == null) + if (_ElectricLocomotive == null) { return; } - Pen pen = new(enitity_electric_locomotive.AdditionalColor); - Brush brush = new SolidBrush(enitity_electric_locomotive.BodyColor); + Pen pen = new(_ElectricLocomotive.AdditionalColor); + Brush brush = new SolidBrush(_ElectricLocomotive.BodyColor); ///ВЛ60к-1595 @@ -165,33 +169,35 @@ namespace ElectricLocomotive g.FillRectangle(brush, _startPosX + 50, _startPosY + 15, 10, 25); ///рога - g.FillRectangle(brush, _startPosX + 25, _startPosY + 5, 15, 5); - - Point[] horns = + if (_ElectricLocomotive.Horns == true) { - new Point(_startPosX+25, _startPosY+10), - new Point(_startPosX+25, _startPosY+5), - new Point(_startPosX+33,_startPosY+5), - new Point(_startPosX+50, _startPosY), - new Point(_startPosX+33,_startPosY+5), - new Point(_startPosX+40,_startPosY+5), - new Point(_startPosX+40,_startPosY+10) - }; - g.DrawPolygon(pen, horns); + g.FillRectangle(brush, _startPosX + 25, _startPosY + 5, 15, 5); - g.FillRectangle(brush, _startPosX + 65, _startPosY + 5, 15, 5); - Point[] horns2 = - { - new Point(_startPosX+65, _startPosY+10), - new Point(_startPosX+65, _startPosY+5), - new Point(_startPosX+73,_startPosY+5), - new Point(_startPosX+90, _startPosY), - new Point(_startPosX+73,_startPosY+5), - new Point(_startPosX+80,_startPosY+5), - new Point(_startPosX+80,_startPosY+10) - }; - g.DrawPolygon(pen, horns2); + Point[] horns = + { + new Point(_startPosX+25, _startPosY+10), + new Point(_startPosX+25, _startPosY+5), + new Point(_startPosX+33,_startPosY+5), + new Point(_startPosX+50, _startPosY), + new Point(_startPosX+33,_startPosY+5), + new Point(_startPosX+40,_startPosY+5), + new Point(_startPosX+40,_startPosY+10) + }; + g.DrawPolygon(pen, horns); + g.FillRectangle(brush, _startPosX + 65, _startPosY + 5, 15, 5); + Point[] horns2 = + { + new Point(_startPosX+65, _startPosY+10), + new Point(_startPosX+65, _startPosY+5), + new Point(_startPosX+73,_startPosY+5), + new Point(_startPosX+90, _startPosY), + new Point(_startPosX+73,_startPosY+5), + new Point(_startPosX+80,_startPosY+5), + new Point(_startPosX+80,_startPosY+10) + }; + g.DrawPolygon(pen, horns2); + } ///Батарея g.FillRectangle(brush, _startPosX + 45, _startPosY + 5, 15, 5); diff --git a/ElectricLocomotive/ElectricLocomotive/ElectricLocomotive.cs b/ElectricLocomotive/ElectricLocomotive/ElectricLocomotive.cs index 360e4bd..744b4dc 100644 --- a/ElectricLocomotive/ElectricLocomotive/ElectricLocomotive.cs +++ b/ElectricLocomotive/ElectricLocomotive/ElectricLocomotive.cs @@ -28,7 +28,9 @@ namespace ElectricLocomotive _drawningElectricLocomotive = new DrawningElectricLocomotive(); _drawningElectricLocomotive.Init(random.Next(100, 300), random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), - Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256))); + Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), + Convert.ToBoolean(random.Next(0, 2)), pictureBoxElectroLocomotiv.Width, pictureBoxElectroLocomotiv.Height); + _drawningElectricLocomotive.SetPosition(random.Next(10, 100), random.Next(10, 100)); Draw(); diff --git a/ElectricLocomotive/ElectricLocomotive/EntityElectricLocomotive.cs b/ElectricLocomotive/ElectricLocomotive/EntityElectricLocomotive.cs index 6e42320..779c84e 100644 --- a/ElectricLocomotive/ElectricLocomotive/EntityElectricLocomotive.cs +++ b/ElectricLocomotive/ElectricLocomotive/EntityElectricLocomotive.cs @@ -8,28 +8,49 @@ namespace ElectricLocomotive { public class EntityElectricLocomotive { - + /// + /// Скорость + /// public int Speed { get; private set; } - + /// + /// Вес + /// public double Weight { get; private set; } - + /// + /// Основной цвет + /// public Color BodyColor { get; private set; } - + /// + /// Дополнительный цвет (для опциональных элементов) + /// public Color AdditionalColor { get; private set; } + /// + /// Признак (опция) наличия обвеса + /// + public bool Horns { get; private set; } + /// + /// Признак (опция) roga + /// - public double Step => (double)Speed * 100 / Weight; + public double Step => (double)Speed * 100 / Weight; ///свойство с лямбда выражением + /// + /// Инициализация полей объекта-класса электролокоматива + /// + /// Скорость + /// Вес + /// Основной цвет + /// Дополнительный цвет + /// Признак наличия рогов - public void Init(int speed, double weight, Color bodyColor, Color additionalColor) + public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool horns) { - Speed = speed; - Weight = weight; - BodyColor = bodyColor; - AdditionalColor = additionalColor; - + Horns = horns; } } + } +