diff --git a/Boats/Boats/DrawingBoat.cs b/Boats/Boats/DrawingBoat.cs index 5b33362..fb44500 100644 --- a/Boats/Boats/DrawingBoat.cs +++ b/Boats/Boats/DrawingBoat.cs @@ -14,15 +14,15 @@ namespace Boats /// /// Класс-сущность /// - public EntityBoat Boat { private set; get; } + public EntityBoat Boat { protected set; get; } /// /// Левая координата отрисовки лодки /// - private float _startPosX; + protected float _startPosX; /// /// Верхняя кооридната отрисовки лодки /// - private float _startPosY; + protected float _startPosY; /// /// Ширина окна отрисовки /// @@ -34,11 +34,11 @@ namespace Boats /// /// Ширина отрисовки лодки /// - private readonly int _boatWidth = 100; + protected readonly int _boatWidth = 100; /// /// Высота отрисовки лодки /// - private readonly int _boatHeight = 40; + protected readonly int _boatHeight = 40; /// /// Инициализация свойств /// @@ -50,6 +50,20 @@ namespace Boats Boat = new EntityBoat(speed, weight, bodyColor); } /// + /// Инициализация свойств + /// + /// Скорость + /// Вес лодки + /// Цвет корпуса + /// Ширина отрисовки лодки + /// Высота отрисовки лодки + protected DrawingBoat(int speed, float weight, Color bodyColor, int boatWidth, int boatHeight) : + this(speed, weight, bodyColor) + { + _boatWidth = boatWidth; + _boatHeight = boatHeight; + } + /// /// Установка позиции лодки /// /// Координата X @@ -113,7 +127,7 @@ namespace Boats /// Отрисовка лодки /// /// - public void DrawTransport(Graphics g) + public virtual void DrawTransport(Graphics g) { if (_startPosX < 0 || _startPosY < 0 || !_pictureHeight.HasValue || !_pictureWidth.HasValue) diff --git a/Boats/Boats/DrawingCatamaran.cs b/Boats/Boats/DrawingCatamaran.cs new file mode 100644 index 0000000..9e9142a --- /dev/null +++ b/Boats/Boats/DrawingCatamaran.cs @@ -0,0 +1,82 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Boats +{ + /// + /// Класс для отрисовки катамарана + /// + internal class DrawingCatamaran : DrawingBoat + { + /// + /// Инициализация свойств + /// + /// Скорость + /// Вес катамарана + /// Цвет корпуса + /// Дополнительный цвет + /// Признак наличия поплавков + /// Признак наличия паруса + public DrawingCatamaran(int speed, float weight, Color bodyColor, + Color dopColor, bool bobbers, bool sail) : + base(speed, weight, bodyColor, 110, 60) + { + Boat = new EntityCatamaran(speed, weight, bodyColor, dopColor, bobbers, sail); + } + /// + /// Метод для отрисовки катамарана + /// + /// + public override void DrawTransport(Graphics g) + { + if (Boat is not EntityCatamaran catamaran) + { + return; + } + Brush dopBrush = new SolidBrush(catamaran.DopColor); + + int bobbersWidth = _boatWidth / 4; + int bobbersHeight = _boatHeight / 5; + + base.DrawTransport(g); + + if (catamaran.Bobbers) + { + // Отрисовка верхних поплавков + g.FillRectangle(dopBrush, _startPosX, _startPosY, bobbersWidth, bobbersHeight); + g.DrawRectangle(Pens.Black, _startPosX, _startPosY, bobbersWidth, bobbersHeight); + g.DrawRectangle(Pens.Black, _startPosX + bobbersWidth / 4, _startPosY, bobbersWidth / 2, bobbersHeight); + + g.FillRectangle(dopBrush, _startPosX + _boatWidth / 2, _startPosY, _boatWidth / 4, bobbersHeight); + g.DrawRectangle(Pens.Black, _startPosX + _boatWidth / 2, _startPosY, _boatWidth / 4, bobbersHeight); + g.DrawRectangle(Pens.Black, _startPosX + _boatWidth / 2 + bobbersWidth / 4, _startPosY, bobbersWidth / 2, bobbersHeight); + + // Отрисовка нижних поплавков + g.FillRectangle(dopBrush, _startPosX, _startPosY + _boatHeight - bobbersHeight, bobbersWidth, bobbersHeight); + g.DrawRectangle(Pens.Black, _startPosX, _startPosY + _boatHeight - bobbersHeight, bobbersWidth, bobbersHeight); + g.DrawRectangle(Pens.Black, _startPosX + bobbersWidth / 4, _startPosY + _boatHeight - bobbersHeight, bobbersWidth / 2, bobbersHeight); + + g.FillRectangle(dopBrush, _startPosX + _boatWidth / 2, _startPosY + _boatHeight - bobbersHeight, bobbersWidth, bobbersHeight); + g.DrawRectangle(Pens.Black, _startPosX + _boatWidth / 2, _startPosY + _boatHeight - bobbersHeight, bobbersWidth, bobbersHeight); + g.DrawRectangle(Pens.Black, _startPosX + _boatWidth / 2 + bobbersWidth / 4, _startPosY + _boatHeight - bobbersHeight, bobbersWidth / 2, bobbersHeight); + } + + if (catamaran.Sail) + { + float downPointSailX = _startPosX + _boatWidth / 2 - _boatWidth / 8; + float downPointSailY = _startPosY + _boatHeight / 2 + _boatWidth / 8; + + PointF[] sailPoints = new PointF[3]; + sailPoints[0] = new PointF(downPointSailX, downPointSailY); + sailPoints[1] = new PointF(downPointSailX, _startPosY); + sailPoints[2] = new PointF(downPointSailX - _boatWidth / 4, downPointSailY - _boatHeight / 4); + // Отрисовка паруса + g.FillPolygon(dopBrush, sailPoints); + g.DrawPolygon(Pens.Black, sailPoints); + } + } + } +} diff --git a/Boats/Boats/EntityCatamaran.cs b/Boats/Boats/EntityCatamaran.cs new file mode 100644 index 0000000..4569a7f --- /dev/null +++ b/Boats/Boats/EntityCatamaran.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Boats +{ + internal class EntityCatamaran : EntityBoat + { + /// + /// Дополнительный цвет + /// + public Color DopColor { get; private set; } + /// + /// Признак наличия поплавков + /// + public bool Bobbers { get; private set; } + /// + /// Признак наличия паруса + /// + public bool Sail { get; private set; } + /// + /// Инициализация свойств + /// + /// Скорость + /// Вес катамарана + /// Цвет корпуса + /// Дополнительный цвет + /// Признак наличия поплавков + /// Признак наличия паруса + public EntityCatamaran(int speed, float weight, Color bodyColor, + Color dopColor, bool bobbers, bool sail) : + base(speed, weight, bodyColor) + { + DopColor = dopColor; + Bobbers = bobbers; + Sail = sail; + } + } +} diff --git a/Boats/Boats/FormBoat.Designer.cs b/Boats/Boats/FormBoat.Designer.cs index d17c12d..e7e7ab0 100644 --- a/Boats/Boats/FormBoat.Designer.cs +++ b/Boats/Boats/FormBoat.Designer.cs @@ -38,6 +38,7 @@ this.ButtonLeft = new System.Windows.Forms.Button(); this.ButtonRight = new System.Windows.Forms.Button(); this.ButtonDown = new System.Windows.Forms.Button(); + this.ButtonCreateModificate = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxBoat)).BeginInit(); this.statusStrip.SuspendLayout(); this.SuspendLayout(); @@ -143,11 +144,23 @@ this.ButtonDown.UseVisualStyleBackColor = true; this.ButtonDown.Click += new System.EventHandler(this.ButtonMove_Click); // + // ButtonCreateModificate + // + this.ButtonCreateModificate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.ButtonCreateModificate.Location = new System.Drawing.Point(138, 381); + this.ButtonCreateModificate.Name = "ButtonCreateModificate"; + this.ButtonCreateModificate.Size = new System.Drawing.Size(117, 29); + this.ButtonCreateModificate.TabIndex = 7; + this.ButtonCreateModificate.Text = "Модификация"; + this.ButtonCreateModificate.UseVisualStyleBackColor = true; + this.ButtonCreateModificate.Click += new System.EventHandler(this.ButtonCreateModificate_Click); + // // FormBoat // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.ButtonCreateModificate); this.Controls.Add(this.ButtonDown); this.Controls.Add(this.ButtonRight); this.Controls.Add(this.ButtonLeft); @@ -177,5 +190,6 @@ private Button ButtonLeft; private Button ButtonRight; private Button ButtonDown; + private Button ButtonCreateModificate; } } \ No newline at end of file diff --git a/Boats/Boats/FormBoat.cs b/Boats/Boats/FormBoat.cs index f858665..2599211 100644 --- a/Boats/Boats/FormBoat.cs +++ b/Boats/Boats/FormBoat.cs @@ -18,6 +18,22 @@ namespace Boats InitializeComponent(); } /// + /// Метод установки данных + /// + private void SetData() + { + Random rnd = new Random(); + _boat.SetPosition( + rnd.Next(10, 100), + rnd.Next(10, 100), + pictureBoxBoat.Width, + pictureBoxBoat.Height + ); + toolStripStatusLabelSpeed.Text = $"Скорость: {_boat.Boat.Speed}"; + toolStripStatusLabelWeight.Text = $"Вес: {_boat.Boat.Weight}"; + toolStripStatusLabelBodyColor.Text = $"Цвет: {_boat.Boat.BodyColor.Name}"; + } + /// /// Метод прорисовки лодки /// private void Draw() @@ -41,15 +57,7 @@ namespace Boats Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)) ); - _boat.SetPosition( - rnd.Next(10, 100), - rnd.Next(10, 100), - pictureBoxBoat.Width, - pictureBoxBoat.Height - ); - toolStripStatusLabelSpeed.Text = $"Скорость: {_boat.Boat.Speed}"; - toolStripStatusLabelWeight.Text = $"Вес: {_boat.Boat.Weight}"; - toolStripStatusLabelBodyColor.Text = $"Цвет: {_boat.Boat.BodyColor.Name}"; + SetData(); Draw(); } /// @@ -88,5 +96,24 @@ namespace Boats _boat?.ChangeBorders(pictureBoxBoat.Width, pictureBoxBoat.Height); Draw(); } + /// + /// Обработка нажатия кнопки "Модификация" + /// + /// + /// + private void ButtonCreateModificate_Click(object sender, EventArgs e) + { + Random rnd = new Random(); + _boat = new DrawingCatamaran( + rnd.Next(100, 300), + rnd.Next(1000, 3000), + Color.FromArgb(rnd.Next(0, 255), rnd.Next(0, 255), rnd.Next(0, 255)), + Color.FromArgb(rnd.Next(0, 255), rnd.Next(0, 255), rnd.Next(0, 255)), + Convert.ToBoolean(rnd.Next(0, 2)), + Convert.ToBoolean(rnd.Next(0, 2)) + ); + SetData(); + Draw(); + } } }