From da86c334a4c094cb074896963d62d4c9c0aa91ab Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Sun, 25 Sep 2022 15:50:46 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D1=85=D0=BE=D0=B4=20?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=BA=D0=BE=D0=BD=D1=81=D1=82=D1=80=D1=83=D0=BA?= =?UTF-8?q?=D1=82=D0=BE=D1=80=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Locomotive/Locomotive/DrawningLocomotive.cs | 5 ++--- Locomotive/Locomotive/EntityLocomotive.cs | 2 +- Locomotive/Locomotive/FormLocomotive.cs | 5 +---- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/Locomotive/Locomotive/DrawningLocomotive.cs b/Locomotive/Locomotive/DrawningLocomotive.cs index 7d8650e..e7c864b 100644 --- a/Locomotive/Locomotive/DrawningLocomotive.cs +++ b/Locomotive/Locomotive/DrawningLocomotive.cs @@ -25,10 +25,9 @@ namespace Locomotive private readonly int _locomotiveHeight = 50; /// Инициализация свойств - public void Init(int speed, float weight, Color bodyColor, EntityLocomotive entity) + public DrawningLocomotive(int speed, float weight, Color bodyColor) { - Locomotive = entity; - Locomotive.Init(speed, weight, bodyColor); + Locomotive = new EntityLocomotive(speed, weight, bodyColor); } /// Установка позиции локомотива public void SetPosition(int x, int y, int width, int height) diff --git a/Locomotive/Locomotive/EntityLocomotive.cs b/Locomotive/Locomotive/EntityLocomotive.cs index 1e407d0..a546746 100644 --- a/Locomotive/Locomotive/EntityLocomotive.cs +++ b/Locomotive/Locomotive/EntityLocomotive.cs @@ -17,7 +17,7 @@ namespace Locomotive /// Шаг перемещения локомотива public float Step => Speed * 100 / Weight; - public void Init(int speed, float weight, Color bodyColor) + public EntityLocomotive(int speed, float weight, Color bodyColor) { Random rnd = new(); Speed = speed <= 0 ? rnd.Next(50, 150) : speed; diff --git a/Locomotive/Locomotive/FormLocomotive.cs b/Locomotive/Locomotive/FormLocomotive.cs index 211a8a6..cb904e7 100644 --- a/Locomotive/Locomotive/FormLocomotive.cs +++ b/Locomotive/Locomotive/FormLocomotive.cs @@ -3,7 +3,6 @@ namespace Locomotive public partial class FormLocomotive : Form { private DrawningLocomotive _locomotive; - private EntityLocomotive _entity; public FormLocomotive() { @@ -22,9 +21,7 @@ namespace Locomotive private void buttonCreate_Click(object sender, EventArgs e) { Random rnd = new(); - _locomotive = new DrawningLocomotive(); - _entity = new EntityLocomotive(); - _locomotive.Init(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), _entity); + _locomotive = new DrawningLocomotive(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); _locomotive.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxLocomotive.Width, pictureBoxLocomotive.Height); toolStripStatusLabelSpeed.Text = $"Speed: {_locomotive.Locomotive.Speed}"; toolStripStatusLabelWeight.Text = $"Weight: {_locomotive.Locomotive.Weight}";