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

This commit is contained in:
AnnZhimol 2022-09-20 18:32:27 +04:00
parent 0f34de33a4
commit cd528db9c6
4 changed files with 5 additions and 7 deletions

View File

@ -11,6 +11,6 @@ namespace Warship
Up=1,
Down=2,
Left=3,
Right=4
Right=4,
}
}

View File

@ -16,10 +16,9 @@ namespace Warship
private readonly int _warshipWidth = 120;
private readonly int _warshipHeight = 40;
public void Init(int speed, float weight,Color bodyColor)
public DrawingWarship(int speed, float weight,Color bodyColor)
{
Warship = new EntityWarship();
Warship.Init(speed, weight, bodyColor);
Warship = new EntityWarship(speed, weight, bodyColor);
}
public void SetPosition(int x, int y, int width, int height)

View File

@ -13,7 +13,7 @@ namespace Warship
public Color BodyColor { get; private set; }
public int Step => (int)(Speed * 2000 / Weight);
public void Init(int speed, float weight, Color bodyColor)
public EntityWarship(int speed, float weight, Color bodyColor)
{
Random rnd = new();
Speed = speed <= 0 ? rnd.Next(10, 60) : speed;

View File

@ -18,8 +18,7 @@ namespace Warship
private void buttonCreate_Click(object sender, EventArgs e)
{
Random rnd = new();
_warship = new DrawingWarship();
_warship.Init(rnd.Next(10, 60), rnd.Next(20000, 25000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
_warship = new DrawingWarship(rnd.Next(10, 60), rnd.Next(20000, 25000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
_warship.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxWarship.Width, pictureBoxWarship.Height);
toolStripStatusLabelSpeed.Text = $"Cêîðîñòü: {_warship.Warship.Speed}";
toolStripStatusLabelWeight.Text = $"Âåñ: {_warship.Warship.Weight}";