diff --git a/Locomotive/Locomotive/DrawningLocomotive.cs b/Locomotive/Locomotive/DrawningLocomotive.cs index 775bd03..7d8650e 100644 --- a/Locomotive/Locomotive/DrawningLocomotive.cs +++ b/Locomotive/Locomotive/DrawningLocomotive.cs @@ -25,9 +25,9 @@ namespace Locomotive private readonly int _locomotiveHeight = 50; /// Инициализация свойств - public void Init(int speed, float weight, Color bodyColor) + public void Init(int speed, float weight, Color bodyColor, EntityLocomotive entity) { - Locomotive = new EntityLocomotive(); + Locomotive = entity; Locomotive.Init(speed, weight, bodyColor); } /// Установка позиции локомотива @@ -101,9 +101,9 @@ namespace Locomotive //тело g.DrawRectangle(pen, _startPosX , _startPosY, _locomotiveWidth - 10, _locomotiveHeight - 10); //окна - g.DrawRectangle(pen, _startPosX + 10, _startPosY + 10, 10, 10); - g.DrawRectangle(pen, _startPosX + 30, _startPosY + 10, 10, 10); - g.DrawRectangle(pen, _startPosX + 80, _startPosY + 10, 10, 10); + g.FillRectangle(new SolidBrush(Locomotive?.BodyColor ?? Color.Black), _startPosX + 10, _startPosY + 10, 10, 10); + g.FillRectangle(new SolidBrush(Locomotive?.BodyColor ?? Color.Black), _startPosX + 30, _startPosY + 10, 10, 10); + g.FillRectangle(new SolidBrush(Locomotive?.BodyColor ?? Color.Black), _startPosX + 80, _startPosY + 10, 10, 10); //дверь g.DrawRectangle(pen, _startPosX + 50, _startPosY + 10, 10, 20); //колеса @@ -112,7 +112,7 @@ namespace Locomotive g.DrawEllipse(pen, _startPosX + 70, _startPosY + 40, 10, 10); g.DrawEllipse(pen, _startPosX + 90, _startPosY + 40, 10, 10); //черный прямоугольник - g.FillRectangle(new SolidBrush(Color.Black), _startPosX + 100, _startPosY + 10, 10, 30); + g.FillRectangle(new SolidBrush(Locomotive?.BodyColor ?? Color.Black), _startPosX + 100, _startPosY + 10, 10, 30); } public void ChangeBorders(int width, int height) diff --git a/Locomotive/Locomotive/FormLocomotive.Designer.cs b/Locomotive/Locomotive/FormLocomotive.Designer.cs index 0ca27bc..4aec4a1 100644 --- a/Locomotive/Locomotive/FormLocomotive.Designer.cs +++ b/Locomotive/Locomotive/FormLocomotive.Designer.cs @@ -51,7 +51,7 @@ this.pictureBoxLocomotive.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; this.pictureBoxLocomotive.TabIndex = 0; this.pictureBoxLocomotive.TabStop = false; - //this.pictureBoxLocomotive.Click += new System.EventHandler(this.pictureBoxLocomotive_Click); + this.pictureBoxLocomotive.Resize += new System.EventHandler(this.pictureBoxLocomotive_Resize); // // statusStrip1 diff --git a/Locomotive/Locomotive/FormLocomotive.cs b/Locomotive/Locomotive/FormLocomotive.cs index 8bd2853..211a8a6 100644 --- a/Locomotive/Locomotive/FormLocomotive.cs +++ b/Locomotive/Locomotive/FormLocomotive.cs @@ -3,6 +3,7 @@ namespace Locomotive public partial class FormLocomotive : Form { private DrawningLocomotive _locomotive; + private EntityLocomotive _entity; public FormLocomotive() { @@ -22,7 +23,8 @@ namespace Locomotive { Random rnd = new(); _locomotive = new DrawningLocomotive(); - _locomotive.Init(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); + _entity = new EntityLocomotive(); + _locomotive.Init(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), _entity); _locomotive.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxLocomotive.Width, pictureBoxLocomotive.Height); toolStripStatusLabelSpeed.Text = $"Speed: {_locomotive.Locomotive.Speed}"; toolStripStatusLabelWeight.Text = $"Weight: {_locomotive.Locomotive.Weight}"; @@ -52,7 +54,6 @@ namespace Locomotive Draw(); } - private void pictureBoxLocomotive_Click() { } private void pictureBoxLocomotive_Resize(object sender, EventArgs e) { _locomotive?.ChangeBorders(pictureBoxLocomotive.Width, pictureBoxLocomotive.Height);