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

This commit is contained in:
Danil Malin 2022-09-23 18:29:37 +04:00
parent 747b5c1c87
commit f9ff52e57b
3 changed files with 4 additions and 6 deletions

View File

@ -45,10 +45,9 @@ namespace WarmlyLocomotive
/// <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 DrawningLocomotive(int speed, float weight, Color bodyColor)
{ {
Locomotive = new EntityLocomotive(); Locomotive = new EntityLocomotive(speed, weight, bodyColor);
Locomotive.Init(speed, weight, bodyColor);
} }
/// <summary> /// <summary>
/// Установка позиции локомотива /// Установка позиции локомотива

View File

@ -31,7 +31,7 @@ namespace WarmlyLocomotive
/// <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 EntityLocomotive(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

@ -25,8 +25,7 @@ namespace WarmlyLocomotive
private void ButtonCreate_Click(object sender, EventArgs e) private void ButtonCreate_Click(object sender, EventArgs e)
{ {
Random rnd = new(); Random rnd = new();
_locomotive = new DrawningLocomotive(); _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.Init(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); _locomotive.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxLocomotive.Width, pictureBoxLocomotive.Height);
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_locomotive.Locomotive.Speed}"; toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_locomotive.Locomotive.Speed}";
toolStripStatusLabelWeight.Text = $"Âåñ: {_locomotive.Locomotive.Weight}"; toolStripStatusLabelWeight.Text = $"Âåñ: {_locomotive.Locomotive.Weight}";