From a273654d6e871b5d3d5550e048afb7b1b7cacdac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=B9=D0=B4=D0=B0=D1=80?= Date: Mon, 3 Oct 2022 23:32:31 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=BE=D0=B4=D0=B2=D0=B8=D0=BD?= =?UTF-8?q?=D1=83=D1=82=D1=8B=D0=B9=20=D0=BE=D0=B1=D1=8A=D0=B5=D0=BA=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Battleship/Battleship/DrawningBattleship.cs | 34 +++++++--- .../Battleship/DrawningGunBattleship.cs | 65 +++++++++++++++++++ Battleship/Battleship/EntityGunBattleship.cs | 49 ++++++++++++++ .../Battleship/FormBattleship.Designer.cs | 13 ++++ Battleship/Battleship/FormBattleship.cs | 36 ++++++++-- 5 files changed, 180 insertions(+), 17 deletions(-) create mode 100644 Battleship/Battleship/DrawningGunBattleship.cs create mode 100644 Battleship/Battleship/EntityGunBattleship.cs diff --git a/Battleship/Battleship/DrawningBattleship.cs b/Battleship/Battleship/DrawningBattleship.cs index 4095cc7..5db407d 100644 --- a/Battleship/Battleship/DrawningBattleship.cs +++ b/Battleship/Battleship/DrawningBattleship.cs @@ -14,15 +14,15 @@ namespace Battleship /// /// Класс-сущность /// - public EntityBattleship Battleship { get; private set; } + public EntityBattleship Battleship { get; protected set; } /// /// Левая координата отрисовки боевого корабля /// - private float _startPosX; + protected float _startPosX; /// /// Верхняя кооридната отрисовки боевого корабля /// - private float _startPosY; + protected float _startPosY; /// /// Ширина окна отрисовки /// @@ -34,7 +34,7 @@ namespace Battleship /// /// Ширина отрисовки боевого корабля /// - private readonly int _battleshipWidth = 80; + private readonly int _battleshipWidth = 120; /// /// Высота отрисовки боевого корабля /// @@ -50,6 +50,20 @@ namespace Battleship Battleship = new EntityBattleship(speed, weight, bodyColor); } /// + /// Инициализация свойств + /// + /// Скорость + /// Вес военного корабля + /// Цвет корпуса корабля + /// Ширина отрисовки военного корабля + /// Высота отрисовки военного корабля + protected DrawningBattleship(int speed, float weight, Color bodyColor, int battleshipWidth, int battleshipHeight) : + this(speed, weight, bodyColor) + { + _battleshipWidth = battleshipWidth; + _battleshipHeight = battleshipHeight; + } + /// /// Установка позиции боевого корабля /// /// Координата X @@ -116,7 +130,7 @@ namespace Battleship /// Отрисовка боевого корабля /// /// - public void DrawTransport(Graphics g) + public virtual void DrawTransport(Graphics g) { if (_startPosX < 0 || _startPosY < 0 || !_pictureHeight.HasValue || !_pictureWidth.HasValue) @@ -130,10 +144,10 @@ namespace Battleship g.DrawRectangle(pen, _startPosX - 4, _startPosY + 4, 4, 10); g.DrawRectangle(pen, _startPosX - 4, _startPosY + 16 , 4, 10); g.DrawRectangle(pen, _startPosX + 40, _startPosY + 4, 10, 20); - g.DrawRectangle(pen, _startPosX , _startPosY, 70, 30); - PointF point_triangle_1 = new PointF(_startPosX + 70, _startPosY); - PointF point_triangle_2 = new PointF(_startPosX + 90, _startPosY + 15); - PointF point_triangle_3 = new PointF(_startPosX + 70, _startPosY + 30); + g.DrawRectangle(pen, _startPosX , _startPosY, 110, 30); + PointF point_triangle_1 = new PointF(_startPosX + 110, _startPosY); + PointF point_triangle_2 = new PointF(_startPosX + 130, _startPosY + 15); + PointF point_triangle_3 = new PointF(_startPosX + 110, _startPosY + 30); PointF[] assembled_triangle = { point_triangle_1, @@ -150,7 +164,7 @@ namespace Battleship //палуба корабля Brush br = new SolidBrush(Battleship?.BodyColor ?? Color.Black); - g.FillRectangle(br, _startPosX, _startPosY, 70, 30); + g.FillRectangle(br, _startPosX, _startPosY, 110, 30); g.FillPolygon(br, assembled_triangle); //отсек корабля diff --git a/Battleship/Battleship/DrawningGunBattleship.cs b/Battleship/Battleship/DrawningGunBattleship.cs new file mode 100644 index 0000000..dba9afa --- /dev/null +++ b/Battleship/Battleship/DrawningGunBattleship.cs @@ -0,0 +1,65 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Battleship +{ + internal class DrawningGunBattleship : DrawningBattleship + { + /// + /// Инициализация свойств + /// + /// Скорость + /// Вес военного корабля + /// Цвет корпуса корабля + /// Дополнительный цвет + /// Признак наличия отсека для ракет + /// Признак наличия орудийной башни + /// Признак наличия забора на корме + public DrawningGunBattleship(int speed, float weight, Color bodyColor, Color dopColor, bool compartmentRocket, bool gunTower, bool sternFence) : + base(speed, weight, bodyColor, 110, 60) + { + Battleship = new EntityGunBattleship(speed, weight, bodyColor, dopColor, compartmentRocket, gunTower, sternFence); + } + public override void DrawTransport(Graphics g) + { + if (Battleship is not EntityGunBattleship gunBattleship) + { + return; + } + + Pen pen = new(Color.Black); + Brush dopBrush = new SolidBrush(gunBattleship.DopColor); + + _startPosX += 10; + _startPosY += 5; + base.DrawTransport(g); + _startPosX -= 10; + _startPosY -= 5; + + if (gunBattleship.CompartmentRocket) + { + g.FillRectangle(dopBrush, _startPosX + 85, _startPosY + 10, 15, 20); + + g.DrawRectangle(pen, _startPosX + 85, _startPosY + 10, 15, 20); + } + + if (gunBattleship.GunTower) + { + g.FillEllipse(dopBrush, _startPosX + 105, _startPosY + 12, 17, 17); + g.FillRectangle(dopBrush, _startPosX + 121, _startPosY + 17, 11, 7); + + g.DrawEllipse(pen, _startPosX + 105, _startPosY + 12, 17, 17); + g.DrawRectangle(pen, _startPosX + 121, _startPosY + 17, 11, 7); + } + + if (gunBattleship.SternFence) + { + g.FillRectangle(dopBrush, _startPosX + 13, _startPosY + 8, 5, 25); + g.DrawRectangle(pen, _startPosX + 13, _startPosY + 8, 5, 25); + } + } + } +} diff --git a/Battleship/Battleship/EntityGunBattleship.cs b/Battleship/Battleship/EntityGunBattleship.cs new file mode 100644 index 0000000..e25fc13 --- /dev/null +++ b/Battleship/Battleship/EntityGunBattleship.cs @@ -0,0 +1,49 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Battleship +{ + /// + /// Класс-сущность "Военный корабль с оружием" + /// + internal class EntityGunBattleship : EntityBattleship + { + /// + /// Дополнительный цвет + /// + public Color DopColor { get; private set; } + /// + /// Признак наличия отсека для ракет + /// + public bool CompartmentRocket { get; private set; } + /// + /// Признак наличия орудийной башни + /// + public bool GunTower { get; private set; } + /// + /// Признак наличия забора на корме + /// + public bool SternFence { get; private set; } + /// + /// Инициализация свойств + /// + /// Скорость + /// Вес военного корабля + /// Цвет корпуса корабля + /// Дополнительный цвет + /// Признак наличия отсека для ракет + /// Признак наличия орудийной башни + /// Признак наличия забора на корме + public EntityGunBattleship(int speed, float weight, Color bodyColor, Color dopColor, bool compartmentRocket, bool gunTower, bool sternFence) : + base(speed, weight, bodyColor) + { + DopColor = dopColor; + CompartmentRocket = compartmentRocket; + GunTower = gunTower; + SternFence = sternFence; + } + } +} diff --git a/Battleship/Battleship/FormBattleship.Designer.cs b/Battleship/Battleship/FormBattleship.Designer.cs index 299bcfd..740f91d 100644 --- a/Battleship/Battleship/FormBattleship.Designer.cs +++ b/Battleship/Battleship/FormBattleship.Designer.cs @@ -38,6 +38,7 @@ this.buttonUp = new System.Windows.Forms.Button(); this.buttonRight = new System.Windows.Forms.Button(); this.buttonLeft = new System.Windows.Forms.Button(); + this.buttonCreateModif = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxBattleship)).BeginInit(); this.statusStripBattleship.SuspendLayout(); this.SuspendLayout(); @@ -138,12 +139,23 @@ this.buttonLeft.UseVisualStyleBackColor = true; this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click); // + // buttonCreateModif + // + this.buttonCreateModif.Location = new System.Drawing.Point(93, 397); + this.buttonCreateModif.Name = "buttonCreateModif"; + this.buttonCreateModif.Size = new System.Drawing.Size(110, 23); + this.buttonCreateModif.TabIndex = 7; + this.buttonCreateModif.Text = "Модификация"; + this.buttonCreateModif.UseVisualStyleBackColor = true; + this.buttonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_Click); + // // FormBattleship // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoSize = true; this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.buttonCreateModif); this.Controls.Add(this.buttonLeft); this.Controls.Add(this.buttonRight); this.Controls.Add(this.buttonUp); @@ -173,5 +185,6 @@ private Button buttonUp; private Button buttonRight; private Button buttonLeft; + private Button buttonCreateModif; } } \ No newline at end of file diff --git a/Battleship/Battleship/FormBattleship.cs b/Battleship/Battleship/FormBattleship.cs index 7d4e6bc..7305ba1 100644 --- a/Battleship/Battleship/FormBattleship.cs +++ b/Battleship/Battleship/FormBattleship.cs @@ -20,19 +20,26 @@ namespace Battleship pictureBoxBattleship.Image = bmp; } /// - /// "" - /// - /// - /// - - private void ButtonCreate_Click(object sender, EventArgs e) + /// + /// + private void SetData() { Random rnd = new(); - _battleship = new DrawningBattleship(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); _battleship.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxBattleship.Width, pictureBoxBattleship.Height); toolStripStatusLabelSpeed.Text = $": {_battleship.Battleship.Speed}"; toolStripStatusLabelWeight.Text = $": {_battleship.Battleship.Weight}"; toolStripStatusLabeBodylColor.Text = $": {_battleship.Battleship.BodyColor.Name}"; + } + /// + /// "" + /// + /// + /// + private void ButtonCreate_Click(object sender, EventArgs e) + { + Random rnd = new(); + _battleship = new DrawningBattleship(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); + SetData(); Draw(); } /// @@ -71,5 +78,20 @@ namespace Battleship _battleship?.ChangeBorders(pictureBoxBattleship.Width, pictureBoxBattleship.Height); Draw(); } + /// + /// "" + /// + /// + /// + private void ButtonCreateModif_Click(object sender, EventArgs e) + { + Random rnd = new(); + _battleship = new DrawningGunBattleship(rnd.Next(100, 300), rnd.Next(1000, 2000), + Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), + Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), + Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2))); + SetData(); + Draw(); + } } } \ No newline at end of file