From 3e58001f7e10aa6ad1661dca7cdd16ff05f88b7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=BB=D0=B0=D0=B4=D0=B8=D1=81=D0=BB=D0=B0=D0=B2=20?= =?UTF-8?q?=D0=97=D0=B0=D1=85=D0=B0=D1=80=D0=BE=D0=B2?= Date: Mon, 26 Sep 2022 22:51:18 +0400 Subject: [PATCH] =?UTF-8?q?+=D0=91=D1=83=D0=BB=D1=8C=D0=B4=D0=BE=D0=B7?= =?UTF-8?q?=D0=B5=D1=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Traktor/Traktor/DrawField.Designer.cs | 57 +++++++++----- Traktor/Traktor/DrawField.cs | 29 ++++++- Traktor/Traktor/MultiTraktor.cs | 32 ++++++++ Traktor/Traktor/MultiTraktorDraw.cs | 109 ++++++++++++++++++++++++++ Traktor/Traktor/TraktorDraw.cs | 21 +++-- 5 files changed, 221 insertions(+), 27 deletions(-) create mode 100644 Traktor/Traktor/MultiTraktor.cs create mode 100644 Traktor/Traktor/MultiTraktorDraw.cs diff --git a/Traktor/Traktor/DrawField.Designer.cs b/Traktor/Traktor/DrawField.Designer.cs index 0455f1e..94499b5 100644 --- a/Traktor/Traktor/DrawField.Designer.cs +++ b/Traktor/Traktor/DrawField.Designer.cs @@ -38,6 +38,7 @@ this.buttonRIGHT = new System.Windows.Forms.Button(); this.buttonDOWN = new System.Windows.Forms.Button(); this.buttonUP = new System.Windows.Forms.Button(); + this.buttonCreateModif = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxTraktor)).BeginInit(); this.statusStrip.SuspendLayout(); this.SuspendLayout(); @@ -46,8 +47,9 @@ // this.pictureBoxTraktor.Dock = System.Windows.Forms.DockStyle.Fill; this.pictureBoxTraktor.Location = new System.Drawing.Point(0, 0); + this.pictureBoxTraktor.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.pictureBoxTraktor.Name = "pictureBoxTraktor"; - this.pictureBoxTraktor.Size = new System.Drawing.Size(800, 425); + this.pictureBoxTraktor.Size = new System.Drawing.Size(700, 316); this.pictureBoxTraktor.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; this.pictureBoxTraktor.TabIndex = 0; this.pictureBoxTraktor.TabStop = false; @@ -60,35 +62,37 @@ this.toolStripStatusLabelSpeed, this.toolStripStatusLabelWeight, this.toolStripStatusLabelBodyColor}); - this.statusStrip.Location = new System.Drawing.Point(0, 425); + this.statusStrip.Location = new System.Drawing.Point(0, 316); this.statusStrip.Name = "statusStrip"; - this.statusStrip.Size = new System.Drawing.Size(800, 26); + this.statusStrip.Padding = new System.Windows.Forms.Padding(1, 0, 12, 0); + this.statusStrip.Size = new System.Drawing.Size(700, 22); this.statusStrip.TabIndex = 1; // // toolStripStatusLabelSpeed // this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed"; - this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(80, 20); + this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(65, 17); this.toolStripStatusLabelSpeed.Text = "Скорость: "; // // toolStripStatusLabelWeight // this.toolStripStatusLabelWeight.Name = "toolStripStatusLabelWeight"; - this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(40, 20); + this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(32, 17); this.toolStripStatusLabelWeight.Text = "Вес: "; // // toolStripStatusLabelBodyColor // this.toolStripStatusLabelBodyColor.Name = "toolStripStatusLabelBodyColor"; - this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(95, 20); + this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(75, 17); this.toolStripStatusLabelBodyColor.Text = "Цвет кузова:"; // // buttonCreate // this.buttonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.buttonCreate.Location = new System.Drawing.Point(29, 363); + this.buttonCreate.Location = new System.Drawing.Point(25, 272); + this.buttonCreate.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonCreate.Name = "buttonCreate"; - this.buttonCreate.Size = new System.Drawing.Size(94, 29); + this.buttonCreate.Size = new System.Drawing.Size(82, 22); this.buttonCreate.TabIndex = 2; this.buttonCreate.Text = "Создать"; this.buttonCreate.UseVisualStyleBackColor = true; @@ -99,9 +103,10 @@ this.buttonLEFT.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonLEFT.BackgroundImage = global::Traktor.Properties.Resources.arrowLeft; this.buttonLEFT.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonLEFT.Location = new System.Drawing.Point(673, 361); + this.buttonLEFT.Location = new System.Drawing.Point(589, 271); + this.buttonLEFT.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonLEFT.Name = "buttonLEFT"; - this.buttonLEFT.Size = new System.Drawing.Size(30, 29); + this.buttonLEFT.Size = new System.Drawing.Size(26, 22); this.buttonLEFT.TabIndex = 3; this.buttonLEFT.UseVisualStyleBackColor = true; this.buttonLEFT.Click += new System.EventHandler(this.ButtonMove_Click); @@ -111,9 +116,10 @@ this.buttonRIGHT.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonRIGHT.BackgroundImage = global::Traktor.Properties.Resources.arrowRight; this.buttonRIGHT.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonRIGHT.Location = new System.Drawing.Point(745, 361); + this.buttonRIGHT.Location = new System.Drawing.Point(652, 271); + this.buttonRIGHT.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonRIGHT.Name = "buttonRIGHT"; - this.buttonRIGHT.Size = new System.Drawing.Size(30, 29); + this.buttonRIGHT.Size = new System.Drawing.Size(26, 22); this.buttonRIGHT.TabIndex = 4; this.buttonRIGHT.UseVisualStyleBackColor = true; this.buttonRIGHT.Click += new System.EventHandler(this.ButtonMove_Click); @@ -123,9 +129,10 @@ this.buttonDOWN.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonDOWN.BackgroundImage = global::Traktor.Properties.Resources.arrowDown; this.buttonDOWN.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonDOWN.Location = new System.Drawing.Point(709, 379); + this.buttonDOWN.Location = new System.Drawing.Point(620, 284); + this.buttonDOWN.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonDOWN.Name = "buttonDOWN"; - this.buttonDOWN.Size = new System.Drawing.Size(30, 29); + this.buttonDOWN.Size = new System.Drawing.Size(26, 22); this.buttonDOWN.TabIndex = 5; this.buttonDOWN.UseVisualStyleBackColor = true; this.buttonDOWN.Click += new System.EventHandler(this.ButtonMove_Click); @@ -135,18 +142,30 @@ this.buttonUP.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonUP.BackgroundImage = global::Traktor.Properties.Resources.arrowUp; this.buttonUP.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonUP.Location = new System.Drawing.Point(709, 343); + this.buttonUP.Location = new System.Drawing.Point(620, 257); + this.buttonUP.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonUP.Name = "buttonUP"; - this.buttonUP.Size = new System.Drawing.Size(30, 29); + this.buttonUP.Size = new System.Drawing.Size(26, 22); this.buttonUP.TabIndex = 6; this.buttonUP.UseVisualStyleBackColor = true; this.buttonUP.Click += new System.EventHandler(this.ButtonMove_Click); // + // buttonCreateModif + // + this.buttonCreateModif.Location = new System.Drawing.Point(113, 272); + this.buttonCreateModif.Name = "buttonCreateModif"; + this.buttonCreateModif.Size = new System.Drawing.Size(110, 22); + this.buttonCreateModif.TabIndex = 7; + this.buttonCreateModif.Text = "Модификация"; + this.buttonCreateModif.UseVisualStyleBackColor = true; + this.buttonCreateModif.Click += new System.EventHandler(this.buttonCreateModif_Click); + // // DrawField // - this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 451); + this.ClientSize = new System.Drawing.Size(700, 338); + this.Controls.Add(this.buttonCreateModif); this.Controls.Add(this.buttonUP); this.Controls.Add(this.buttonDOWN); this.Controls.Add(this.buttonRIGHT); @@ -154,6 +173,7 @@ this.Controls.Add(this.buttonCreate); this.Controls.Add(this.pictureBoxTraktor); this.Controls.Add(this.statusStrip); + this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.Name = "DrawField"; this.Text = "Трактор"; this.Click += new System.EventHandler(this.ButtonMove_Click); @@ -177,5 +197,6 @@ private Button buttonRIGHT; private Button buttonDOWN; private Button buttonUP; + private Button buttonCreateModif; } } \ No newline at end of file diff --git a/Traktor/Traktor/DrawField.cs b/Traktor/Traktor/DrawField.cs index a5ff01f..e7b802f 100644 --- a/Traktor/Traktor/DrawField.cs +++ b/Traktor/Traktor/DrawField.cs @@ -1,3 +1,5 @@ +using System; + namespace Traktor { public partial class DrawField : Form @@ -18,15 +20,22 @@ namespace Traktor pictureBoxTraktor.Image = bmp; } + // + private void SetData() + { + Random random = new(); + _Traktor.SetPosition(random.Next(10, 50), random.Next(10, 50), pictureBoxTraktor.Width, pictureBoxTraktor.Height); + toolStripStatusLabelSpeed.Text = $": {_Traktor.Traktor.Speed}"; + toolStripStatusLabelWeight.Text = $": {_Traktor.Traktor.Weight}"; + toolStripStatusLabelBodyColor.Text = $" : {_Traktor.Traktor.BodyColor.Name}"; + } + // private void ButtonCreate_Click(object sender, EventArgs e) { Random random = new Random(); _Traktor = new TraktorDraw(random.Next(100, 200), random.Next(2500, 5000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256))); - _Traktor.SetPosition(random.Next(10, 50), random.Next(10, 50), pictureBoxTraktor.Width, pictureBoxTraktor.Height); - toolStripStatusLabelSpeed.Text = $": {_Traktor.Traktor.Speed}"; - toolStripStatusLabelWeight.Text = $": {_Traktor.Traktor.Weight}"; - toolStripStatusLabelBodyColor.Text = $" : {_Traktor.Traktor.BodyColor.Name}"; + SetData(); Draw(); } @@ -57,5 +66,17 @@ namespace Traktor _Traktor?.ChangeBorders(pictureBoxTraktor.Width, pictureBoxTraktor.Height); Draw(); } + + // "" + private void buttonCreateModif_Click(object sender, EventArgs e) + { + Random random = new Random(); + _Traktor = new MultiTraktorDraw(random.Next(100, 200), random.Next(2500, 5000), + Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), + Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), + Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2))); + SetData(); + Draw(); + } } } \ No newline at end of file diff --git a/Traktor/Traktor/MultiTraktor.cs b/Traktor/Traktor/MultiTraktor.cs new file mode 100644 index 0000000..cc03e88 --- /dev/null +++ b/Traktor/Traktor/MultiTraktor.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Traktor +{ + // Класс сущности "многофункциональный трактор" + internal class MultiTraktor : EntityTraktor + { + /// Дополнительный цвет + public Color DopColor { get; private set; } + /// Признак наличия ковша спереди + public bool KovshFront { get; private set; } + /// Признак наличия ковша сзади + public bool KovshBack { get; private set; } + /// Инициализация свойств + /// Скорость + /// Вес трактора + /// Цвет кузова + /// Дополнительный цвет + /// Признак наличия ковша спереди + /// Признак наличия ковша сзади + public MultiTraktor(int speed, float weight, Color bodyColor, Color dopColor, bool kovshFront, bool kovshBack) : base(speed, weight, bodyColor) + { + DopColor = dopColor; + KovshFront = kovshFront; + KovshBack = kovshBack; + } + } +} diff --git a/Traktor/Traktor/MultiTraktorDraw.cs b/Traktor/Traktor/MultiTraktorDraw.cs new file mode 100644 index 0000000..f09a387 --- /dev/null +++ b/Traktor/Traktor/MultiTraktorDraw.cs @@ -0,0 +1,109 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Traktor +{ + // Класс, отвечающий за прорисовку и перемещение объекта-сущности + internal class MultiTraktorDraw : TraktorDraw + { + /// Инициализация свойств + /// Скорость + /// Вес трактора + /// Цвет кузова + /// Дополнительный цвет + /// Признак наличия ковша спереди + /// Признак наличия ковша сзади + /// Ширина отрисовки автомобиля + /// Высота отрисовки автомобиля + public MultiTraktorDraw(int speed, float weight, Color bodyColor, Color dopColor, bool kovshFront, bool kovshBack) : base(speed, weight, bodyColor, 188, 100) + { + Traktor = new MultiTraktor(speed, weight, bodyColor, dopColor, kovshFront, kovshBack); + } + + public override void DrawEntity(Graphics g) + { + if (Traktor is not MultiTraktor multiTraktor) + { + return; + } + Pen pen_Black_1pxl = new Pen(Color.Black, 1); + Pen pen_Black_2pxl = new Pen(Color.Black, 2); + Brush brBlack = new SolidBrush(Color.Black); + Brush dopBrush = new SolidBrush(multiTraktor.DopColor); + + PointF point1; + PointF point2; + PointF point3; + PointF point4; + + bool Draw = false; + if (multiTraktor.KovshBack) + { + g.DrawRectangle(pen_Black_1pxl, startPosX, startPosY + 8, 4, 35); + g.DrawRectangle(pen_Black_1pxl, startPosX + 33, startPosY + 34, 10, 15); + + point1 = new PointF(startPosX, startPosY + 8); + point2 = new PointF(startPosX + 33, startPosY + 41); + point3 = new PointF(startPosX + 33, startPosY + 34); + point4 = new PointF(startPosX + 7, startPosY + 8); + PointF[] curvePoints = + { + point1, + point2, + point3, + point4 + }; + g.FillPolygon(dopBrush, curvePoints); + g.DrawPolygon(pen_Black_1pxl, curvePoints); + + point1 = new PointF(startPosX + 6, startPosY + 8 + 15); + point2 = new PointF(startPosX + 6, startPosY + 8 + 35); + point3 = new PointF(startPosX + 26, startPosY + 8 + 35); + PointF[] curvePoints2 = +{ + point1, + point2, + point3 + }; + g.FillPolygon(dopBrush, curvePoints2); + g.DrawPolygon(pen_Black_1pxl, curvePoints2); + + startPosX += 43; + base.DrawEntity(g); + startPosX -= 43; + Draw = true; + } + + if (multiTraktor.KovshFront) + { + if (Draw) + { + point1 = new PointF(startPosX + 43 + 102, startPosY + 30); + point2 = new PointF(startPosX + 43 + 102, startPosY + 65); + point3 = new PointF(startPosX + 43 + 137, startPosY + 65); + + } + else + { + point1 = new PointF(startPosX + 102, startPosY + 30); + point2 = new PointF(startPosX + 102, startPosY + 65); + point3 = new PointF(startPosX + 137, startPosY + 65); + base.DrawEntity(g); + } + PointF[] curvePoints = + { + point1, + point2, + point3 + }; + g.FillPolygon(dopBrush, curvePoints); + g.DrawPolygon(pen_Black_1pxl, curvePoints); + } + if (!Draw) { base.DrawEntity(g); } + } + } +} diff --git a/Traktor/Traktor/TraktorDraw.cs b/Traktor/Traktor/TraktorDraw.cs index fa0a0dd..1681188 100644 --- a/Traktor/Traktor/TraktorDraw.cs +++ b/Traktor/Traktor/TraktorDraw.cs @@ -12,17 +12,17 @@ namespace Traktor internal class TraktorDraw { //Сущность - public EntityTraktor Traktor { get; private set; } + public EntityTraktor Traktor { get; protected set; } /// Левая координата отрисовки сущности - private float startPosX; + protected float startPosX; /// Верхняя кооридната отрисовки сущности - private float startPosY; + protected float startPosY; /// Ширина окна отрисовки private int? pictureWidth = null; /// Высота окна отрисовки private int? pictureHeight = null; /// Ширина отрисовки сущности - private readonly int entWidth = 130; + private readonly int entWidth = 115; /// Высота отрисовки сущности private readonly int entHeight = 100; @@ -30,6 +30,17 @@ namespace Traktor { Traktor = new EntityTraktor(speed, weight, bodycolor); } + /// Инициализация свойств + /// Скорость + /// Вес автомобиля + /// Цвет кузова + /// Ширина отрисовки автомобиля + /// Высота отрисовки автомобиля + protected TraktorDraw(int speed, float weight, Color bodyColor, int trktrWidth, int trktrHeight) : this(speed, weight, bodyColor) + { + entWidth = trktrWidth; + entHeight = trktrHeight; + } //Установка позиции сущности public void SetPosition(int x, int y, int width, int height) @@ -83,7 +94,7 @@ namespace Traktor } //Отрисовка сущности - public void DrawEntity(Graphics g) + public virtual void DrawEntity(Graphics g) { if (startPosX < 0 || startPosY < 0 || !pictureHeight.HasValue || !pictureWidth.HasValue) {