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

This commit is contained in:
Sem730 2022-09-26 22:25:23 +03:00
parent d9ad3e29c2
commit 5669b4e535
3 changed files with 4 additions and 6 deletions

View File

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

View File

@ -31,7 +31,7 @@ namespace ProjectLocomotive
/// <param name="weight"></param>
/// <param name="bodyColor"></param>
/// <returns></returns>
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;

View File

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