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

This commit is contained in:
Denis 2022-10-06 01:34:11 +04:00
parent f0f0b3a9f9
commit 7e26948aff
3 changed files with 4 additions and 6 deletions

View File

@ -15,10 +15,9 @@ namespace AirplaneWithRadar
private int? _pictureHeight = null;
private readonly int _airplaneWidth = 50;
private readonly int _airplaneHeight = 27;
public void Init(int speed, float weight, Color bodyColor)
public DrawingAirplane(int speed, float weight, Color bodyColor)
{
Airplane = new EntityAirplane();
Airplane.Init(speed, weight, bodyColor);
Airplane = new EntityAirplane(speed, weight, bodyColor);
}
public void SetPosition(int x, int y, int width, int height)
{

View File

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

View File

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