Переход на конструкторы
This commit is contained in:
parent
95c09688b7
commit
b9ad742c3f
@ -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>
|
||||||
/// Установка позиции корабля
|
/// Установка позиции корабля
|
||||||
|
@ -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;
|
||||||
|
@ -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}";
|
||||||
|
Loading…
Reference in New Issue
Block a user