diff --git a/Sailboat/Sailboat/DrawingSailboat.cs b/Sailboat/Sailboat/DrawingSailboat.cs index 3ade4a5..97f82b7 100644 --- a/Sailboat/Sailboat/DrawingSailboat.cs +++ b/Sailboat/Sailboat/DrawingSailboat.cs @@ -8,71 +8,38 @@ namespace Sailboat { public class DrawingSailboat { - /// - /// Класс-сущность - /// public EntitySailboat? EntitySailboat { get; private set; } - /// - /// Ширина окна - /// private int _pictureWidth; - /// - /// Высота окна - /// private int _pictureHeight; - /// - /// Левая координата прорисовки автомобиля - /// private int _startPosX; - /// - /// Верхняя кооридната прорисовки автомобиля - /// private int _startPosY; - /// - /// Ширина прорисовки автомобиля - /// - private readonly int _boatWidth = 180; - /// - /// Высота прорисовки автомобиля - /// - private readonly int _boatHeight = 180; - /// - /// Инициализация свойств - /// - /// Скорость - /// Вес - /// Цвет кузова - /// Дополнительный цвет - /// Признак наличия обвеса - /// Признак наличия антикрыла - /// Признак наличия гоночной полосы - /// Ширина картинки - /// Высота картинки - /// true - объект создан, false - проверка не пройдена, нельзя создать объект в этих размерах - public bool Init(int speed, double weight, Color bodyColor, Color additionalColor, bool bodyKit, bool wing, bool sportLine, int width, int height) + private readonly int _boatWidth = 160; + private readonly int _boatHeight = 160; + public bool Init(int speed, double weight, Color bodyColor, Color additionalColor, bool hull, bool sail, int width, int height) { - // TODO: Продумать проверки + if (width < _boatWidth || height < _boatHeight) + { + return false; + } _pictureWidth = width; _pictureHeight = height; EntitySailboat = new EntitySailboat(); - EntitySailboat.Init(speed, weight, bodyColor, additionalColor, bodyKit, wing, sportLine); + EntitySailboat.Init(speed, weight, bodyColor, additionalColor, hull, sail); return true; } - /// - /// Установка позиции - /// - /// Координата X - /// Координата Y public void SetPosition(int x, int y) { - // TODO: Изменение x, y + if (x < 0 || x + _boatWidth > _pictureWidth) + { + x = 0; + } + if (y < 0 || y + _boatHeight > _pictureHeight) + { + y = 0; + } _startPosX = x; _startPosY = y; } - /// - /// Изменение направления перемещения - /// - /// Направление public void MoveTransport(DirectionType direction) { if (EntitySailboat == null) @@ -81,28 +48,24 @@ namespace Sailboat } switch (direction) { - //влево case DirectionType.Left: if (_startPosX - EntitySailboat.Step > 0) { _startPosX -= (int)EntitySailboat.Step; } break; - //вверх case DirectionType.Up: if (_startPosY - EntitySailboat.Step > 0) { _startPosY -= (int)EntitySailboat.Step; } break; - // вправо case DirectionType.Right: if (_startPosX + EntitySailboat.Step + _boatWidth < _pictureWidth) { _startPosX += (int)EntitySailboat.Step; } break; - //вниз case DirectionType.Down: if (_startPosY + EntitySailboat.Step + _boatHeight < _pictureHeight) { @@ -111,103 +74,43 @@ namespace Sailboat break; } } - /// - /// Прорисовка объекта - /// - /// public void DrawTransport(Graphics g) { if (EntitySailboat == null) { return; } - Pen pen = new(Color.Black); + Pen pen = new(Color.Black, 4); Brush additionalBrush = new SolidBrush(EntitySailboat.AdditionalColor); - // обвесы - /*if (EntitySailboat.BodyKit) - { - g.DrawEllipse(pen, _startPosX + 90, _startPosY, 20, 20); - g.DrawEllipse(pen, _startPosX + 90, _startPosY + 40, 20, - 20); - g.DrawRectangle(pen, _startPosX + 90, _startPosY + 10, - 20, 40); - g.DrawRectangle(pen, _startPosX + 90, _startPosY, 15, - 15); - g.DrawRectangle(pen, _startPosX + 90, _startPosY + 45, - 15, 15); - g.FillEllipse(additionalBrush, _startPosX + 90, - _startPosY, 20, 20); - g.FillEllipse(additionalBrush, _startPosX + 90, - _startPosY + 40, 20, 20); - g.FillRectangle(additionalBrush, _startPosX + 90, - _startPosY + 10, 20, 40); - g.FillRectangle(additionalBrush, _startPosX + 90, - _startPosY + 1, 15, 15); - g.FillRectangle(additionalBrush, _startPosX + 90, - _startPosY + 45, 15, 15); - g.DrawEllipse(pen, _startPosX, _startPosY, 20, 20); - g.DrawEllipse(pen, _startPosX, _startPosY + 40, 20, 20); - g.DrawRectangle(pen, _startPosX, _startPosY + 10, 20, - 40); - g.DrawRectangle(pen, _startPosX + 5, _startPosY, 14, - 15); - g.DrawRectangle(pen, _startPosX + 5, _startPosY + 45, - 14, 15); - g.FillEllipse(additionalBrush, _startPosX, _startPosY, - 20, 20); - g.FillEllipse(additionalBrush, _startPosX, _startPosY + - 40, 20, 20); - g.FillRectangle(additionalBrush, _startPosX + 1, - _startPosY + 10, 25, 40); - g.FillRectangle(additionalBrush, _startPosX + 5, - _startPosY + 1, 15, 15); - g.FillRectangle(additionalBrush, _startPosX + 5, - _startPosY + 45, 15, 15); - g.DrawRectangle(pen, _startPosX + 35, _startPosY, 39, - 15); - g.DrawRectangle(pen, _startPosX + 35, _startPosY + 45, - 39, 15); - g.FillRectangle(additionalBrush, _startPosX + 35, - _startPosY + 1, 40, 15); - 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); - g.DrawEllipse(pen, _startPosX + 80, _startPosY + 5, 20, 20); - g.DrawEllipse(pen, _startPosX + 80, _startPosY + 35, 20, 20); - 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);*/ - + //усиленный корпус парусника - Point[] hullCooler = new Point[] + if (EntitySailboat.Hull) { - 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.FillPolygon(additionalBrush, hullCooler); - g.DrawPolygon(pen, hullCooler); + Point[] hullCooler = new Point[] + { + new Point(_startPosX, _startPosY + 80), + new Point(_startPosX + 120, _startPosY + 80), + new Point(_startPosX + 160, _startPosY + 120), + new Point(_startPosX + 120, _startPosY + 160), + new Point(_startPosX, _startPosY + 160) + }; + g.FillPolygon(additionalBrush, hullCooler); + g.DrawPolygon(pen, hullCooler); + } + //основной корпус парусника - Brush Brush = new SolidBrush(EntitySailboat.BodyColor); Point[] hull = new Point[] { - 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) + new Point(_startPosX + 10, _startPosY + 90), + new Point(_startPosX + 110, _startPosY + 90), + new Point(_startPosX + 140, _startPosY + 120), + new Point(_startPosX + 110, _startPosY + 150), + new Point(_startPosX + 10, _startPosY + 150) }; g.FillPolygon(Brush, hull); g.DrawPolygon(pen, hull); @@ -215,22 +118,25 @@ namespace Sailboat Brush addBrush = new SolidBrush(Color.Green); - g.FillEllipse(addBrush, _startPosX + 50, _startPosY + 120, 90, 40); - g.DrawEllipse(pen, _startPosX + 50, _startPosY + 120, 90, 40); + g.FillEllipse(addBrush, _startPosX + 20, _startPosY + 100, 90, 40); + g.DrawEllipse(pen, _startPosX + 20, _startPosY + 100, 90, 40); //парус - Brush sailBrush = new - SolidBrush(Color.Cyan); - - Point[] sail = new Point[] + if (EntitySailboat.Sail) { - new Point(_startPosX + 95, _startPosY + 20), - new Point(_startPosX + 160, _startPosY + 140), - new Point(_startPosX + 45, _startPosY + 140) - }; - g.FillPolygon(sailBrush, sail); - g.DrawPolygon(pen, sail); - g.DrawLine(pen, new Point(_startPosX + 95, _startPosY + 140), new Point(_startPosX + 95, _startPosY + 20)); + Brush sailBrush = new + SolidBrush(EntitySailboat.AdditionalColor); + + Point[] sail = new Point[] + { + new Point(_startPosX + 65, _startPosY), + new Point(_startPosX + 130, _startPosY + 120), + new Point(_startPosX + 15, _startPosY + 120) + }; + g.FillPolygon(sailBrush, sail); + g.DrawPolygon(pen, sail); + g.DrawLine(pen, new Point(_startPosX + 65, _startPosY + 120), new Point(_startPosX + 65, _startPosY)); + } } } } diff --git a/Sailboat/Sailboat/EntitySailboat.cs b/Sailboat/Sailboat/EntitySailboat.cs index 79dfc2a..8aa513f 100644 --- a/Sailboat/Sailboat/EntitySailboat.cs +++ b/Sailboat/Sailboat/EntitySailboat.cs @@ -25,17 +25,13 @@ namespace Sailboat /// public Color AdditionalColor { get; private set; } /// - /// Признак (опция) наличия обвеса + /// Признак (опция) наличия усиленного корпуса /// - public bool BodyKit { get; private set; } + public bool Hull { get; private set; } /// - /// Признак (опция) наличия антикрыла + /// Признак (опция) наличия паруса /// - public bool Wing { get; private set; } - /// - /// Признак (опция) наличия гоночной полосы - /// - public bool SportLine { get; private set; } + public bool Sail { get; private set; } /// /// Шаг перемещения автомобиля /// @@ -47,19 +43,17 @@ namespace Sailboat /// Вес автомобиля /// Основной цвет /// Дополнительный цвет - /// Признак наличия обвеса - /// Признак наличия антикрыла - /// Признак наличия гоночной полосы + /// Признак наличия усиленного корпуса + /// Признак наличия паруса public void Init(int speed, double weight, Color bodyColor, Color - additionalColor, bool bodyKit, bool wing, bool sportLine) + additionalColor, bool hull, bool sail) { Speed = speed; Weight = weight; BodyColor = bodyColor; AdditionalColor = additionalColor; - BodyKit = bodyKit; - Wing = wing; - SportLine = sportLine; + Hull = hull; + Sail = sail; } } } diff --git a/Sailboat/Sailboat/FormSailboat.Designer.cs b/Sailboat/Sailboat/FormSailboat.Designer.cs index fd83356..4226e22 100644 --- a/Sailboat/Sailboat/FormSailboat.Designer.cs +++ b/Sailboat/Sailboat/FormSailboat.Designer.cs @@ -43,7 +43,7 @@ this.pictureBoxSailboat.Dock = System.Windows.Forms.DockStyle.Fill; this.pictureBoxSailboat.Location = new System.Drawing.Point(0, 0); this.pictureBoxSailboat.Name = "pictureBoxSailboat"; - this.pictureBoxSailboat.Size = new System.Drawing.Size(1466, 741); + this.pictureBoxSailboat.Size = new System.Drawing.Size(882, 453); this.pictureBoxSailboat.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; this.pictureBoxSailboat.TabIndex = 0; this.pictureBoxSailboat.TabStop = false; @@ -51,7 +51,7 @@ // 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(12, 683); + this.buttonCreate.Location = new System.Drawing.Point(12, 395); this.buttonCreate.Name = "buttonCreate"; this.buttonCreate.Size = new System.Drawing.Size(127, 46); this.buttonCreate.TabIndex = 1; @@ -64,7 +64,7 @@ this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonLeft.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("buttonLeft.BackgroundImage"))); this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; - this.buttonLeft.Location = new System.Drawing.Point(1294, 691); + this.buttonLeft.Location = new System.Drawing.Point(710, 403); this.buttonLeft.Name = "buttonLeft"; this.buttonLeft.Size = new System.Drawing.Size(30, 30); this.buttonLeft.TabIndex = 2; @@ -76,7 +76,7 @@ this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonUp.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("buttonUp.BackgroundImage"))); this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; - this.buttonUp.Location = new System.Drawing.Point(1343, 646); + this.buttonUp.Location = new System.Drawing.Point(759, 358); this.buttonUp.Name = "buttonUp"; this.buttonUp.Size = new System.Drawing.Size(30, 30); this.buttonUp.TabIndex = 3; @@ -88,7 +88,7 @@ this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonRight.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("buttonRight.BackgroundImage"))); this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; - this.buttonRight.Location = new System.Drawing.Point(1393, 691); + this.buttonRight.Location = new System.Drawing.Point(809, 403); this.buttonRight.Name = "buttonRight"; this.buttonRight.Size = new System.Drawing.Size(30, 30); this.buttonRight.TabIndex = 4; @@ -100,7 +100,7 @@ this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonDown.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("buttonDown.BackgroundImage"))); this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; - this.buttonDown.Location = new System.Drawing.Point(1343, 691); + this.buttonDown.Location = new System.Drawing.Point(759, 403); this.buttonDown.Name = "buttonDown"; this.buttonDown.Size = new System.Drawing.Size(30, 30); this.buttonDown.TabIndex = 5; @@ -111,7 +111,7 @@ // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(1466, 741); + this.ClientSize = new System.Drawing.Size(882, 453); this.Controls.Add(this.buttonDown); this.Controls.Add(this.buttonRight); this.Controls.Add(this.buttonUp); diff --git a/Sailboat/Sailboat/FormSailboat.cs b/Sailboat/Sailboat/FormSailboat.cs index 3606e69..66139d6 100644 --- a/Sailboat/Sailboat/FormSailboat.cs +++ b/Sailboat/Sailboat/FormSailboat.cs @@ -23,14 +23,9 @@ namespace Sailboat { 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)), + _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); + Convert.ToBoolean(random.Next(0, 2)), pictureBoxSailboat.Width, pictureBoxSailboat.Height); _drawingSailboat.SetPosition(random.Next(10, 100), random.Next(10, 100)); Draw(); }