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

This commit is contained in:
ityurner02@mail.ru 2022-09-17 17:17:24 +04:00
parent 62e0ec9148
commit 001cdd770b
3 changed files with 4 additions and 6 deletions

View File

@ -45,10 +45,9 @@ namespace AntiAircraftGun
/// <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 DrawingAntiAircraftGun(int speed, float weight, Color bodyColor)
{ {
AntiAircraftGun = new EntityAntiAircraftGun(); AntiAircraftGun = new EntityAntiAircraftGun(speed, weight, bodyColor);
AntiAircraftGun.Init(speed, weight, bodyColor);
} }
/// <summary> /// <summary>
/// Установка позиции зенитного орудия /// Установка позиции зенитного орудия

View File

@ -31,7 +31,7 @@ namespace AntiAircraftGun
/// <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 EntityAntiAircraftGun(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

@ -32,8 +32,7 @@ namespace AntiAircraftGun
private void ButtonCreate_Click(object sender, EventArgs e) private void ButtonCreate_Click(object sender, EventArgs e)
{ {
Random rnd = new(); Random rnd = new();
_antiAircrafGun = new DrawingAntiAircraftGun(); _antiAircrafGun = new DrawingAntiAircraftGun(rnd.Next(100, 300), rnd.Next(1000, 2000),
_antiAircrafGun.Init(rnd.Next(100, 300), rnd.Next(1000, 2000),
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
_antiAircrafGun.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), _antiAircrafGun.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100),
pictureBoxAntiAircraftGun.Width, pictureBoxAntiAircraftGun.Height); pictureBoxAntiAircraftGun.Width, pictureBoxAntiAircraftGun.Height);