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

This commit is contained in:
the 2022-09-27 09:34:26 +04:00
parent 95c09688b7
commit b9ad742c3f
3 changed files with 4 additions and 7 deletions

View File

@ -42,10 +42,9 @@ namespace Ship
/// <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 DrawingShip(int speed, float weight, Color bodyColor)
{ {
Ship = new EntityShip(); Ship = new EntityShip(speed, weight, bodyColor);
Ship.Init(speed, weight, bodyColor);
} }
/// <summary> /// <summary>
/// Установка позиции корабля /// Установка позиции корабля

View File

@ -31,7 +31,7 @@ namespace Ship
/// <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 EntityShip(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,9 +26,7 @@ namespace Ship
private void buttonCreate_Click(object sender, EventArgs e) private void buttonCreate_Click(object sender, EventArgs e)
{ {
Random rnd = new(); Random rnd = new();
_ship = new DrawingShip(); _ship = new DrawingShip(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
_ship.Init(rnd.Next(100, 300), rnd.Next(1000, 2000),
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
_ship.SetPosition(rnd.Next(10, 100), pictureBoxShip.Height - rnd.Next(20, 100), _ship.SetPosition(rnd.Next(10, 100), pictureBoxShip.Height - rnd.Next(20, 100),
pictureBoxShip.Width, pictureBoxShip.Height); pictureBoxShip.Width, pictureBoxShip.Height);
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_ship.Ship.Speed}"; toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_ship.Ship.Speed}";