From 629f4919c079c5054e7ae2be20a3f79502e38a58 Mon Sep 17 00:00:00 2001 From: Hells Hound Date: Sat, 17 Sep 2022 11:17:47 +0400 Subject: [PATCH 1/9] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D1=85=D0=BE=D0=B4?= =?UTF-8?q?=20=D0=BD=D0=B0=20=D0=BA=D0=BE=D0=BD=D1=81=D1=82=D1=80=D1=83?= =?UTF-8?q?=D0=BA=D1=82=D0=BE=D1=80=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AircraftCarrier/AircraftCarrier/DrawingWarship.cs | 5 ++--- AircraftCarrier/AircraftCarrier/EntityWarship.cs | 2 +- .../AircraftCarrier/FormWarship.Designer.cs | 14 +++++++------- AircraftCarrier/AircraftCarrier/FormWarship.cs | 3 +-- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/AircraftCarrier/AircraftCarrier/DrawingWarship.cs b/AircraftCarrier/AircraftCarrier/DrawingWarship.cs index e5fdddb..a97c5df 100644 --- a/AircraftCarrier/AircraftCarrier/DrawingWarship.cs +++ b/AircraftCarrier/AircraftCarrier/DrawingWarship.cs @@ -45,10 +45,9 @@ namespace AircraftCarrier /// Скорость /// Вес военного корабля /// Цвет главной палубы - public void Init(int speed, float weight, Color bodyColor) + public DrawingWarship(int speed, float weight, Color bodyColor) { - Warship = new EntityWarship(); - Warship.Init(speed, weight, bodyColor); + Warship = new EntityWarship(speed, weight, bodyColor); } /// /// Установка позиции военного корабля diff --git a/AircraftCarrier/AircraftCarrier/EntityWarship.cs b/AircraftCarrier/AircraftCarrier/EntityWarship.cs index 2c0f4f5..88b6a83 100644 --- a/AircraftCarrier/AircraftCarrier/EntityWarship.cs +++ b/AircraftCarrier/AircraftCarrier/EntityWarship.cs @@ -33,7 +33,7 @@ namespace AircraftCarrier /// /// /// - public void Init(int speed, float weight, Color bodyColor) + public EntityWarship(int speed, float weight, Color bodyColor) { Random rnd = new(); Speed = speed <= 0 ? rnd.Next(50, 150) : speed; diff --git a/AircraftCarrier/AircraftCarrier/FormWarship.Designer.cs b/AircraftCarrier/AircraftCarrier/FormWarship.Designer.cs index 4e7f9f8..293e458 100644 --- a/AircraftCarrier/AircraftCarrier/FormWarship.Designer.cs +++ b/AircraftCarrier/AircraftCarrier/FormWarship.Designer.cs @@ -47,7 +47,7 @@ this.pictureBoxWarship.Dock = System.Windows.Forms.DockStyle.Fill; this.pictureBoxWarship.Location = new System.Drawing.Point(0, 0); this.pictureBoxWarship.Name = "pictureBoxWarship"; - this.pictureBoxWarship.Size = new System.Drawing.Size(510, 426); + this.pictureBoxWarship.Size = new System.Drawing.Size(768, 426); this.pictureBoxWarship.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; this.pictureBoxWarship.TabIndex = 0; this.pictureBoxWarship.TabStop = false; @@ -61,7 +61,7 @@ this.toolStripStatusLabelBodyColor}); this.statusStrip.Location = new System.Drawing.Point(0, 426); this.statusStrip.Name = "statusStrip"; - this.statusStrip.Size = new System.Drawing.Size(510, 22); + this.statusStrip.Size = new System.Drawing.Size(768, 22); this.statusStrip.TabIndex = 1; // // toolStripStatusLabelSpeed @@ -98,7 +98,7 @@ this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonDown.BackgroundImage = global::AircraftCarrier.Properties.Resources.ArrowDown; this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonDown.Location = new System.Drawing.Point(428, 386); + this.buttonDown.Location = new System.Drawing.Point(686, 386); this.buttonDown.Name = "buttonDown"; this.buttonDown.Size = new System.Drawing.Size(30, 30); this.buttonDown.TabIndex = 3; @@ -111,7 +111,7 @@ this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonUp.BackgroundImage = global::AircraftCarrier.Properties.Resources.ArrowUp; this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonUp.Location = new System.Drawing.Point(428, 350); + this.buttonUp.Location = new System.Drawing.Point(686, 350); this.buttonUp.Name = "buttonUp"; this.buttonUp.Size = new System.Drawing.Size(30, 30); this.buttonUp.TabIndex = 4; @@ -124,7 +124,7 @@ this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonLeft.BackgroundImage = global::AircraftCarrier.Properties.Resources.ArrowLeft; this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonLeft.Location = new System.Drawing.Point(392, 386); + this.buttonLeft.Location = new System.Drawing.Point(650, 386); this.buttonLeft.Name = "buttonLeft"; this.buttonLeft.Size = new System.Drawing.Size(30, 30); this.buttonLeft.TabIndex = 5; @@ -137,7 +137,7 @@ this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonRight.BackgroundImage = global::AircraftCarrier.Properties.Resources.ArrowRight; this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonRight.Location = new System.Drawing.Point(464, 386); + this.buttonRight.Location = new System.Drawing.Point(722, 386); this.buttonRight.Name = "buttonRight"; this.buttonRight.Size = new System.Drawing.Size(30, 30); this.buttonRight.TabIndex = 6; @@ -149,7 +149,7 @@ // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(510, 448); + this.ClientSize = new System.Drawing.Size(768, 448); this.Controls.Add(this.buttonRight); this.Controls.Add(this.buttonLeft); this.Controls.Add(this.buttonUp); diff --git a/AircraftCarrier/AircraftCarrier/FormWarship.cs b/AircraftCarrier/AircraftCarrier/FormWarship.cs index 3866bc7..00708c3 100644 --- a/AircraftCarrier/AircraftCarrier/FormWarship.cs +++ b/AircraftCarrier/AircraftCarrier/FormWarship.cs @@ -25,8 +25,7 @@ namespace AircraftCarrier private void ButtonCreate_Click(object sender, EventArgs e) { Random rnd = new(); - _warship = new DrawingWarship(); - _warship.Init(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); + _warship = new DrawingWarship(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); _warship.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxWarship.Width, pictureBoxWarship.Height); toolStripStatusLabelSpeed.Text = $": {_warship.Warship.Speed}"; toolStripStatusLabelWeight.Text = $": {_warship.Warship.Weight}"; -- 2.25.1 From 7f1f1ca3e4d798e0b256c8c3deb2ff00d45e5004 Mon Sep 17 00:00:00 2001 From: Hells Hound Date: Sun, 18 Sep 2022 21:41:23 +0400 Subject: [PATCH 2/9] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=20DrawingAircraftCarrie?= =?UTF-8?q?r?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AircraftCarrier/DrawingAircraftCarrier.cs | 33 +++++++++++++ .../AircraftCarrier/DrawingWarship.cs | 19 +++++++- .../AircraftCarrier/EntityAircraftCarrier.cs | 46 +++++++++++++++++++ 3 files changed, 96 insertions(+), 2 deletions(-) create mode 100644 AircraftCarrier/AircraftCarrier/DrawingAircraftCarrier.cs create mode 100644 AircraftCarrier/AircraftCarrier/EntityAircraftCarrier.cs diff --git a/AircraftCarrier/AircraftCarrier/DrawingAircraftCarrier.cs b/AircraftCarrier/AircraftCarrier/DrawingAircraftCarrier.cs new file mode 100644 index 0000000..f85e406 --- /dev/null +++ b/AircraftCarrier/AircraftCarrier/DrawingAircraftCarrier.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AircraftCarrier +{ + internal class DrawingAircraftCarrier : DrawingWarship + { + /// + /// Инициализация свойств + /// + /// Скорость + /// Вес автомобиля + /// Цвет кузова + /// Дополнительный цвет + /// Признак наличия обвеса + /// Признак наличия антикрыла + /// Признак наличия гоночной полосы + public DrawingAircraftCarrier(int speed, float weight, Color bodyColor, Color dopColor, bool bodyKit, bool wing, bool sportLine) : + base(speed, weight, bodyColor, 110, 60) + { + Warship = new EntityAircraftCarrier(speed, weight, bodyColor, dopColor, bodyKit, wing, sportLine); + } + + public override void DrawTransport(Graphics g) + { + base.DrawTransport(g); + } + } + +} diff --git a/AircraftCarrier/AircraftCarrier/DrawingWarship.cs b/AircraftCarrier/AircraftCarrier/DrawingWarship.cs index a97c5df..0f377aa 100644 --- a/AircraftCarrier/AircraftCarrier/DrawingWarship.cs +++ b/AircraftCarrier/AircraftCarrier/DrawingWarship.cs @@ -14,7 +14,7 @@ namespace AircraftCarrier /// /// Класс-сущность /// - public EntityWarship Warship { get; private set; } + public EntityWarship Warship { get; protected set; } /// /// Левая координата отрисовки военного корабля /// @@ -49,6 +49,21 @@ namespace AircraftCarrier { Warship = new EntityWarship(speed, weight, bodyColor); } + + /// + /// Инициализация свойств + /// + /// Скорость + /// Вес военного корабля + /// Цвет главной палубы + /// Ширина отрисовки автомобиля + /// Высота отрисовки автомобиля + protected DrawingWarship(int speed, float weight, Color bodyColor, int warshipWidth, int warshipHeight) : + this(speed, weight, bodyColor) + { + _warshipWidth = warshipWidth; + _warshipHeight = warshipHeight; + } /// /// Установка позиции военного корабля /// @@ -127,7 +142,7 @@ namespace AircraftCarrier /// Отрисовка военного корабля /// /// - public void DrawTransport(Graphics g) + public virtual void DrawTransport(Graphics g) { if (_startPosX < 0 || _startPosY < 0 || !_pictureHeight.HasValue || !_pictureWidth.HasValue) diff --git a/AircraftCarrier/AircraftCarrier/EntityAircraftCarrier.cs b/AircraftCarrier/AircraftCarrier/EntityAircraftCarrier.cs new file mode 100644 index 0000000..e99bdbd --- /dev/null +++ b/AircraftCarrier/AircraftCarrier/EntityAircraftCarrier.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AircraftCarrier +{ + internal class EntityAircraftCarrier : EntityWarship + { + /// + /// Дополнительный цвет + /// + public Color DopColor { get; private set; } + /// + /// Признак наличия обвеса + /// + public bool BodyKit { get; private set; } + /// + /// Признак наличия антикрыла + /// + public bool Wing { get; private set; } + /// + /// Признак наличия гоночной полосы + /// + public bool SportLine { get; private set; } + /// + /// Инициализация свойств + /// + /// Скорость + /// Вес автомобиля + /// Цвет кузова + /// Дополнительный цвет + /// Признак наличия обвеса + /// Признак наличия антикрыла + /// Признак наличия гоночной полосы + public EntityAircraftCarrier(int speed, float weight, Color bodyColor, Color dopColor, bool bodyKit, bool wing, bool sportLine) : + base(speed, weight, bodyColor) + { + DopColor = dopColor; + BodyKit = bodyKit; + Wing = wing; + SportLine = sportLine; + } + } +} -- 2.25.1 From 01cffb5f90fa8bcaf2f683510537679fc8551e4f Mon Sep 17 00:00:00 2001 From: Hells Hound Date: Tue, 20 Sep 2022 18:26:55 +0400 Subject: [PATCH 3/9] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=20DrawingAircraftCarrie?= =?UTF-8?q?r?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AircraftCarrier/DrawingAircraftCarrier.cs | 9 ++++++ .../AircraftCarrier/DrawingWarship.cs | 24 +++++++------- .../AircraftCarrier/FormWarship.Designer.cs | 13 ++++++++ .../AircraftCarrier/FormWarship.cs | 32 ++++++++++++++++--- 4 files changed, 62 insertions(+), 16 deletions(-) diff --git a/AircraftCarrier/AircraftCarrier/DrawingAircraftCarrier.cs b/AircraftCarrier/AircraftCarrier/DrawingAircraftCarrier.cs index f85e406..bf56d6c 100644 --- a/AircraftCarrier/AircraftCarrier/DrawingAircraftCarrier.cs +++ b/AircraftCarrier/AircraftCarrier/DrawingAircraftCarrier.cs @@ -26,6 +26,15 @@ namespace AircraftCarrier public override void DrawTransport(Graphics g) { + if(Warship is not EntityAircraftCarrier aircraftCarrier) + { + return; + } + + Pen pen = new(Color.Black); + Brush dopBrush = new SolidBrush(aircraftCarrier.DopColor); + + base.DrawTransport(g); } } diff --git a/AircraftCarrier/AircraftCarrier/DrawingWarship.cs b/AircraftCarrier/AircraftCarrier/DrawingWarship.cs index 0f377aa..ade4a9f 100644 --- a/AircraftCarrier/AircraftCarrier/DrawingWarship.cs +++ b/AircraftCarrier/AircraftCarrier/DrawingWarship.cs @@ -34,7 +34,7 @@ namespace AircraftCarrier /// /// Ширина отрисовки военного корабля /// - private readonly int _warshipWidth = 94; + private readonly int _warshipWidth = 114; /// /// Высота отрисовки военного корабля /// @@ -152,11 +152,11 @@ namespace AircraftCarrier Pen pen = new(Color.Black); //границы военного корабля - PointF point1 = new PointF(_startPosX, _startPosY); - PointF point2 = new PointF(_startPosX + 74, _startPosY); - PointF point3 = new PointF(_startPosX + 94, _startPosY + 20); - PointF point4 = new PointF(_startPosX + 74, _startPosY + 40); - PointF point5 = new PointF(_startPosX, _startPosY + 40); + PointF point1 = new PointF(_startPosX + 4, _startPosY); + PointF point2 = new PointF(_startPosX + 94, _startPosY); + PointF point3 = new PointF(_startPosX + 114, _startPosY + 20); + PointF point4 = new PointF(_startPosX + 94, _startPosY + 40); + PointF point5 = new PointF(_startPosX + 4, _startPosY + 40); PointF[] curvePoints = { @@ -170,18 +170,18 @@ namespace AircraftCarrier //мачта Brush brWhite = new SolidBrush(Color.White); - g.FillEllipse(brWhite, _startPosX + 59, _startPosY + 13, 15, 15); + g.FillEllipse(brWhite, _startPosX + 79, _startPosY + 13, 15, 15); //границы мачты - g.DrawEllipse(pen, _startPosX + 59, _startPosY + 13, 15, 15); + g.DrawEllipse(pen, _startPosX + 79, _startPosY + 13, 15, 15); //палуба - g.FillRectangle(brWhite, _startPosX + 44, _startPosY + 10, 10, 20); - g.FillRectangle(brWhite, _startPosX + 24, _startPosY + 15, 20, 10); + g.FillRectangle(brWhite, _startPosX + 64, _startPosY + 10, 10, 20); + g.FillRectangle(brWhite, _startPosX + 44, _startPosY + 15, 20, 10); //границы палуба - g.DrawRectangle(pen, _startPosX + 44, _startPosY + 10, 10, 20); - g.DrawRectangle(pen, _startPosX + 24, _startPosY + 15, 20, 10); + g.DrawRectangle(pen, _startPosX + 64, _startPosY + 10, 10, 20); + g.DrawRectangle(pen, _startPosX + 44, _startPosY + 15, 20, 10); //двигатели Brush brBlack = new SolidBrush(Color.Black); diff --git a/AircraftCarrier/AircraftCarrier/FormWarship.Designer.cs b/AircraftCarrier/AircraftCarrier/FormWarship.Designer.cs index 293e458..854abe8 100644 --- a/AircraftCarrier/AircraftCarrier/FormWarship.Designer.cs +++ b/AircraftCarrier/AircraftCarrier/FormWarship.Designer.cs @@ -38,6 +38,7 @@ this.buttonUp = new System.Windows.Forms.Button(); this.buttonLeft = new System.Windows.Forms.Button(); this.buttonRight = new System.Windows.Forms.Button(); + this.buttonCreateModif = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxWarship)).BeginInit(); this.statusStrip.SuspendLayout(); this.SuspendLayout(); @@ -145,11 +146,22 @@ this.buttonRight.UseVisualStyleBackColor = true; this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click); // + // buttonCreateModif + // + this.buttonCreateModif.Location = new System.Drawing.Point(93, 393); + this.buttonCreateModif.Name = "buttonCreateModif"; + this.buttonCreateModif.Size = new System.Drawing.Size(92, 23); + this.buttonCreateModif.TabIndex = 7; + this.buttonCreateModif.Text = "Modification"; + this.buttonCreateModif.UseVisualStyleBackColor = true; + this.buttonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_Click); + // // FormWarship // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(768, 448); + this.Controls.Add(this.buttonCreateModif); this.Controls.Add(this.buttonRight); this.Controls.Add(this.buttonLeft); this.Controls.Add(this.buttonUp); @@ -179,5 +191,6 @@ private Button buttonUp; private Button buttonLeft; private Button buttonRight; + private Button buttonCreateModif; } } \ No newline at end of file diff --git a/AircraftCarrier/AircraftCarrier/FormWarship.cs b/AircraftCarrier/AircraftCarrier/FormWarship.cs index 00708c3..dede81b 100644 --- a/AircraftCarrier/AircraftCarrier/FormWarship.cs +++ b/AircraftCarrier/AircraftCarrier/FormWarship.cs @@ -18,6 +18,17 @@ namespace AircraftCarrier pictureBoxWarship.Image = bmp; } /// + /// + /// + private void SetData() + { + Random rnd = new(); + _warship.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxWarship.Width, pictureBoxWarship.Height); + toolStripStatusLabelSpeed.Text = $": {_warship.Warship.Speed}"; + toolStripStatusLabelWeight.Text = $": {_warship.Warship.Weight}"; + toolStripStatusLabelBodyColor.Text = $": {_warship.Warship.BodyColor.Name}"; + } + /// /// "Create" /// /// @@ -26,10 +37,7 @@ namespace AircraftCarrier { Random rnd = new(); _warship = new DrawingWarship(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); - _warship.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxWarship.Width, pictureBoxWarship.Height); - toolStripStatusLabelSpeed.Text = $": {_warship.Warship.Speed}"; - toolStripStatusLabelWeight.Text = $": {_warship.Warship.Weight}"; - toolStripStatusLabelBodyColor.Text = $": {_warship.Warship.BodyColor.Name}"; + SetData(); Draw(); } @@ -63,5 +71,21 @@ namespace AircraftCarrier _warship?.ChangeBorders(pictureBoxWarship.Width,pictureBoxWarship.Height); Draw(); } + /// + /// "Modification" + /// + /// + /// + private void ButtonCreateModif_Click(object sender, EventArgs e) + { + Random rnd = new(); + _warship = new DrawingAircraftCarrier(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 -- 2.25.1 From 098ef0c921a8bd30ee9131dd85fd9fce8753d192 Mon Sep 17 00:00:00 2001 From: Hells Hound Date: Tue, 20 Sep 2022 23:20:22 +0400 Subject: [PATCH 4/9] =?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 --- .../AircraftCarrier/DrawingAircraftCarrier.cs | 60 +++++++++++++++- .../AircraftCarrier/DrawingWarship.cs | 72 ++++++++----------- .../AircraftCarrier/EntityAircraftCarrier.cs | 14 ++-- 3 files changed, 95 insertions(+), 51 deletions(-) diff --git a/AircraftCarrier/AircraftCarrier/DrawingAircraftCarrier.cs b/AircraftCarrier/AircraftCarrier/DrawingAircraftCarrier.cs index bf56d6c..1672a7a 100644 --- a/AircraftCarrier/AircraftCarrier/DrawingAircraftCarrier.cs +++ b/AircraftCarrier/AircraftCarrier/DrawingAircraftCarrier.cs @@ -33,9 +33,67 @@ namespace AircraftCarrier Pen pen = new(Color.Black); Brush dopBrush = new SolidBrush(aircraftCarrier.DopColor); + Brush brGray = new SolidBrush(Color.Gray); + Brush brRed = new SolidBrush(Color.Red); + Brush br = new SolidBrush(Warship?.BodyColor ?? Color.White); + if (aircraftCarrier.BodyKit) + { + //боковая площадка + PointF pointAircraftCarrier1 = new PointF(_startPosX + 94, _startPosY + 40); + PointF pointAircraftCarrier2 = new PointF(_startPosX + 74, _startPosY + 60); + PointF pointAircraftCarrier3 = new PointF(_startPosX + 24, _startPosY + 60); + PointF pointAircraftCarrier4 = new PointF(_startPosX + 4, _startPosY + 40); - base.DrawTransport(g); + PointF[] PointsAircraftCarrier = + { + pointAircraftCarrier1, pointAircraftCarrier2, pointAircraftCarrier3, pointAircraftCarrier4 + }; + g.FillPolygon(br, PointsAircraftCarrier); + g.DrawPolygon(pen, PointsAircraftCarrier); + + //полоса + PointF pontStartLine1 = new PointF(_startPosX + 4, _startPosY); + PointF pontStartLine2 = new PointF(_startPosX + 15, _startPosY); + PointF pontStartLine3 = new PointF(_startPosX + 74, _startPosY + 60); + PointF pontStartLine4 = new PointF(_startPosX + 59, _startPosY + 60); + + PointF[] PointsStartLine = + { + pontStartLine1, pontStartLine2, pontStartLine3, pontStartLine4 + }; + g.FillPolygon(brGray, PointsStartLine); + g.DrawPolygon(pen, PointsStartLine); + } + + if (aircraftCarrier.SuperEngine) + { + g.FillEllipse(brRed, _startPosX, _startPosY, 10, 10); + g.DrawEllipse(pen, _startPosX, _startPosY, 10, 10); + + g.FillEllipse(brRed, _startPosX, _startPosY + 10, 10, 10); + g.DrawEllipse(pen, _startPosX, _startPosY + 10, 10, 10); + + g.FillEllipse(brRed, _startPosX, _startPosY + 18, 10, 10); + g.DrawEllipse(pen, _startPosX, _startPosY + 18, 10, 10); + + g.FillEllipse(brRed, _startPosX, _startPosY + 30, 10, 10); + g.DrawEllipse(pen, _startPosX, _startPosY + 30, 10, 10); + } + + base.DrawTransport(g); + + if (aircraftCarrier.Сabin) + { + g.FillEllipse(brGray, _startPosX + 10, _startPosY + 15, 10, 10); + g.DrawEllipse(pen, _startPosX + 10, _startPosY + 15, 10, 10); + + g.FillEllipse(brGray, _startPosX + 20, _startPosY + 15, 10, 10); + g.DrawEllipse(pen, _startPosX + 20, _startPosY + 15, 10, 10); + + g.FillRectangle(brGray, _startPosX + 15, _startPosY + 15, 10, 10); + g.DrawRectangle(pen, _startPosX + 15, _startPosY + 15, 10, 10); + } } } diff --git a/AircraftCarrier/AircraftCarrier/DrawingWarship.cs b/AircraftCarrier/AircraftCarrier/DrawingWarship.cs index ade4a9f..01c3e18 100644 --- a/AircraftCarrier/AircraftCarrier/DrawingWarship.cs +++ b/AircraftCarrier/AircraftCarrier/DrawingWarship.cs @@ -18,11 +18,11 @@ namespace AircraftCarrier /// /// Левая координата отрисовки военного корабля /// - private float _startPosX; + protected float _startPosX; /// /// Верхняя кооридната отрисовки военного корабля /// - private float _startPosY; + protected float _startPosY; /// /// Ширина окна отрисовки /// @@ -73,27 +73,14 @@ namespace AircraftCarrier /// public void SetPosition(int x, int y, int width, int height) { - _startPosX = x; - _startPosY = y; - _pictureWidth = width; - _pictureHeight = height; - - if (width < _warshipWidth) + if (width >= x + _warshipWidth && height >= y + _warshipHeight && x >= 0 && y >= 0) { - width = _warshipWidth; - } - if (height < _warshipHeight) - { - height = _warshipHeight; - } - if(x + _warshipWidth > width) - { - _startPosX -= x + _warshipWidth - width; - } - if (y + _warshipHeight > height) - { - _pictureHeight -= y + _warshipHeight - height; + _startPosX = x; + _startPosY = y; + _pictureWidth = width; + _pictureHeight = height; } + else return; } /// /// Изменение направления пермещения @@ -116,14 +103,14 @@ namespace AircraftCarrier break; //влево case Direction.Left: - if(_startPosX - Warship.Step > 0) + if(_startPosX - Warship.Step >= 0) { _startPosX -= Warship.Step; } break; //вверх case Direction.Up: - if (_startPosY - Warship.Step > 0) + if (_startPosY - Warship.Step >= 0) { _startPosY -= Warship.Step; } @@ -150,34 +137,33 @@ namespace AircraftCarrier return; } Pen pen = new(Color.Black); - - //границы военного корабля - PointF point1 = new PointF(_startPosX + 4, _startPosY); - PointF point2 = new PointF(_startPosX + 94, _startPosY); - PointF point3 = new PointF(_startPosX + 114, _startPosY + 20); - PointF point4 = new PointF(_startPosX + 94, _startPosY + 40); - PointF point5 = new PointF(_startPosX + 4, _startPosY + 40); - - PointF[] curvePoints = - { - point1, point2, point3, point4, point5 - }; - g.DrawPolygon(pen, curvePoints); + Brush brOrange = new SolidBrush(Color.Orange); + Brush brPurple = new SolidBrush(Color.RebeccaPurple); //главная палуба Brush br = new SolidBrush(Warship?.BodyColor ?? Color.White); - g.FillPolygon(br, curvePoints); + PointF pointWarship1 = new PointF(_startPosX + 4, _startPosY); + PointF pointWarship2 = new PointF(_startPosX + 94, _startPosY); + PointF pointWarship3 = new PointF(_startPosX + 114, _startPosY + 20); + PointF pointWarship4 = new PointF(_startPosX + 94, _startPosY + 40); + PointF pointWarship5 = new PointF(_startPosX + 4, _startPosY + 40); - //мачта - Brush brWhite = new SolidBrush(Color.White); - g.FillEllipse(brWhite, _startPosX + 79, _startPosY + 13, 15, 15); + PointF[] PointsWarship = + { + pointWarship1, pointWarship2, pointWarship3, pointWarship4, pointWarship5 + }; + g.FillPolygon(br, PointsWarship); + g.DrawPolygon(pen, PointsWarship); + + //мачта + g.FillEllipse(brOrange, _startPosX + 79, _startPosY + 13, 15, 15); //границы мачты g.DrawEllipse(pen, _startPosX + 79, _startPosY + 13, 15, 15); - //палуба - g.FillRectangle(brWhite, _startPosX + 64, _startPosY + 10, 10, 20); - g.FillRectangle(brWhite, _startPosX + 44, _startPosY + 15, 20, 10); + //палуба + g.FillRectangle(brPurple, _startPosX + 64, _startPosY + 10, 10, 20); + g.FillRectangle(brPurple, _startPosX + 44, _startPosY + 15, 20, 10); //границы палуба g.DrawRectangle(pen, _startPosX + 64, _startPosY + 10, 10, 20); diff --git a/AircraftCarrier/AircraftCarrier/EntityAircraftCarrier.cs b/AircraftCarrier/AircraftCarrier/EntityAircraftCarrier.cs index e99bdbd..621ddc8 100644 --- a/AircraftCarrier/AircraftCarrier/EntityAircraftCarrier.cs +++ b/AircraftCarrier/AircraftCarrier/EntityAircraftCarrier.cs @@ -13,17 +13,17 @@ namespace AircraftCarrier /// public Color DopColor { get; private set; } /// - /// Признак наличия обвеса + /// Признак наличия боковой площадки /// public bool BodyKit { get; private set; } /// - /// Признак наличия антикрыла + /// Признак наличия рубки /// - public bool Wing { get; private set; } + public bool Сabin { get; private set; } /// - /// Признак наличия гоночной полосы + /// Признак наличия усиленного двигателя /// - public bool SportLine { get; private set; } + public bool SuperEngine { get; private set; } /// /// Инициализация свойств /// @@ -39,8 +39,8 @@ namespace AircraftCarrier { DopColor = dopColor; BodyKit = bodyKit; - Wing = wing; - SportLine = sportLine; + Сabin = wing; + SuperEngine = sportLine; } } } -- 2.25.1 From 8b1391adee2bd1da4eb8b57e640b24c8fb86a886 Mon Sep 17 00:00:00 2001 From: Hells Hound Date: Tue, 20 Sep 2022 23:42:48 +0400 Subject: [PATCH 5/9] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=B8=D0=BD=D1=82=D0=B5=D1=80=D1=84=D0=B5?= =?UTF-8?q?=D0=B9=D1=81=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AircraftCarrier/DrawingAircraftCarrier.cs | 16 +++---- .../AircraftCarrier/DrawingObjectWarship.cs | 39 +++++++++++++++++ .../AircraftCarrier/DrawingWarship.cs | 8 ++++ .../AircraftCarrier/EntityAircraftCarrier.cs | 16 +++---- .../AircraftCarrier/IDrawingObject.cs | 43 +++++++++++++++++++ 5 files changed, 106 insertions(+), 16 deletions(-) create mode 100644 AircraftCarrier/AircraftCarrier/DrawingObjectWarship.cs create mode 100644 AircraftCarrier/AircraftCarrier/IDrawingObject.cs diff --git a/AircraftCarrier/AircraftCarrier/DrawingAircraftCarrier.cs b/AircraftCarrier/AircraftCarrier/DrawingAircraftCarrier.cs index 1672a7a..cea3477 100644 --- a/AircraftCarrier/AircraftCarrier/DrawingAircraftCarrier.cs +++ b/AircraftCarrier/AircraftCarrier/DrawingAircraftCarrier.cs @@ -12,16 +12,16 @@ namespace AircraftCarrier /// Инициализация свойств /// /// Скорость - /// Вес автомобиля - /// Цвет кузова + /// Вес военного корабля + /// Цвет основной палубы /// Дополнительный цвет - /// Признак наличия обвеса - /// Признак наличия антикрыла - /// Признак наличия гоночной полосы - public DrawingAircraftCarrier(int speed, float weight, Color bodyColor, Color dopColor, bool bodyKit, bool wing, bool sportLine) : - base(speed, weight, bodyColor, 110, 60) + /// Признак наличия боковой площадки + /// Признак наличия рубки + /// Признак наличия усиленного двигателя + public DrawingAircraftCarrier(int speed, float weight, Color bodyColor, Color dopColor, bool bodyKit, bool сabin, bool superEngine) : + base(speed, weight, bodyColor, 114, 40) { - Warship = new EntityAircraftCarrier(speed, weight, bodyColor, dopColor, bodyKit, wing, sportLine); + Warship = new EntityAircraftCarrier(speed, weight, bodyColor, dopColor, bodyKit, сabin, superEngine); } public override void DrawTransport(Graphics g) diff --git a/AircraftCarrier/AircraftCarrier/DrawingObjectWarship.cs b/AircraftCarrier/AircraftCarrier/DrawingObjectWarship.cs new file mode 100644 index 0000000..104b2e0 --- /dev/null +++ b/AircraftCarrier/AircraftCarrier/DrawingObjectWarship.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AircraftCarrier +{ + internal class DrawingObjectWarship : IDrawingObject + { + private DrawingWarship _warship = null; + + public DrawingObjectWarship(DrawingWarship warship) + { + _warship = warship; + } + public float Step => _warship?.Warship?.Step ?? 0; + + public (float Left, float Right, float Top, float Bottom) GetCurrentPosition() + { + return _warship?.GetCurrentPosition() ?? default; + } + + public void MoveObject(Direction direction) + { + _warship?.MoveTransport(direction); + } + + public void SetObject(int x, int y, int width, int height) + { + _warship.SetPosition(x, y, width, height); + } + + void IDrawingObject.DrawningObject(Graphics g) + { + _warship.DrawTransport(g); + } + } +} diff --git a/AircraftCarrier/AircraftCarrier/DrawingWarship.cs b/AircraftCarrier/AircraftCarrier/DrawingWarship.cs index 01c3e18..581ea62 100644 --- a/AircraftCarrier/AircraftCarrier/DrawingWarship.cs +++ b/AircraftCarrier/AircraftCarrier/DrawingWarship.cs @@ -199,6 +199,14 @@ namespace AircraftCarrier _startPosY = _pictureHeight.Value - _warshipHeight; } } + /// + /// Получение текущей позиции объекта + /// + /// + public (float Left, float Right, float Top, float Bottom) GetCurrentPosition() + { + return (_startPosX, _startPosY, _startPosX + _warshipWidth, _startPosY + _warshipHeight); + } } } diff --git a/AircraftCarrier/AircraftCarrier/EntityAircraftCarrier.cs b/AircraftCarrier/AircraftCarrier/EntityAircraftCarrier.cs index 621ddc8..6f75160 100644 --- a/AircraftCarrier/AircraftCarrier/EntityAircraftCarrier.cs +++ b/AircraftCarrier/AircraftCarrier/EntityAircraftCarrier.cs @@ -28,19 +28,19 @@ namespace AircraftCarrier /// Инициализация свойств /// /// Скорость - /// Вес автомобиля - /// Цвет кузова + /// Вес военного корабля + /// Цвет основной палубы /// Дополнительный цвет - /// Признак наличия обвеса - /// Признак наличия антикрыла - /// Признак наличия гоночной полосы - public EntityAircraftCarrier(int speed, float weight, Color bodyColor, Color dopColor, bool bodyKit, bool wing, bool sportLine) : + /// Признак наличия боковой площадки + /// Признак наличия рубки + /// Признак наличия усиленного двигателя + public EntityAircraftCarrier(int speed, float weight, Color bodyColor, Color dopColor, bool bodyKit, bool сabin, bool superEngine) : base(speed, weight, bodyColor) { DopColor = dopColor; BodyKit = bodyKit; - Сabin = wing; - SuperEngine = sportLine; + Сabin = сabin; + SuperEngine = superEngine; } } } diff --git a/AircraftCarrier/AircraftCarrier/IDrawingObject.cs b/AircraftCarrier/AircraftCarrier/IDrawingObject.cs new file mode 100644 index 0000000..c22daf9 --- /dev/null +++ b/AircraftCarrier/AircraftCarrier/IDrawingObject.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AircraftCarrier +{ + /// + /// Интерфейс для работы с объектом, прорисовываемым на форме + /// + internal interface IDrawingObject + { + /// + /// Шаг перемещения объекта + /// + public float Step { get; } + /// + /// Установка позиции объекта + /// + /// Координата X + /// Координата Y + /// Ширина полотна + /// Высота полотна + void SetObject(int x, int y, int width, int height); + /// + /// Изменение направления пермещения объекта + /// + /// Направление + /// + void MoveObject(Direction direction); + /// + /// Отрисовка объекта + /// + /// + void DrawningObject(Graphics g); + /// + /// Получение текущей позиции объекта + /// + /// + (float Left, float Right, float Top, float Bottom) GetCurrentPosition(); + } +} -- 2.25.1 From 128e854feb0fabef3da682ca248cd9e5af86b2e1 Mon Sep 17 00:00:00 2001 From: Hells Hound Date: Wed, 21 Sep 2022 00:36:21 +0400 Subject: [PATCH 6/9] =?UTF-8?q?=D0=90=D0=B1=D1=81=D1=82=D1=80=D0=B0=D0=BA?= =?UTF-8?q?=D1=82=D0=BD=D1=8B=D0=B9=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AircraftCarrier/AbstractMap.cs | 84 +++++++ AircraftCarrier/AircraftCarrier/Direction.cs | 1 + .../AircraftCarrier/FormMap.Designer.cs | 210 ++++++++++++++++++ AircraftCarrier/AircraftCarrier/FormMap.cs | 101 +++++++++ AircraftCarrier/AircraftCarrier/FormMap.resx | 63 ++++++ .../AircraftCarrier/FormWarship.cs | 6 +- AircraftCarrier/AircraftCarrier/Program.cs | 2 +- AircraftCarrier/AircraftCarrier/SimpleMap.cs | 56 +++++ 8 files changed, 521 insertions(+), 2 deletions(-) create mode 100644 AircraftCarrier/AircraftCarrier/AbstractMap.cs create mode 100644 AircraftCarrier/AircraftCarrier/FormMap.Designer.cs create mode 100644 AircraftCarrier/AircraftCarrier/FormMap.cs create mode 100644 AircraftCarrier/AircraftCarrier/FormMap.resx create mode 100644 AircraftCarrier/AircraftCarrier/SimpleMap.cs diff --git a/AircraftCarrier/AircraftCarrier/AbstractMap.cs b/AircraftCarrier/AircraftCarrier/AbstractMap.cs new file mode 100644 index 0000000..5b81d0f --- /dev/null +++ b/AircraftCarrier/AircraftCarrier/AbstractMap.cs @@ -0,0 +1,84 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AircraftCarrier +{ + internal abstract class AbstractMap + { + private IDrawingObject _drawingObject = null; + protected int[,] _map = null; + protected int _width; + protected int _height; + protected float _size_x; + protected float _size_y; + protected readonly Random _random = new(); + protected readonly int _freeRoad = 0; + protected readonly int _barrier = 1; + + public Bitmap CreateMap(int width, int height, IDrawingObject drawningObject) + { + _width = width; + _height = height; + _drawingObject = drawningObject; + GenerateMap(); + while (!SetObjectOnMap()) + { + GenerateMap(); + } + return DrawMapWithObject(); + } + public Bitmap MoveObject(Direction direction) + { + // TODO проверка, что объект может переместится в требуемом направлении + if (true) + { + _drawingObject.MoveObject(direction); + } + return DrawMapWithObject(); + } + private bool SetObjectOnMap() + { + if (_drawingObject == null || _map == null) + { + return false; + } + int x = _random.Next(0, 10); + int y = _random.Next(0, 10); + _drawingObject.SetObject(x, y, _width, _height); + // TODO првоерка, что объект не "накладывается" на закрытые участки + return true; + } + private Bitmap DrawMapWithObject() + { + Bitmap bmp = new(_width, _height); + if (_drawingObject == null || _map == null) + { + return bmp; + } + Graphics gr = Graphics.FromImage(bmp); + for (int i = 0; i < _map.GetLength(0); ++i) + { + for (int j = 0; j < _map.GetLength(1); ++j) + { + if (_map[i, j] == _freeRoad) + { + DrawRoadPart(gr, i, j); + } + else if (_map[i, j] == _barrier) + { + DrawBarrierPart(gr, i, j); + } + } + } + _drawingObject.DrawningObject(gr); + return bmp; + } + + protected abstract void GenerateMap(); + protected abstract void DrawRoadPart(Graphics g, int i, int j); + protected abstract void DrawBarrierPart(Graphics g, int i, int j); + } +} diff --git a/AircraftCarrier/AircraftCarrier/Direction.cs b/AircraftCarrier/AircraftCarrier/Direction.cs index ec2abc9..0f48c8f 100644 --- a/AircraftCarrier/AircraftCarrier/Direction.cs +++ b/AircraftCarrier/AircraftCarrier/Direction.cs @@ -11,6 +11,7 @@ namespace AircraftCarrier /// internal enum Direction { + None = 0, Up = 1, Down = 2, Left = 3, diff --git a/AircraftCarrier/AircraftCarrier/FormMap.Designer.cs b/AircraftCarrier/AircraftCarrier/FormMap.Designer.cs new file mode 100644 index 0000000..74fc6e0 --- /dev/null +++ b/AircraftCarrier/AircraftCarrier/FormMap.Designer.cs @@ -0,0 +1,210 @@ +namespace AircraftCarrier +{ + partial class FormMap + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.pictureBoxWarship = new System.Windows.Forms.PictureBox(); + this.statusStrip = new System.Windows.Forms.StatusStrip(); + this.toolStripStatusLabelSpeed = new System.Windows.Forms.ToolStripStatusLabel(); + this.toolStripStatusLabelWeight = new System.Windows.Forms.ToolStripStatusLabel(); + this.toolStripStatusLabelBodyColor = new System.Windows.Forms.ToolStripStatusLabel(); + this.buttonCreate = new System.Windows.Forms.Button(); + this.buttonDown = new System.Windows.Forms.Button(); + this.buttonUp = new System.Windows.Forms.Button(); + this.buttonLeft = new System.Windows.Forms.Button(); + this.buttonRight = new System.Windows.Forms.Button(); + this.buttonCreateModif = new System.Windows.Forms.Button(); + this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxWarship)).BeginInit(); + this.statusStrip.SuspendLayout(); + this.SuspendLayout(); + // + // pictureBoxWarship + // + this.pictureBoxWarship.Dock = System.Windows.Forms.DockStyle.Fill; + this.pictureBoxWarship.Location = new System.Drawing.Point(0, 0); + this.pictureBoxWarship.Name = "pictureBoxWarship"; + this.pictureBoxWarship.Size = new System.Drawing.Size(768, 426); + this.pictureBoxWarship.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; + this.pictureBoxWarship.TabIndex = 0; + this.pictureBoxWarship.TabStop = false; + // + // statusStrip + // + this.statusStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.toolStripStatusLabelSpeed, + this.toolStripStatusLabelWeight, + this.toolStripStatusLabelBodyColor}); + this.statusStrip.Location = new System.Drawing.Point(0, 426); + this.statusStrip.Name = "statusStrip"; + this.statusStrip.Size = new System.Drawing.Size(768, 22); + this.statusStrip.TabIndex = 1; + // + // toolStripStatusLabelSpeed + // + this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed"; + this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(39, 17); + this.toolStripStatusLabelSpeed.Text = "Speed"; + // + // toolStripStatusLabelWeight + // + this.toolStripStatusLabelWeight.Name = "toolStripStatusLabelWeight"; + this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(45, 17); + this.toolStripStatusLabelWeight.Text = "Weight"; + // + // toolStripStatusLabelBodyColor + // + this.toolStripStatusLabelBodyColor.Name = "toolStripStatusLabelBodyColor"; + this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(36, 17); + this.toolStripStatusLabelBodyColor.Text = "Color"; + // + // 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, 393); + this.buttonCreate.Name = "buttonCreate"; + this.buttonCreate.Size = new System.Drawing.Size(75, 23); + this.buttonCreate.TabIndex = 2; + this.buttonCreate.Text = "Create"; + this.buttonCreate.UseVisualStyleBackColor = true; + this.buttonCreate.Click += new System.EventHandler(this.ButtonCreate_Click); + // + // buttonDown + // + this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonDown.BackgroundImage = global::AircraftCarrier.Properties.Resources.ArrowDown; + this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonDown.Location = new System.Drawing.Point(686, 386); + this.buttonDown.Name = "buttonDown"; + this.buttonDown.Size = new System.Drawing.Size(30, 30); + this.buttonDown.TabIndex = 3; + this.buttonDown.Text = " "; + this.buttonDown.UseVisualStyleBackColor = true; + this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click); + // + // buttonUp + // + this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonUp.BackgroundImage = global::AircraftCarrier.Properties.Resources.ArrowUp; + this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonUp.Location = new System.Drawing.Point(686, 350); + this.buttonUp.Name = "buttonUp"; + this.buttonUp.Size = new System.Drawing.Size(30, 30); + this.buttonUp.TabIndex = 4; + this.buttonUp.Text = " "; + this.buttonUp.UseVisualStyleBackColor = true; + this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click); + // + // buttonLeft + // + this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonLeft.BackgroundImage = global::AircraftCarrier.Properties.Resources.ArrowLeft; + this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonLeft.Location = new System.Drawing.Point(650, 386); + this.buttonLeft.Name = "buttonLeft"; + this.buttonLeft.Size = new System.Drawing.Size(30, 30); + this.buttonLeft.TabIndex = 5; + this.buttonLeft.Text = " "; + this.buttonLeft.UseVisualStyleBackColor = true; + this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click); + // + // buttonRight + // + this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonRight.BackgroundImage = global::AircraftCarrier.Properties.Resources.ArrowRight; + this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonRight.Location = new System.Drawing.Point(722, 386); + this.buttonRight.Name = "buttonRight"; + this.buttonRight.Size = new System.Drawing.Size(30, 30); + this.buttonRight.TabIndex = 6; + this.buttonRight.Text = " "; + this.buttonRight.UseVisualStyleBackColor = true; + this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click); + // + // buttonCreateModif + // + this.buttonCreateModif.Location = new System.Drawing.Point(93, 393); + this.buttonCreateModif.Name = "buttonCreateModif"; + this.buttonCreateModif.Size = new System.Drawing.Size(92, 23); + this.buttonCreateModif.TabIndex = 7; + this.buttonCreateModif.Text = "Modification"; + this.buttonCreateModif.UseVisualStyleBackColor = true; + this.buttonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_Click); + // + // comboBoxSelectorMap + // + this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBoxSelectorMap.FormattingEnabled = true; + this.comboBoxSelectorMap.Items.AddRange(new object[] { + "Простая карта"}); + this.comboBoxSelectorMap.Location = new System.Drawing.Point(12, 12); + this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; + this.comboBoxSelectorMap.Size = new System.Drawing.Size(121, 23); + this.comboBoxSelectorMap.TabIndex = 8; + this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.comboBoxSelectorMap_SelectedIndexChanged); + // + // FormMap + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(768, 448); + this.Controls.Add(this.comboBoxSelectorMap); + this.Controls.Add(this.buttonCreateModif); + this.Controls.Add(this.buttonRight); + this.Controls.Add(this.buttonLeft); + this.Controls.Add(this.buttonUp); + this.Controls.Add(this.buttonDown); + this.Controls.Add(this.buttonCreate); + this.Controls.Add(this.pictureBoxWarship); + this.Controls.Add(this.statusStrip); + this.Name = "FormMap"; + this.Text = "Карта"; + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxWarship)).EndInit(); + this.statusStrip.ResumeLayout(false); + this.statusStrip.PerformLayout(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private PictureBox pictureBoxWarship; + private StatusStrip statusStrip; + private ToolStripStatusLabel toolStripStatusLabelSpeed; + private ToolStripStatusLabel toolStripStatusLabelWeight; + private ToolStripStatusLabel toolStripStatusLabelBodyColor; + private Button buttonCreate; + private Button buttonDown; + private Button buttonUp; + private Button buttonLeft; + private Button buttonRight; + private Button buttonCreateModif; + private ComboBox comboBoxSelectorMap; + } +} \ No newline at end of file diff --git a/AircraftCarrier/AircraftCarrier/FormMap.cs b/AircraftCarrier/AircraftCarrier/FormMap.cs new file mode 100644 index 0000000..a6461db --- /dev/null +++ b/AircraftCarrier/AircraftCarrier/FormMap.cs @@ -0,0 +1,101 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace AircraftCarrier +{ + public partial class FormMap : Form + { + private AbstractMap _abstractMap; + public FormMap() + { + InitializeComponent(); + _abstractMap = new SimpleMap(); + } + /// + /// Заполнение информации по объекту + /// + /// + private void SetData(DrawingWarship warship) + { + toolStripStatusLabelSpeed.Text = $"Скорость: {warship.Warship.Speed}"; + toolStripStatusLabelWeight.Text = $"Вес: {warship.Warship.Weight}"; + toolStripStatusLabelBodyColor.Text = $"Цвет: {warship.Warship.BodyColor.Name}"; + pictureBoxWarship.Image = _abstractMap.CreateMap(pictureBoxWarship.Width, pictureBoxWarship.Height, + new DrawingObjectWarship(warship)); + } + /// + /// Обработка нажатия кнопки "Create" + /// + /// + /// + private void ButtonCreate_Click(object sender, EventArgs e) + { + Random rnd = new(); + var warship = new DrawingWarship(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); + SetData(warship); + } + /// + /// Обработка нажатия стрелочек + /// + /// + /// + private void ButtonMove_Click(object sender, EventArgs e) + { + //получаем имя кнопки + string name = ((Button)sender)?.Name ?? string.Empty; + Direction dir = Direction.None; + switch (name) + { + case "buttonUp": + dir = Direction.Up; + break; + case "buttonDown": + dir = Direction.Down; + break; + case "buttonLeft": + dir = Direction.Left; + break; + case "buttonRight": + dir = Direction.Right; + break; + } + pictureBoxWarship.Image = _abstractMap?.MoveObject(dir); + } + + /// + /// Обработка нажатия кнопки "Modification" + /// + /// + /// + private void ButtonCreateModif_Click(object sender, EventArgs e) + { + Random rnd = new(); + var car = new DrawingAircraftCarrier(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(car); + } + /// + /// Смена карты + /// + /// + /// + private void comboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e) + { + switch (comboBoxSelectorMap.Text) + { + case "Простая карта": + _abstractMap = new SimpleMap(); + break; + } + } + } +} diff --git a/AircraftCarrier/AircraftCarrier/FormMap.resx b/AircraftCarrier/AircraftCarrier/FormMap.resx new file mode 100644 index 0000000..2c0949d --- /dev/null +++ b/AircraftCarrier/AircraftCarrier/FormMap.resx @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/AircraftCarrier/AircraftCarrier/FormWarship.cs b/AircraftCarrier/AircraftCarrier/FormWarship.cs index dede81b..1d0e4a3 100644 --- a/AircraftCarrier/AircraftCarrier/FormWarship.cs +++ b/AircraftCarrier/AircraftCarrier/FormWarship.cs @@ -40,7 +40,11 @@ namespace AircraftCarrier SetData(); Draw(); } - + /// + /// + /// + /// + /// private void ButtonMove_Click(object sender, EventArgs e) { string name = ((Button)sender)?.Name ?? string.Empty; diff --git a/AircraftCarrier/AircraftCarrier/Program.cs b/AircraftCarrier/AircraftCarrier/Program.cs index 8b302c0..4080ebd 100644 --- a/AircraftCarrier/AircraftCarrier/Program.cs +++ b/AircraftCarrier/AircraftCarrier/Program.cs @@ -11,7 +11,7 @@ namespace AircraftCarrier // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormWarship()); + Application.Run(new FormMap()); } } } \ No newline at end of file diff --git a/AircraftCarrier/AircraftCarrier/SimpleMap.cs b/AircraftCarrier/AircraftCarrier/SimpleMap.cs new file mode 100644 index 0000000..5da18d4 --- /dev/null +++ b/AircraftCarrier/AircraftCarrier/SimpleMap.cs @@ -0,0 +1,56 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AircraftCarrier +{ + /// + /// Простая реализация абсрактного класса AbstractMap + /// + internal class SimpleMap : AbstractMap + { + /// + /// Цвет участка закрытого + /// + private readonly Brush barrierColor = new SolidBrush(Color.Black); + /// + /// Цвет участка открытого + /// + private readonly Brush waterColor = new SolidBrush(Color.Blue); + + protected override void DrawBarrierPart(Graphics g, int i, int j) + { + g.FillRectangle(barrierColor, i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1)); + } + protected override void DrawRoadPart(Graphics g, int i, int j) + { + g.FillRectangle(waterColor, i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1)); + } + protected override void GenerateMap() + { + _map = new int[100, 100]; + _size_x = (float)_width / _map.GetLength(0); + _size_y = (float)_height / _map.GetLength(1); + int counter = 0; + for (int i = 0; i < _map.GetLength(0); ++i) + { + for (int j = 0; j < _map.GetLength(1); ++j) + { + _map[i, j] = _freeRoad; + } + } + while (counter < 50) + { + int x = _random.Next(0, 100); + int y = _random.Next(0, 100); + if (_map[x, y] == _freeRoad) + { + _map[x, y] = _barrier; + counter++; + } + } + } + } +} -- 2.25.1 From 711b7d213b7044775d7d4dd6003ab46e2523e60c Mon Sep 17 00:00:00 2001 From: Hells Hound Date: Wed, 21 Sep 2022 10:06:30 +0400 Subject: [PATCH 7/9] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=B2=D1=82=D0=BE=D1=80=D0=B0=D1=8F=20=D0=BA?= =?UTF-8?q?=D0=B0=D1=80=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AircraftCarrier/AbstractMap.cs | 59 +++++++++++++++++ .../AircraftCarrier/FormMap.Designer.cs | 3 +- AircraftCarrier/AircraftCarrier/FormMap.cs | 3 + AircraftCarrier/AircraftCarrier/LineMap.cs | 64 +++++++++++++++++++ 4 files changed, 128 insertions(+), 1 deletion(-) create mode 100644 AircraftCarrier/AircraftCarrier/LineMap.cs diff --git a/AircraftCarrier/AircraftCarrier/AbstractMap.cs b/AircraftCarrier/AircraftCarrier/AbstractMap.cs index 5b81d0f..3a2e8c4 100644 --- a/AircraftCarrier/AircraftCarrier/AbstractMap.cs +++ b/AircraftCarrier/AircraftCarrier/AbstractMap.cs @@ -49,6 +49,65 @@ namespace AircraftCarrier int y = _random.Next(0, 10); _drawingObject.SetObject(x, y, _width, _height); // TODO првоерка, что объект не "накладывается" на закрытые участки + + + + + + + + + + /*(float left, float right, float top, float bottom) = _drawingObject.GetCurrentPosition(); + float step = _drawingObject?.Step ?? 0; + + int searchX = 0, + searchY = 0, + startX = 0, + startY = 0; + switch (direction) + { + case Direction.UP: + searchX = (int)right; + searchY = (int)top; + startX = (int)left; + startY = (int)(top - step); + break; + case Direction.DOWN: + searchX = (int)right; + searchY = (int)(bottom + step); + startX = (int)left; + startY = (int)bottom; + break; + case Direction.LEFT: + searchX = (int)left; + searchY = (int)bottom; + startX = (int)(left - step); + startY = (int)top; + break; + case Direction.RIGHT: + searchX = (int)(right + step); + searchY = (int)bottom; + startX = (int)right; + startY = (int)top; + break; + } + + searchX = (int)(searchX / _size_x) + 1; + searchY = (int)(searchY / _size_y) + 1; + startX = (int)(startX / _size_x); + startY = (int)(startY / _size_y); + + if (searchX < 0 || searchX > _width || searchY < 0 || searchY > _height) return false; + + for (int i = startY; i < searchY; i++) + { + for (int j = startX; j < searchX; j++) + { + if (_map[j, i] == _barrier) return false; + } + } +*/ return true; } private Bitmap DrawMapWithObject() diff --git a/AircraftCarrier/AircraftCarrier/FormMap.Designer.cs b/AircraftCarrier/AircraftCarrier/FormMap.Designer.cs index 74fc6e0..ee9bc8b 100644 --- a/AircraftCarrier/AircraftCarrier/FormMap.Designer.cs +++ b/AircraftCarrier/AircraftCarrier/FormMap.Designer.cs @@ -161,7 +161,8 @@ this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.comboBoxSelectorMap.FormattingEnabled = true; this.comboBoxSelectorMap.Items.AddRange(new object[] { - "Простая карта"}); + "Простая карта", + "Преграды-линии"}); this.comboBoxSelectorMap.Location = new System.Drawing.Point(12, 12); this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; this.comboBoxSelectorMap.Size = new System.Drawing.Size(121, 23); diff --git a/AircraftCarrier/AircraftCarrier/FormMap.cs b/AircraftCarrier/AircraftCarrier/FormMap.cs index a6461db..9925c2d 100644 --- a/AircraftCarrier/AircraftCarrier/FormMap.cs +++ b/AircraftCarrier/AircraftCarrier/FormMap.cs @@ -95,6 +95,9 @@ namespace AircraftCarrier case "Простая карта": _abstractMap = new SimpleMap(); break; + case "Преграды линии": + _abstractMap = new LineMap(); + break; } } } diff --git a/AircraftCarrier/AircraftCarrier/LineMap.cs b/AircraftCarrier/AircraftCarrier/LineMap.cs new file mode 100644 index 0000000..97087a5 --- /dev/null +++ b/AircraftCarrier/AircraftCarrier/LineMap.cs @@ -0,0 +1,64 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace AircraftCarrier +{ + internal class LineMap : AbstractMap + { + /// + /// Цвет участка закрытого + /// + private readonly Brush barrierColor = new SolidBrush(Color.Blue); + /// + /// Цвет участка открытого + /// + private readonly Brush roadColor = new SolidBrush(Color.Gray); + protected override void DrawBarrierPart(Graphics g, int i, int j) + { + g.FillRectangle(barrierColor, i * _size_x, j * _size_y, _size_x, _size_y); + } + protected override void DrawRoadPart(Graphics g, int i, int j) + { + g.FillRectangle(roadColor, i * _size_x, j * _size_y, _size_x, _size_y); + } + protected override void GenerateMap() + { + _map = new int[100, 100]; + _size_x = (float)_width / _map.GetLength(0); + _size_y = (float)_height / _map.GetLength(1); + int counter = 0; + for (int i = 0; i < _map.GetLength(0); ++i) + { + for (int j = 0; j < _map.GetLength(1); ++j) + { + _map[i, j] = _freeRoad; + } + } + bool flag = true; + while (counter < 10) + { + int lineX = _random.Next(0, 100); + int lineY = _random.Next(0, 100); + if (flag) + { + for (int i = 0; i <= 10; i++) + _map[lineX, i] = _barrier; + flag = false; + } + else + { + for (int i = 0; i <= 10; i++) + _map[i, lineY] = _barrier; + flag = true; + } + counter++; + } + } + + + } +} -- 2.25.1 From 9a8bafa28332a78aef21f8079c5505c34ae2c524 Mon Sep 17 00:00:00 2001 From: Hells Hound Date: Wed, 21 Sep 2022 10:52:37 +0400 Subject: [PATCH 8/9] =?UTF-8?q?=D0=9F=D0=BE=D0=BB=D0=BD=D0=BE=D1=81=D1=82?= =?UTF-8?q?=D1=8C=D1=8E=20=D0=B3=D0=BE=D1=82=D0=BE=D0=B2=D0=B0=D1=8F=20?= =?UTF-8?q?=D0=B2=D1=82=D0=BE=D1=80=D0=B0=D1=8F=20=D0=BB=D0=B0=D0=B1=D0=BE?= =?UTF-8?q?=D1=80=D0=B0=D1=82=D0=BE=D1=80=D0=BD=D0=B0=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AircraftCarrier/AbstractMap.cs | 129 ++++++++++-------- AircraftCarrier/AircraftCarrier/FormMap.cs | 2 +- AircraftCarrier/AircraftCarrier/LineMap.cs | 17 +-- AircraftCarrier/AircraftCarrier/SimpleMap.cs | 2 +- 4 files changed, 82 insertions(+), 68 deletions(-) diff --git a/AircraftCarrier/AircraftCarrier/AbstractMap.cs b/AircraftCarrier/AircraftCarrier/AbstractMap.cs index 3a2e8c4..2836c1f 100644 --- a/AircraftCarrier/AircraftCarrier/AbstractMap.cs +++ b/AircraftCarrier/AircraftCarrier/AbstractMap.cs @@ -32,13 +32,38 @@ namespace AircraftCarrier } public Bitmap MoveObject(Direction direction) { - // TODO проверка, что объект может переместится в требуемом направлении if (true) { _drawingObject.MoveObject(direction); } + (float Left, float Right, float Top, float Bottom) = _drawingObject.GetCurrentPosition(); + + + if (Check(Left, Right, Top, Bottom) != 0) + { + _drawingObject.MoveObject(GetOpositDirection(direction)); + } return DrawMapWithObject(); } + + private Direction GetOpositDirection(Direction dir) + { + switch (dir) + { + case Direction.None: + return Direction.None; + case Direction.Up: + return Direction.Down; + case Direction.Down: + return Direction.Up; + case Direction.Left: + return Direction.Right; + case Direction.Right: + return Direction.Left; + } + return Direction.None; + } + private bool SetObjectOnMap() { if (_drawingObject == null || _map == null) @@ -48,68 +73,56 @@ namespace AircraftCarrier int x = _random.Next(0, 10); int y = _random.Next(0, 10); _drawingObject.SetObject(x, y, _width, _height); - // TODO првоерка, что объект не "накладывается" на закрытые участки - - - - - - - - - - /*(float left, float right, float top, float bottom) = _drawingObject.GetCurrentPosition(); - float step = _drawingObject?.Step ?? 0; - - int searchX = 0, - searchY = 0, - startX = 0, - startY = 0; - switch (direction) + (float Left, float Right, float Top, float Bottom) = _drawingObject.GetCurrentPosition(); + float nowX = Left; + float nowY = Right; + float lenX = Top - Left; + float lenY = Bottom - Right; + while (Check(nowX, nowY, nowX + lenX, nowY + lenY) != 2) { - case Direction.UP: - searchX = (int)right; - searchY = (int)top; - startX = (int)left; - startY = (int)(top - step); - break; - case Direction.DOWN: - searchX = (int)right; - searchY = (int)(bottom + step); - startX = (int)left; - startY = (int)bottom; - break; - case Direction.LEFT: - searchX = (int)left; - searchY = (int)bottom; - startX = (int)(left - step); - startY = (int)top; - break; - case Direction.RIGHT: - searchX = (int)(right + step); - searchY = (int)bottom; - startX = (int)right; - startY = (int)top; - break; - } - - searchX = (int)(searchX / _size_x) + 1; - searchY = (int)(searchY / _size_y) + 1; - startX = (int)(startX / _size_x); - startY = (int)(startY / _size_y); - - if (searchX < 0 || searchX > _width || searchY < 0 || searchY > _height) return false; - - for (int i = startY; i < searchY; i++) - { - for (int j = startX; j < searchX; j++) + int result; + do { - if (_map[j, i] == _barrier) return false; + result = Check(nowX, nowY, nowX + lenX, nowY + lenY); + if (result == 0) + { + _drawingObject.SetObject((int)nowX, (int)nowY, _width, _height); + return true; + } + else + { + nowX += _size_x; + } + } while (result != 2); + nowX = x; + nowY += _size_y; + } + return false; + } + + private int Check(float Left, float Right, float Top, float Bottom) + { + int startX = (int)(Left / _size_x); + int startY = (int)(Right / _size_y); + int endX = (int)(Top / _size_x); + int endY = (int)(Bottom / _size_y); + if (startX < 0 || startY < 0 || endX >= _map.GetLength(0) || endY >= _map.GetLength(0)) + { + return 2; + } + for (int i = startX; i <= endX; i++) + { + for (int j = startY; j <= endY; j++) + { + if (_map[i, j] == _barrier) + { + return 1; + } } } -*/ - return true; + return 0; } + private Bitmap DrawMapWithObject() { Bitmap bmp = new(_width, _height); diff --git a/AircraftCarrier/AircraftCarrier/FormMap.cs b/AircraftCarrier/AircraftCarrier/FormMap.cs index 9925c2d..acd3cfe 100644 --- a/AircraftCarrier/AircraftCarrier/FormMap.cs +++ b/AircraftCarrier/AircraftCarrier/FormMap.cs @@ -95,7 +95,7 @@ namespace AircraftCarrier case "Простая карта": _abstractMap = new SimpleMap(); break; - case "Преграды линии": + case "Преграды-линии": _abstractMap = new LineMap(); break; } diff --git a/AircraftCarrier/AircraftCarrier/LineMap.cs b/AircraftCarrier/AircraftCarrier/LineMap.cs index 97087a5..df6829b 100644 --- a/AircraftCarrier/AircraftCarrier/LineMap.cs +++ b/AircraftCarrier/AircraftCarrier/LineMap.cs @@ -12,18 +12,18 @@ namespace AircraftCarrier /// /// Цвет участка закрытого /// - private readonly Brush barrierColor = new SolidBrush(Color.Blue); + private readonly Brush barrierColor = new SolidBrush(Color.Brown); /// /// Цвет участка открытого /// - private readonly Brush roadColor = new SolidBrush(Color.Gray); + private readonly Brush waterColor = new SolidBrush(Color.Blue); protected override void DrawBarrierPart(Graphics g, int i, int j) { g.FillRectangle(barrierColor, i * _size_x, j * _size_y, _size_x, _size_y); } protected override void DrawRoadPart(Graphics g, int i, int j) { - g.FillRectangle(roadColor, i * _size_x, j * _size_y, _size_x, _size_y); + g.FillRectangle(waterColor, i * _size_x, j * _size_y, _size_x, _size_y); } protected override void GenerateMap() { @@ -39,19 +39,20 @@ namespace AircraftCarrier } } bool flag = true; - while (counter < 10) + while (counter < 20) { - int lineX = _random.Next(0, 100); - int lineY = _random.Next(0, 100); + int lineX = _random.Next(11, 89); + int lineY = _random.Next(11, 89); + if (flag) { - for (int i = 0; i <= 10; i++) + for (int i = lineY; i <= lineY + 10; i++) _map[lineX, i] = _barrier; flag = false; } else { - for (int i = 0; i <= 10; i++) + for (int i = lineX; i <= lineX + 10; i++) _map[i, lineY] = _barrier; flag = true; } diff --git a/AircraftCarrier/AircraftCarrier/SimpleMap.cs b/AircraftCarrier/AircraftCarrier/SimpleMap.cs index 5da18d4..190d99f 100644 --- a/AircraftCarrier/AircraftCarrier/SimpleMap.cs +++ b/AircraftCarrier/AircraftCarrier/SimpleMap.cs @@ -14,7 +14,7 @@ namespace AircraftCarrier /// /// Цвет участка закрытого /// - private readonly Brush barrierColor = new SolidBrush(Color.Black); + private readonly Brush barrierColor = new SolidBrush(Color.Brown); /// /// Цвет участка открытого /// -- 2.25.1 From c3b6d7169edee8752a98b4671d28fe789719d5e3 Mon Sep 17 00:00:00 2001 From: Hells Hound Date: Fri, 30 Sep 2022 19:41:15 +0400 Subject: [PATCH 9/9] =?UTF-8?q?=D0=9F=D0=BE=D0=BB=D0=BD=D0=BE=D1=81=D1=82?= =?UTF-8?q?=D1=8C=D1=8E=20=D0=B3=D0=BE=D1=82=D0=BE=D0=B2=D0=B0=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AircraftCarrier/AircraftCarrier/AbstractMap.cs | 1 - AircraftCarrier/AircraftCarrier/DrawingWarship.cs | 1 - AircraftCarrier/AircraftCarrier/EntityWarship.cs | 2 -- AircraftCarrier/AircraftCarrier/LineMap.cs | 2 -- 4 files changed, 6 deletions(-) diff --git a/AircraftCarrier/AircraftCarrier/AbstractMap.cs b/AircraftCarrier/AircraftCarrier/AbstractMap.cs index 2836c1f..667881f 100644 --- a/AircraftCarrier/AircraftCarrier/AbstractMap.cs +++ b/AircraftCarrier/AircraftCarrier/AbstractMap.cs @@ -38,7 +38,6 @@ namespace AircraftCarrier } (float Left, float Right, float Top, float Bottom) = _drawingObject.GetCurrentPosition(); - if (Check(Left, Right, Top, Bottom) != 0) { _drawingObject.MoveObject(GetOpositDirection(direction)); diff --git a/AircraftCarrier/AircraftCarrier/DrawingWarship.cs b/AircraftCarrier/AircraftCarrier/DrawingWarship.cs index 581ea62..0cf2699 100644 --- a/AircraftCarrier/AircraftCarrier/DrawingWarship.cs +++ b/AircraftCarrier/AircraftCarrier/DrawingWarship.cs @@ -207,6 +207,5 @@ namespace AircraftCarrier { return (_startPosX, _startPosY, _startPosX + _warshipWidth, _startPosY + _warshipHeight); } - } } diff --git a/AircraftCarrier/AircraftCarrier/EntityWarship.cs b/AircraftCarrier/AircraftCarrier/EntityWarship.cs index 88b6a83..b5d037c 100644 --- a/AircraftCarrier/AircraftCarrier/EntityWarship.cs +++ b/AircraftCarrier/AircraftCarrier/EntityWarship.cs @@ -40,7 +40,5 @@ namespace AircraftCarrier Weight = weight <= 0 ? rnd.Next(40, 70) : weight; BodyColor = bodyColor; } - - } } diff --git a/AircraftCarrier/AircraftCarrier/LineMap.cs b/AircraftCarrier/AircraftCarrier/LineMap.cs index df6829b..2853b76 100644 --- a/AircraftCarrier/AircraftCarrier/LineMap.cs +++ b/AircraftCarrier/AircraftCarrier/LineMap.cs @@ -59,7 +59,5 @@ namespace AircraftCarrier counter++; } } - - } } -- 2.25.1