Переход на конструкторы

This commit is contained in:
evasina2312@gmail.com 2022-09-29 14:44:15 +04:00
parent 8faf79a407
commit c2213d181e
3 changed files with 4 additions and 6 deletions

View File

@ -45,10 +45,9 @@ namespace ProjectMachine
/// <param name="speed">Скорость</param> /// <param name="speed">Скорость</param>
/// <param name="weight">Вес автомобиля</param> /// <param name="weight">Вес автомобиля</param>
/// <param name="bodyColor">Цвет кузова</param> /// <param name="bodyColor">Цвет кузова</param>
public void Init(int speed, float weight, Color bodyColor) public DrawningMachine(int speed, float weight, Color bodyColor)
{ {
Machine = new EntityMachine(); Machine = new EntityMachine(speed, weight, bodyColor);
Machine.Init(speed, weight, bodyColor);
} }
/// <summary> /// <summary>
/// Установка позиции машины /// Установка позиции машины

View File

@ -34,7 +34,7 @@ namespace ProjectMachine
/// <param name="weight"></param> /// <param name="weight"></param>
/// <param name="bodyColor"></param> /// <param name="bodyColor"></param>
/// <returns></returns> /// <returns></returns>
public void Init(int speed, float weight, Color bodyColor) public EntityMachine(int speed, float weight, Color bodyColor)
{ {
Random rnd = new(); Random rnd = new();
Speed = speed <= 0 ? rnd.Next(50, 150) : speed; Speed = speed <= 0 ? rnd.Next(50, 150) : speed;

View File

@ -26,8 +26,7 @@ namespace ProjectMachine
private void ButtonCreate_Click(object sender, EventArgs e) private void ButtonCreate_Click(object sender, EventArgs e)
{ {
Random rnd = new(); Random rnd = new();
_machine = new DrawningMachine(); _machine = new DrawningMachine(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
_machine.Init(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
_machine.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxMachine.Width, pictureBoxMachine.Height); _machine.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxMachine.Width, pictureBoxMachine.Height);
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_machine.Machine.Speed}"; toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_machine.Machine.Speed}";
toolStripStatusLabelWeight.Text = $"Âåñ: {_machine.Machine.Weight}"; toolStripStatusLabelWeight.Text = $"Âåñ: {_machine.Machine.Weight}";