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