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

This commit is contained in:
Артём Алейкин 2022-10-04 16:41:33 +04:00
parent 1f16cad283
commit 746f60a4b1
3 changed files with 5 additions and 7 deletions

View File

@ -16,10 +16,9 @@ namespace AirBomber
private readonly int _airBomberWidth = 100; private readonly int _airBomberWidth = 100;
private readonly int _airBomberHeight = 100; private readonly int _airBomberHeight = 100;
public void Init(int speed, float weight, Color bodyColor) public DrawningBomber(int speed, float weight, Color bodyColor)
{ {
AirBomber = new EntityAirBomber(); AirBomber = new EntityAirBomber(speed, weight, bodyColor);
AirBomber.Init(speed, weight, bodyColor);
} }
public void SetPosition(int x, int y, int width, int height) public void SetPosition(int x, int y, int width, int height)

View File

@ -13,9 +13,9 @@ namespace AirBomber
public Color BodyColor { get; private set; } public Color BodyColor { get; private set; }
public float Step => Speed * 100 / Weight; public float Step => Speed * 100 / Weight;
public void Init(int speed, float weight, Color bodyColor) public EntityAirBomber(int speed, float weight, Color bodyColor)
{ {
Random rnd = new(); Random rnd = new Random();
Speed = speed <= 0 ? rnd.Next(50, 150) : speed; Speed = speed <= 0 ? rnd.Next(50, 150) : speed;
Weight = weight <= 0 ? rnd.Next(40, 70) : weight; Weight = weight <= 0 ? rnd.Next(40, 70) : weight;
BodyColor = bodyColor; BodyColor = bodyColor;

View File

@ -19,8 +19,7 @@ namespace AirBomber
private void ButtonCreate_Click(object sender, EventArgs e) private void ButtonCreate_Click(object sender, EventArgs e)
{ {
Random rnd = new(); Random rnd = new();
_airBomber = new DrawningBomber(); _airBomber = new DrawningBomber(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
_airBomber.Init(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
_airBomber.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxAirBomber.Width, pictureBoxAirBomber.Height); _airBomber.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxAirBomber.Width, pictureBoxAirBomber.Height);
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_airBomber.AirBomber.Speed}"; toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_airBomber.AirBomber.Speed}";
toolStripStatusLabelWeight.Text = $"Âåñ: {_airBomber.AirBomber.Weight}"; toolStripStatusLabelWeight.Text = $"Âåñ: {_airBomber.AirBomber.Weight}";