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

This commit is contained in:
crum61kg 2022-10-02 21:36:21 +04:00
parent 0002354055
commit fc67dec55e
3 changed files with 4 additions and 6 deletions

View File

@ -45,10 +45,9 @@ namespace WarmlyShip
/// <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 DrawningShip(int speed, float weight, Color bodyColor)
{ {
Ship = new EntityShip(); Ship = new EntityShip(speed, weight, bodyColor);
Ship.Init(speed, weight, bodyColor);
} }
/// <summary> /// <summary>

View File

@ -35,7 +35,7 @@ namespace WarmlyShip
/// <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

@ -28,8 +28,7 @@ namespace WarmlyShip
private void ButtonCreate_Click(object sender, EventArgs e) private void ButtonCreate_Click(object sender, EventArgs e)
{ {
Random rnd = new(); Random rnd = new();
_ship = new DrawningShip(); _ship = new DrawningShip(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), rnd.Next(10, 100), pictureBoxShip.Width, pictureBoxShip.Height); _ship.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxShip.Width, pictureBoxShip.Height);
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_ship.Ship.Speed}"; toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_ship.Ship.Speed}";
toolStripStatusLabelWeight.Text = $"Âåñ: {_ship.Ship.Weight}"; toolStripStatusLabelWeight.Text = $"Âåñ: {_ship.Ship.Weight}";