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

This commit is contained in:
Дамир Нугаев 2022-10-09 17:36:10 +04:00
parent d78b63b7fc
commit f6797078a8
3 changed files with 4 additions and 6 deletions

View File

@ -16,10 +16,9 @@ namespace Bus
protected readonly int _busWidth = 157;
protected readonly int _busHeight = 65;
public void Init(int speed, float weight, Color bodyColor)
public DrawingBus(int speed, float weight, Color bodyColor)
{
Bus = new EntityBus();
Bus.Init(speed, weight, bodyColor);
Bus = new EntityBus(speed, weight, bodyColor);
}
public void SetPosition(int x, int y, int width, int height)

View File

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

View File

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