From e7832c9d05120ae6a0b9df1bb3a1d09b46c0b30e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=BE=D0=BB=D0=B8=D0=BD=D0=B0=20=D0=A7=D1=83=D0=B1?= =?UTF-8?q?=D1=8B=D0=BA=D0=B8=D0=BD=D0=B0?= Date: Fri, 22 Sep 2023 17:19:54 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=B0=D1=80=D0=B8=D1=81=D0=BE=D0=B2?= =?UTF-8?q?=D0=B0=D0=BB=D0=B0=20=D0=BF=D0=B0=D1=80=D1=83=D1=81=D0=BD=D0=B8?= =?UTF-8?q?=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sailboat/Sailboat/Direction.cs | 2 +- Sailboat/Sailboat/DrawingSailboat.cs | 103 ++++++++++----------- Sailboat/Sailboat/EntitySailboat.cs | 2 +- Sailboat/Sailboat/FormSailboat.Designer.cs | 5 + Sailboat/Sailboat/FormSailboat.cs | 55 ++++++++++- 5 files changed, 108 insertions(+), 59 deletions(-) diff --git a/Sailboat/Sailboat/Direction.cs b/Sailboat/Sailboat/Direction.cs index 31bfff6..46e7fda 100644 --- a/Sailboat/Sailboat/Direction.cs +++ b/Sailboat/Sailboat/Direction.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace Sailboat { - internal enum DirectionType + public enum DirectionType { /// /// Вверх diff --git a/Sailboat/Sailboat/DrawingSailboat.cs b/Sailboat/Sailboat/DrawingSailboat.cs index 9ab0542..fd82435 100644 --- a/Sailboat/Sailboat/DrawingSailboat.cs +++ b/Sailboat/Sailboat/DrawingSailboat.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace Sailboat { - internal class DrawingSailboat + public class DrawingSailboat { /// /// Класс-сущность @@ -31,11 +31,11 @@ namespace Sailboat /// /// Ширина прорисовки автомобиля /// - private readonly int _carWidth = 110; + private readonly int _boatWidth = 180; /// /// Высота прорисовки автомобиля /// - private readonly int _carHeight = 60; + private readonly int _boatHeight = 180; /// /// Инициализация свойств /// @@ -97,11 +97,17 @@ namespace Sailboat break; // вправо case DirectionType.Right: - // TODO: Продумать логику + if (_startPosX + EntitySailboat.Step + _boatWidth < _pictureWidth) + { + _startPosX += (int)EntitySailboat.Step; + } break; //вниз case DirectionType.Down: - // TODO: Продумать логику + if (_startPosY + EntitySailboat.Step + _boatHeight < _pictureHeight) + { + _startPosY += (int)EntitySailboat.Step; + } break; } } @@ -119,7 +125,7 @@ namespace Sailboat Brush additionalBrush = new SolidBrush(EntitySailboat.AdditionalColor); // обвесы - if (EntitySailboat.BodyKit) + /*if (EntitySailboat.BodyKit) { g.DrawEllipse(pen, _startPosX + 90, _startPosY, 20, 20); g.DrawEllipse(pen, _startPosX + 90, _startPosY + 40, 20, @@ -167,6 +173,7 @@ namespace Sailboat g.FillRectangle(additionalBrush, _startPosX + 35, _startPosY + 45, 40, 15); } + //границы автомобиля g.DrawEllipse(pen, _startPosX + 10, _startPosY + 5, 20, 20); g.DrawEllipse(pen, _startPosX + 10, _startPosY + 35, 20, 20); @@ -175,58 +182,42 @@ namespace Sailboat g.DrawRectangle(pen, _startPosX + 9, _startPosY + 15, 10, 30); g.DrawRectangle(pen, _startPosX + 90, _startPosY + 15, 10, 30); - g.DrawRectangle(pen, _startPosX + 20, _startPosY + 4, 70, 52); - //задние фары - Brush brRed = new SolidBrush(Color.Red); - g.FillEllipse(brRed, _startPosX + 10, _startPosY + 5, 20, 20); - g.FillEllipse(brRed, _startPosX + 10, _startPosY + 35, 20, - 20); - //передние фары - Brush brYellow = new SolidBrush(Color.Yellow); - g.FillEllipse(brYellow, _startPosX + 80, _startPosY + 5, 20, - 20); - g.FillEllipse(brYellow, _startPosX + 80, _startPosY + 35, 20, - 20); - //кузов - Brush br = new SolidBrush(EntitySailboat.BodyColor); - g.FillRectangle(br, _startPosX + 10, _startPosY + 15, 10, 30); - g.FillRectangle(br, _startPosX + 90, _startPosY + 15, 10, 30); - g.FillRectangle(br, _startPosX + 20, _startPosY + 5, 70, 50); - //стекла - Brush brBlue = new SolidBrush(Color.LightBlue); - g.FillRectangle(brBlue, _startPosX + 70, _startPosY + 10, 5, - 40); - g.FillRectangle(brBlue, _startPosX + 30, _startPosY + 10, 5, - 40); - g.FillRectangle(brBlue, _startPosX + 35, _startPosY + 8, 35, - 2); - g.FillRectangle(brBlue, _startPosX + 35, _startPosY + 51, 35, - 2); - //выделяем рамкой крышу - g.DrawRectangle(pen, _startPosX + 35, _startPosY + 10, 35, - 40); - g.DrawRectangle(pen, _startPosX + 75, _startPosY + 15, 25, - 30); - g.DrawRectangle(pen, _startPosX + 10, _startPosY + 15, 15, - 30); - // спортивная линия - if (EntitySailboat.SportLine) + g.DrawRectangle(pen, _startPosX + 20, _startPosY + 4, 70, 52);*/ + + //основной корпус парусника + Point[] hull = new Point[] { - g.FillRectangle(additionalBrush, _startPosX + 75, - _startPosY + 23, 25, 15); - g.FillRectangle(additionalBrush, _startPosX + 35, - _startPosY + 23, 35, 15); - g.FillRectangle(additionalBrush, _startPosX + 10, - _startPosY + 23, 20, 15); - } - // крыло - if (EntitySailboat.Wing) + new Point(_startPosX + 40, _startPosY + 110), + new Point(_startPosX + 140, _startPosY + 110), + new Point(_startPosX + 170, _startPosY + 140), + new Point(_startPosX + 140, _startPosY + 170), + new Point(_startPosX + 40, _startPosY + 170) + }; + g.DrawPolygon(pen, hull); + + g.DrawEllipse(pen, _startPosX + 50, _startPosY + 120, 90, 40); + + //усиленный корпус парусника + Point[] hullCooler = new Point[] { - g.FillRectangle(additionalBrush, _startPosX, _startPosY - + 5, 10, 50); - g.DrawRectangle(pen, _startPosX, _startPosY + 5, 10, - 50); - } + new Point(_startPosX + 30, _startPosY + 100), + new Point(_startPosX + 150, _startPosY + 100), + new Point(_startPosX + 190, _startPosY + 140), + new Point(_startPosX + 150, _startPosY + 180), + new Point(_startPosX + 30, _startPosY + 180) + }; + g.DrawPolygon(pen, hullCooler); + + //парус + + g.DrawLine(pen, new Point(_startPosX + 95, _startPosY + 140),new Point (_startPosX + 95, _startPosY + 20)); + Point[] sail = new Point[] + { + new Point(_startPosX + 95, _startPosY + 20), + new Point(_startPosX + 160, _startPosY + 140), + new Point(_startPosX + 45, _startPosY + 140) + }; + g.DrawPolygon(pen, sail); } } } diff --git a/Sailboat/Sailboat/EntitySailboat.cs b/Sailboat/Sailboat/EntitySailboat.cs index c9fda1f..79dfc2a 100644 --- a/Sailboat/Sailboat/EntitySailboat.cs +++ b/Sailboat/Sailboat/EntitySailboat.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace Sailboat { - internal class EntitySailboat + public class EntitySailboat { /// /// Скорость diff --git a/Sailboat/Sailboat/FormSailboat.Designer.cs b/Sailboat/Sailboat/FormSailboat.Designer.cs index 6d9dcd1..fd83356 100644 --- a/Sailboat/Sailboat/FormSailboat.Designer.cs +++ b/Sailboat/Sailboat/FormSailboat.Designer.cs @@ -57,6 +57,7 @@ this.buttonCreate.TabIndex = 1; this.buttonCreate.Text = "Создать"; this.buttonCreate.UseVisualStyleBackColor = true; + this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click); // // buttonLeft // @@ -68,6 +69,7 @@ this.buttonLeft.Size = new System.Drawing.Size(30, 30); this.buttonLeft.TabIndex = 2; this.buttonLeft.UseVisualStyleBackColor = true; + this.buttonLeft.Click += new System.EventHandler(this.buttonMove_Click); // // buttonUp // @@ -79,6 +81,7 @@ this.buttonUp.Size = new System.Drawing.Size(30, 30); this.buttonUp.TabIndex = 3; this.buttonUp.UseVisualStyleBackColor = true; + this.buttonUp.Click += new System.EventHandler(this.buttonMove_Click); // // buttonRight // @@ -90,6 +93,7 @@ this.buttonRight.Size = new System.Drawing.Size(30, 30); this.buttonRight.TabIndex = 4; this.buttonRight.UseVisualStyleBackColor = true; + this.buttonRight.Click += new System.EventHandler(this.buttonMove_Click); // // buttonDown // @@ -101,6 +105,7 @@ this.buttonDown.Size = new System.Drawing.Size(30, 30); this.buttonDown.TabIndex = 5; this.buttonDown.UseVisualStyleBackColor = true; + this.buttonDown.Click += new System.EventHandler(this.buttonMove_Click); // // FormSailboat // diff --git a/Sailboat/Sailboat/FormSailboat.cs b/Sailboat/Sailboat/FormSailboat.cs index 14e0cf0..3606e69 100644 --- a/Sailboat/Sailboat/FormSailboat.cs +++ b/Sailboat/Sailboat/FormSailboat.cs @@ -2,9 +2,62 @@ namespace Sailboat { public partial class FormSailboat : Form { + private DrawingSailboat? _drawingSailboat; public FormSailboat() { InitializeComponent(); } + private void Draw() + { + if (_drawingSailboat == null) + { + return; + } + Bitmap bmp = new(pictureBoxSailboat.Width, + pictureBoxSailboat.Height); + Graphics gr = Graphics.FromImage(bmp); + _drawingSailboat.DrawTransport(gr); + pictureBoxSailboat.Image = bmp; + } + private void buttonCreate_Click(object sender, EventArgs e) + { + Random random = new(); + _drawingSailboat = new DrawingSailboat(); + _drawingSailboat.Init(random.Next(100, 300), + random.Next(1000, 3000), + 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)), Convert.ToBoolean(random.Next(0, 2)), pictureBoxSailboat.Width, pictureBoxSailboat.Height); + _drawingSailboat.SetPosition(random.Next(10, 100), random.Next(10, 100)); + Draw(); + } + private void buttonMove_Click(object sender, EventArgs e) + { + if (_drawingSailboat == null) + { + return; + } + string name = ((Button)sender)?.Name ?? string.Empty; + switch (name) + { + case "buttonUp": + _drawingSailboat.MoveTransport(DirectionType.Up); + break; + case "buttonDown": + _drawingSailboat.MoveTransport(DirectionType.Down); + break; + case "buttonLeft": + _drawingSailboat.MoveTransport(DirectionType.Left); + break; + case "buttonRight": + _drawingSailboat.MoveTransport(DirectionType.Right); + break; + } + Draw(); + + } } -} \ No newline at end of file +} \ No newline at end of file