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

This commit is contained in:
just1valery 2022-09-27 10:49:18 +04:00
parent 907be7656b
commit b699fe0553
3 changed files with 4 additions and 6 deletions

View File

@ -36,10 +36,9 @@
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес коробля</param>
/// <param name="bodyColor">Цвет основной части</param>
public void Init(int speed, float weight, Color bodyColor)
public DrawningWarmlyShip(int speed, float weight, Color bodyColor)
{
Ship = new EntityWarmlyShip();
Ship.Init(speed, weight, bodyColor);
Ship = new EntityWarmlyShip(speed, weight, bodyColor);
}
/// <summary>
/// Установка позиции коробля

View File

@ -31,7 +31,7 @@ namespace WarmlyShip
/// <param name="weight"></param>
/// <param name="bodyColor"></param>
/// <returns></returns>
public void Init(int speed, float weight, Color bodyColor)
public EntityWarmlyShip(int speed, float weight, Color bodyColor)
{
Random rnd = new();
Speed = speed <= 0 ? rnd.Next(50, 150) : speed;

View File

@ -22,8 +22,7 @@ namespace WarmlyShip
private void buttonCreate_Click(object sender, EventArgs e)
{
Random rnd = new();
_ship = new DrawningWarmlyShip();
_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 = new DrawningWarmlyShip(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);
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_ship.Ship.Speed}";
toolStripStatusLabelWeight.Text = $"Âåñ: {_ship.Ship.Weight}";