From 79d879bc9f8c80c93d382b67a92b527c8d9e24d1 Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Tue, 13 Sep 2022 17:13:08 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9E=D1=84=D0=BE=D1=80=D0=BC=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Locomotive/Locomotive/DrawningLocomotive.cs | 12 ++++++------ Locomotive/Locomotive/FormLocomotive.Designer.cs | 2 +- Locomotive/Locomotive/FormLocomotive.cs | 5 +++-- 3 files changed, 10 insertions(+), 9 deletions(-) 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);