From d35b31c29c567e3c2177a2e2835ab3d6db1c425e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=20=D0=91=D0=BE=D0=BD=D0=B4=D0=B0?= =?UTF-8?q?=D1=80=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Wed, 21 Sep 2022 10:11:01 +0400 Subject: [PATCH 01/14] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D1=85=D0=BE?= =?UTF-8?q?=D0=B4=20=D0=BD=D0=B0=20=D0=BA=D0=BE=D0=BD=D1=81=D1=82=D1=80?= =?UTF-8?q?=D1=83=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 --- WarmlyShip/WarmlyShip/DrawingWarmlyShip.cs | 5 ++--- WarmlyShip/WarmlyShip/EntityWarmlyShip.cs | 2 +- WarmlyShip/WarmlyShip/FormClass.cs | 3 +-- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/WarmlyShip/WarmlyShip/DrawingWarmlyShip.cs b/WarmlyShip/WarmlyShip/DrawingWarmlyShip.cs index b131644..ac2bdeb 100644 --- a/WarmlyShip/WarmlyShip/DrawingWarmlyShip.cs +++ b/WarmlyShip/WarmlyShip/DrawingWarmlyShip.cs @@ -16,10 +16,9 @@ namespace WarmlyShip private readonly int _warmlyShipWidth = 125; //Ширина отрисовки корабля private readonly int _warmlyShipHeight = 50; //Высота отрисовки корабля - public void Init(int speed, float weight, Color bodyColor) + public DrawingWarmlyShip(int speed, float weight, Color bodyColor) { - warmlyShip = new EntityWarmlyShip(); - warmlyShip.Init(speed, weight, bodyColor); + warmlyShip = new EntityWarmlyShip(speed, weight, bodyColor); } public void SetPosition(int x, int y, int width, int height) diff --git a/WarmlyShip/WarmlyShip/EntityWarmlyShip.cs b/WarmlyShip/WarmlyShip/EntityWarmlyShip.cs index 29576fb..0049f81 100644 --- a/WarmlyShip/WarmlyShip/EntityWarmlyShip.cs +++ b/WarmlyShip/WarmlyShip/EntityWarmlyShip.cs @@ -13,7 +13,7 @@ namespace WarmlyShip public Color BodyColor { get; private set; } //Цвет public float Step => Speed * 100 / Weight; //Шаг при перемещении - public void Init(int speed, float weight, Color bodyColor) + public EntityWarmlyShip(int speed, float weight, Color bodyColor) { Random random = new Random(); Speed = speed <= 0 ? random.Next(50, 150) : speed; diff --git a/WarmlyShip/WarmlyShip/FormClass.cs b/WarmlyShip/WarmlyShip/FormClass.cs index 23e86ce..02796ed 100644 --- a/WarmlyShip/WarmlyShip/FormClass.cs +++ b/WarmlyShip/WarmlyShip/FormClass.cs @@ -20,8 +20,7 @@ namespace WarmlyShip private void ButtonCreate_Click(object sender, EventArgs e) { Random random = new Random(); - _warmlyShip = new DrawingWarmlyShip(); - _warmlyShip.Init(random.Next(100, 300), random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256))); + _warmlyShip = new DrawingWarmlyShip(random.Next(100, 300), random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256))); _warmlyShip.SetPosition(random.Next(pictureBox.Width - 150, pictureBox.Width - 125), random.Next(pictureBox.Height - 150, pictureBox.Height - 50), pictureBox.Width, pictureBox.Height); toolStripStatusSpeed.Text = $": {_warmlyShip.warmlyShip?.Speed}"; toolStripStatusWeight.Text = $": {_warmlyShip.warmlyShip?.Weight}"; -- 2.25.1 From 33d1b6d8469fc0e7cd73735bd73747ebe743dc8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=20=D0=91=D0=BE=D0=BD=D0=B4=D0=B0?= =?UTF-8?q?=D1=80=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Wed, 21 Sep 2022 10:49:05 +0400 Subject: [PATCH 02/14] =?UTF-8?q?=D0=A1=D0=BE=D1=85=D1=80=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D0=BB=20=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WarmlyShip/WarmlyShip/DrawingWarmlyShip.cs | 14 ++++++++---- WarmlyShip/WarmlyShip/DrawningMotorShip.cs | 25 ++++++++++++++++++++++ WarmlyShip/WarmlyShip/EntityMotorShip.cs | 25 ++++++++++++++++++++++ 3 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 WarmlyShip/WarmlyShip/DrawningMotorShip.cs create mode 100644 WarmlyShip/WarmlyShip/EntityMotorShip.cs diff --git a/WarmlyShip/WarmlyShip/DrawingWarmlyShip.cs b/WarmlyShip/WarmlyShip/DrawingWarmlyShip.cs index ac2bdeb..cb9311e 100644 --- a/WarmlyShip/WarmlyShip/DrawingWarmlyShip.cs +++ b/WarmlyShip/WarmlyShip/DrawingWarmlyShip.cs @@ -8,9 +8,9 @@ namespace WarmlyShip { internal class DrawingWarmlyShip { - public EntityWarmlyShip warmlyShip { private set; get; } //Класс-сущность - public float _startPosX; //Координаты отрисовки по оси x - public float _startPosY; //Координаты отрисовки по оси y + public EntityWarmlyShip warmlyShip { protected set; get; } //Класс-сущность + protected float _startPosX; //Координаты отрисовки по оси x + protected float _startPosY; //Координаты отрисовки по оси y private int? _pictureWidth = null; //Ширина окна private int? _pictureHeight = null; //Высота окна private readonly int _warmlyShipWidth = 125; //Ширина отрисовки корабля @@ -21,6 +21,12 @@ namespace WarmlyShip warmlyShip = new EntityWarmlyShip(speed, weight, bodyColor); } + protected DrawingWarmlyShip(int speed, float weight, Color bodyColor, int warmlyWidth, int warmlyHeight) : this(speed, weight, bodyColor) + { + _warmlyShipWidth = warmlyWidth; + _warmlyShipHeight = warmlyHeight; + } + public void SetPosition(int x, int y, int width, int height) { if (width < _warmlyShipWidth || height < _warmlyShipHeight) return; @@ -51,7 +57,7 @@ namespace WarmlyShip } } - public void DrawTransport(Graphics g) + public virtual void DrawTransport(Graphics g) { if (_startPosX < 0 || _startPosY < 0 || !_pictureHeight.HasValue || !_pictureWidth.HasValue) { diff --git a/WarmlyShip/WarmlyShip/DrawningMotorShip.cs b/WarmlyShip/WarmlyShip/DrawningMotorShip.cs new file mode 100644 index 0000000..d296623 --- /dev/null +++ b/WarmlyShip/WarmlyShip/DrawningMotorShip.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WarmlyShip +{ + internal class DrawningMotorShip : DrawingWarmlyShip + { + public DrawningMotorShip(int speed, float weight, Color bodyColor, Color dopColor, bool bodyKit, bool wing, bool sportLine) : base(speed, weight, bodyColor, 110, 60) + { + warmlyShip = new EntityMotorShip(speed, weight, bodyColor, dopColor, bodyKit, wing, sportLine); + } + + public override void DrawTransport(Graphics g) + { + if (warmlyShip is not EntityMotorShip sportCar) + { + return; + } + + } + } +} \ No newline at end of file diff --git a/WarmlyShip/WarmlyShip/EntityMotorShip.cs b/WarmlyShip/WarmlyShip/EntityMotorShip.cs new file mode 100644 index 0000000..55687e5 --- /dev/null +++ b/WarmlyShip/WarmlyShip/EntityMotorShip.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WarmlyShip +{ + internal class EntityMotorShip : EntityWarmlyShip + { + 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 EntityMotorShip(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; + } + + } +} + \ No newline at end of file -- 2.25.1 From 48a9ca1a4493c2b774469b1094d075a94ed25025 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=20=D0=91=D0=BE=D0=BD=D0=B4=D0=B0?= =?UTF-8?q?=D1=80=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Fri, 30 Sep 2022 18:55:38 +0400 Subject: [PATCH 03/14] =?UTF-8?q?=D0=A1=D0=BE=D1=85=D1=80=D0=B0=D0=BD?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WarmlyShip/WarmlyShip/DrawingWarmlyShip.cs | 5 +++++ WarmlyShip/WarmlyShip/EntityMotorShip.cs | 1 + 2 files changed, 6 insertions(+) diff --git a/WarmlyShip/WarmlyShip/DrawingWarmlyShip.cs b/WarmlyShip/WarmlyShip/DrawingWarmlyShip.cs index cb9311e..097b8b1 100644 --- a/WarmlyShip/WarmlyShip/DrawingWarmlyShip.cs +++ b/WarmlyShip/WarmlyShip/DrawingWarmlyShip.cs @@ -16,6 +16,7 @@ namespace WarmlyShip private readonly int _warmlyShipWidth = 125; //Ширина отрисовки корабля private readonly int _warmlyShipHeight = 50; //Высота отрисовки корабля + //Конструктор класса public DrawingWarmlyShip(int speed, float weight, Color bodyColor) { warmlyShip = new EntityWarmlyShip(speed, weight, bodyColor); @@ -27,6 +28,7 @@ namespace WarmlyShip _warmlyShipHeight = warmlyHeight; } + //Начальная позиция коробля public void SetPosition(int x, int y, int width, int height) { if (width < _warmlyShipWidth || height < _warmlyShipHeight) return; @@ -37,6 +39,7 @@ namespace WarmlyShip _pictureHeight = height; } + //Функция передвижения объекта public void MoveTransport(Direction direction) { if (!_pictureWidth.HasValue || !_pictureHeight.HasValue) return; @@ -57,6 +60,7 @@ namespace WarmlyShip } } + //Отрисовка транспорта public virtual void DrawTransport(Graphics g) { if (_startPosX < 0 || _startPosY < 0 || !_pictureHeight.HasValue || !_pictureWidth.HasValue) @@ -89,6 +93,7 @@ namespace WarmlyShip g.DrawEllipse(new(Color.Blue, 2), _startPosX + _warmlyShipWidth * 2 / 5 + 2.5f, _startPosY + 25, 20, 20); } + //Изменение границ отрисовки public void ChangeBorders(int width, int height) { _pictureWidth = width; diff --git a/WarmlyShip/WarmlyShip/EntityMotorShip.cs b/WarmlyShip/WarmlyShip/EntityMotorShip.cs index 55687e5..a2d5d38 100644 --- a/WarmlyShip/WarmlyShip/EntityMotorShip.cs +++ b/WarmlyShip/WarmlyShip/EntityMotorShip.cs @@ -12,6 +12,7 @@ namespace WarmlyShip public bool BodyKit { get; private set; } public bool Wing { get; private set; } public bool SportLine { get; private set; } + public EntityMotorShip(int speed, float weight, Color bodyColor, Color dopColor, bool bodyKit, bool wing, bool sportLine) : base(speed, weight, bodyColor) { DopColor = dopColor; -- 2.25.1 From fe5fe24f5a20e41c7aa5154715d41e0f7f89c4d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=20=D0=91=D0=BE=D0=BD=D0=B4=D0=B0?= =?UTF-8?q?=D1=80=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Tue, 4 Oct 2022 19:49:57 +0400 Subject: [PATCH 04/14] =?UTF-8?q?=D0=A4=D0=B8=D0=BA=D1=81=D0=B0=D1=86?= =?UTF-8?q?=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WarmlyShip/WarmlyShip/DrawningMotorShip.cs | 17 ++++++++++--- ...ingWarmlyShip.cs => DrawningWarmlyShip.cs} | 6 ++--- WarmlyShip/WarmlyShip/EntityMotorShip.cs | 12 ++++----- WarmlyShip/WarmlyShip/FormClass.Designer.cs | 14 +++++++++++ WarmlyShip/WarmlyShip/FormClass.cs | 25 ++++++++++++++++--- 5 files changed, 56 insertions(+), 18 deletions(-) rename WarmlyShip/WarmlyShip/{DrawingWarmlyShip.cs => DrawningWarmlyShip.cs} (94%) diff --git a/WarmlyShip/WarmlyShip/DrawningMotorShip.cs b/WarmlyShip/WarmlyShip/DrawningMotorShip.cs index d296623..7ef8c2c 100644 --- a/WarmlyShip/WarmlyShip/DrawningMotorShip.cs +++ b/WarmlyShip/WarmlyShip/DrawningMotorShip.cs @@ -6,20 +6,29 @@ using System.Threading.Tasks; namespace WarmlyShip { - internal class DrawningMotorShip : DrawingWarmlyShip + internal class DrawningMotorShip : DrawningWarmlyShip { - public DrawningMotorShip(int speed, float weight, Color bodyColor, Color dopColor, bool bodyKit, bool wing, bool sportLine) : base(speed, weight, bodyColor, 110, 60) + public DrawningMotorShip(int speed, float weight, Color bodyColor, Color dopColor, bool tubes, bool cistern) : base(speed, weight, bodyColor, 110, 60) { - warmlyShip = new EntityMotorShip(speed, weight, bodyColor, dopColor, bodyKit, wing, sportLine); + warmlyShip = new EntityMotorShip(speed, weight, bodyColor, dopColor, tubes , cistern); } public override void DrawTransport(Graphics g) { - if (warmlyShip is not EntityMotorShip sportCar) + if (warmlyShip is not EntityMotorShip motorShip) { return; } + if (motorShip.Tubes) + { + + } + + if (motorShip.Cistern) + { + + } } } } \ No newline at end of file diff --git a/WarmlyShip/WarmlyShip/DrawingWarmlyShip.cs b/WarmlyShip/WarmlyShip/DrawningWarmlyShip.cs similarity index 94% rename from WarmlyShip/WarmlyShip/DrawingWarmlyShip.cs rename to WarmlyShip/WarmlyShip/DrawningWarmlyShip.cs index 097b8b1..b3e03f1 100644 --- a/WarmlyShip/WarmlyShip/DrawingWarmlyShip.cs +++ b/WarmlyShip/WarmlyShip/DrawningWarmlyShip.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace WarmlyShip { - internal class DrawingWarmlyShip + internal class DrawningWarmlyShip { public EntityWarmlyShip warmlyShip { protected set; get; } //Класс-сущность protected float _startPosX; //Координаты отрисовки по оси x @@ -17,12 +17,12 @@ namespace WarmlyShip private readonly int _warmlyShipHeight = 50; //Высота отрисовки корабля //Конструктор класса - public DrawingWarmlyShip(int speed, float weight, Color bodyColor) + public DrawningWarmlyShip(int speed, float weight, Color bodyColor) { warmlyShip = new EntityWarmlyShip(speed, weight, bodyColor); } - protected DrawingWarmlyShip(int speed, float weight, Color bodyColor, int warmlyWidth, int warmlyHeight) : this(speed, weight, bodyColor) + protected DrawningWarmlyShip(int speed, float weight, Color bodyColor, int warmlyWidth, int warmlyHeight) : this(speed, weight, bodyColor) { _warmlyShipWidth = warmlyWidth; _warmlyShipHeight = warmlyHeight; diff --git a/WarmlyShip/WarmlyShip/EntityMotorShip.cs b/WarmlyShip/WarmlyShip/EntityMotorShip.cs index a2d5d38..55ddeb5 100644 --- a/WarmlyShip/WarmlyShip/EntityMotorShip.cs +++ b/WarmlyShip/WarmlyShip/EntityMotorShip.cs @@ -9,16 +9,14 @@ namespace WarmlyShip internal class EntityMotorShip : EntityWarmlyShip { 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 bool Tubes { get; private set; } + public bool Cistern { get; private set; } - public EntityMotorShip(int speed, float weight, Color bodyColor, Color dopColor, bool bodyKit, bool wing, bool sportLine) : base(speed, weight, bodyColor) + public EntityMotorShip(int speed, float weight, Color bodyColor, Color dopColor, bool tubes, bool cistern) : base(speed, weight, bodyColor) { DopColor = dopColor; - BodyKit = bodyKit; - Wing = wing; - SportLine = sportLine; + Tubes = tubes; + Cistern = cistern; } } diff --git a/WarmlyShip/WarmlyShip/FormClass.Designer.cs b/WarmlyShip/WarmlyShip/FormClass.Designer.cs index 26dca06..f23d522 100644 --- a/WarmlyShip/WarmlyShip/FormClass.Designer.cs +++ b/WarmlyShip/WarmlyShip/FormClass.Designer.cs @@ -38,6 +38,7 @@ this.buttonLeft = new System.Windows.Forms.Button(); this.buttonDown = new System.Windows.Forms.Button(); this.ButtonCreate = new System.Windows.Forms.Button(); + this.buttonCreateModif = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit(); this.statusStrip.SuspendLayout(); this.SuspendLayout(); @@ -142,11 +143,23 @@ this.ButtonCreate.UseVisualStyleBackColor = true; this.ButtonCreate.Click += new System.EventHandler(this.ButtonCreate_Click); // + // buttonCreateModif + // + this.buttonCreateModif.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.buttonCreateModif.Location = new System.Drawing.Point(93, 402); + this.buttonCreateModif.Name = "buttonCreateModif"; + this.buttonCreateModif.Size = new System.Drawing.Size(100, 23); + this.buttonCreateModif.TabIndex = 8; + this.buttonCreateModif.Text = "Модификация "; + this.buttonCreateModif.UseVisualStyleBackColor = true; + this.buttonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_Click); + // // FormClass // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.buttonCreateModif); this.Controls.Add(this.ButtonCreate); this.Controls.Add(this.buttonDown); this.Controls.Add(this.buttonLeft); @@ -176,5 +189,6 @@ private Button buttonLeft; private Button buttonDown; private Button ButtonCreate; + private Button buttonCreateModif; } } \ No newline at end of file diff --git a/WarmlyShip/WarmlyShip/FormClass.cs b/WarmlyShip/WarmlyShip/FormClass.cs index 02796ed..c28b163 100644 --- a/WarmlyShip/WarmlyShip/FormClass.cs +++ b/WarmlyShip/WarmlyShip/FormClass.cs @@ -2,7 +2,7 @@ namespace WarmlyShip { public partial class FormClass : Form { - private DrawingWarmlyShip _warmlyShip; + private DrawningWarmlyShip _warmlyShip; public FormClass() { @@ -17,14 +17,20 @@ namespace WarmlyShip pictureBox.Image = bmp; } - private void ButtonCreate_Click(object sender, EventArgs e) - { + private void SetData() + { Random random = new Random(); - _warmlyShip = new DrawingWarmlyShip(random.Next(100, 300), random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256))); _warmlyShip.SetPosition(random.Next(pictureBox.Width - 150, pictureBox.Width - 125), random.Next(pictureBox.Height - 150, pictureBox.Height - 50), pictureBox.Width, pictureBox.Height); toolStripStatusSpeed.Text = $": {_warmlyShip.warmlyShip?.Speed}"; toolStripStatusWeight.Text = $": {_warmlyShip.warmlyShip?.Weight}"; toolStripStatusLabelBodyColor.Text = $": {_warmlyShip.warmlyShip?.BodyColor}"; + } + + private void ButtonCreate_Click(object sender, EventArgs e) + { + Random random = new Random(); + _warmlyShip = new DrawningWarmlyShip(random.Next(100, 300), random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256))); + SetData(); Draw(); } @@ -54,5 +60,16 @@ namespace WarmlyShip _warmlyShip?.ChangeBorders(pictureBox.Width, pictureBox.Height); Draw(); } + + private void ButtonCreateModif_Click(object sender, EventArgs e) + { + Random random = new Random(); + _warmlyShip = new DrawningMotorShip(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, 1)), Convert.ToBoolean(random.Next(0, 1))); + SetData(); + Draw(); + } } } \ No newline at end of file -- 2.25.1 From e51d851a3204978d119dd3b7a09438dd9e87cc63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=20=D0=91=D0=BE=D0=BD=D0=B4=D0=B0?= =?UTF-8?q?=D1=80=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Tue, 4 Oct 2022 21:21:25 +0400 Subject: [PATCH 05/14] =?UTF-8?q?=D0=A4=D0=B8=D0=BA=D1=81=D0=B0=D1=86?= =?UTF-8?q?=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WarmlyShip/WarmlyShip/DrawningMotorShip.cs | 16 +++++++++++++--- WarmlyShip/WarmlyShip/DrawningWarmlyShip.cs | 12 ++++++------ WarmlyShip/WarmlyShip/FormClass.cs | 4 ++-- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/WarmlyShip/WarmlyShip/DrawningMotorShip.cs b/WarmlyShip/WarmlyShip/DrawningMotorShip.cs index 7ef8c2c..dd551ca 100644 --- a/WarmlyShip/WarmlyShip/DrawningMotorShip.cs +++ b/WarmlyShip/WarmlyShip/DrawningMotorShip.cs @@ -8,7 +8,7 @@ namespace WarmlyShip { internal class DrawningMotorShip : DrawningWarmlyShip { - public DrawningMotorShip(int speed, float weight, Color bodyColor, Color dopColor, bool tubes, bool cistern) : base(speed, weight, bodyColor, 110, 60) + public DrawningMotorShip(int speed, float weight, Color bodyColor, Color dopColor, bool tubes, bool cistern) : base(speed, weight, bodyColor, 150, 75) { warmlyShip = new EntityMotorShip(speed, weight, bodyColor, dopColor, tubes , cistern); } @@ -20,14 +20,24 @@ namespace WarmlyShip return; } + Pen pen = new(Color.Black, 2); + Brush dopBrush = new SolidBrush(motorShip.DopColor); if (motorShip.Tubes) { - + g.FillRectangle(dopBrush, _startPosX + _warmlyShipWidth / 5, _startPosY, _warmlyShipWidth / 5, _warmlyShipHeight / 2); + g.DrawRectangle(pen, _startPosX + _warmlyShipWidth / 5, _startPosY, _warmlyShipWidth / 5, _warmlyShipHeight / 2); + g.FillRectangle(dopBrush, _startPosX + _warmlyShipWidth * 3 / 5, _startPosY, _warmlyShipWidth / 5, _warmlyShipHeight / 2); + g.DrawRectangle(pen, _startPosX + _warmlyShipWidth * 3 / 5, _startPosY, _warmlyShipWidth / 5, _warmlyShipHeight / 2); } + _startPosY += 25; + base.DrawTransport(g); + _startPosY -= 25; + if (motorShip.Cistern) { - + g.FillEllipse(dopBrush, _startPosX, _startPosY + 25, 25, 20); + g.DrawEllipse(pen, _startPosX, _startPosY + 25, 25, 20); } } } diff --git a/WarmlyShip/WarmlyShip/DrawningWarmlyShip.cs b/WarmlyShip/WarmlyShip/DrawningWarmlyShip.cs index b3e03f1..74f0c7b 100644 --- a/WarmlyShip/WarmlyShip/DrawningWarmlyShip.cs +++ b/WarmlyShip/WarmlyShip/DrawningWarmlyShip.cs @@ -13,8 +13,8 @@ namespace WarmlyShip protected float _startPosY; //Координаты отрисовки по оси y private int? _pictureWidth = null; //Ширина окна private int? _pictureHeight = null; //Высота окна - private readonly int _warmlyShipWidth = 125; //Ширина отрисовки корабля - private readonly int _warmlyShipHeight = 50; //Высота отрисовки корабля + protected readonly int _warmlyShipWidth = 125; //Ширина отрисовки корабля + protected readonly int _warmlyShipHeight = 50; //Высота отрисовки корабля //Конструктор класса public DrawningWarmlyShip(int speed, float weight, Color bodyColor) @@ -73,8 +73,8 @@ namespace WarmlyShip { new Point((int)(_startPosX), (int)(_startPosY + 20)), new Point((int)(_startPosX + _warmlyShipWidth), (int)(_startPosY + 20)), - new Point((int)(_startPosX + _warmlyShipWidth - 25), (int)(_startPosY + _warmlyShipHeight)), - new Point((int)(_startPosX + 25), (int)(_startPosY + _warmlyShipHeight)) + new Point((int)(_startPosX + _warmlyShipWidth - 25), (int)(_startPosY + 50)), + new Point((int)(_startPosX + 25), (int)(_startPosY +50)) }); g.FillRectangle(brush, _startPosX + _warmlyShipWidth / 5, _startPosY, _warmlyShipWidth * 3 / 5, 20); g.FillEllipse(new SolidBrush(Color.Aquamarine), _startPosX + _warmlyShipWidth / 5, _startPosY + 25, 20, 20); @@ -84,8 +84,8 @@ namespace WarmlyShip { new Point((int)(_startPosX), (int)(_startPosY + 20)), new Point((int)(_startPosX + _warmlyShipWidth), (int)(_startPosY + 20)), - new Point((int)(_startPosX + _warmlyShipWidth - 25), (int)(_startPosY + _warmlyShipHeight)), - new Point((int)(_startPosX + 25), (int)(_startPosY + _warmlyShipHeight)) + new Point((int)(_startPosX + _warmlyShipWidth - 25), (int)(_startPosY + 50)), + new Point((int)(_startPosX + 25), (int)(_startPosY + 50)) }); g.DrawRectangle(pen, _startPosX + _warmlyShipWidth / 5, _startPosY, _warmlyShipWidth * 3 / 5, 20); g.DrawEllipse(new(Color.Blue, 2), _startPosX + _warmlyShipWidth / 5, _startPosY + 25, 20, 20); diff --git a/WarmlyShip/WarmlyShip/FormClass.cs b/WarmlyShip/WarmlyShip/FormClass.cs index c28b163..9348d08 100644 --- a/WarmlyShip/WarmlyShip/FormClass.cs +++ b/WarmlyShip/WarmlyShip/FormClass.cs @@ -20,7 +20,7 @@ namespace WarmlyShip private void SetData() { Random random = new Random(); - _warmlyShip.SetPosition(random.Next(pictureBox.Width - 150, pictureBox.Width - 125), random.Next(pictureBox.Height - 150, pictureBox.Height - 50), pictureBox.Width, pictureBox.Height); + _warmlyShip.SetPosition(random.Next(0, 100), random.Next(0, 100), pictureBox.Width, pictureBox.Height); toolStripStatusSpeed.Text = $": {_warmlyShip.warmlyShip?.Speed}"; toolStripStatusWeight.Text = $": {_warmlyShip.warmlyShip?.Weight}"; toolStripStatusLabelBodyColor.Text = $": {_warmlyShip.warmlyShip?.BodyColor}"; @@ -67,7 +67,7 @@ namespace WarmlyShip _warmlyShip = new DrawningMotorShip(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, 1)), Convert.ToBoolean(random.Next(0, 1))); + Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2))); SetData(); Draw(); } -- 2.25.1 From 43563881626f4fb1cbcb463ab21090f3e23840b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=20=D0=91=D0=BE=D0=BD=D0=B4=D0=B0?= =?UTF-8?q?=D1=80=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Tue, 4 Oct 2022 21:57:28 +0400 Subject: [PATCH 06/14] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B8=D0=BD=D1=82=D0=B5=D1=80=D1=84?= =?UTF-8?q?=D0=B5=D0=B9=D1=81=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WarmlyShip/WarmlyShip/DrawningObjectShip.cs | 40 +++++++++++++++++++++ WarmlyShip/WarmlyShip/DrawningWarmlyShip.cs | 5 +++ WarmlyShip/WarmlyShip/IDrawningObject.cs | 17 +++++++++ 3 files changed, 62 insertions(+) create mode 100644 WarmlyShip/WarmlyShip/DrawningObjectShip.cs create mode 100644 WarmlyShip/WarmlyShip/IDrawningObject.cs diff --git a/WarmlyShip/WarmlyShip/DrawningObjectShip.cs b/WarmlyShip/WarmlyShip/DrawningObjectShip.cs new file mode 100644 index 0000000..eaecf5e --- /dev/null +++ b/WarmlyShip/WarmlyShip/DrawningObjectShip.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WarmlyShip +{ + internal class DrawningObjectShip : IDrawningObject + { + private DrawningWarmlyShip _warmlyShip = null; + + public DrawningObjectShip(DrawningWarmlyShip warmlyShip) + { + _warmlyShip = warmlyShip; + } + + public float Step => _warmlyShip?.warmlyShip?.Step ?? 0; + + public void DrawningObject(Graphics g) + { + _warmlyShip?.DrawTransport(g); + } + + public (float Left, float Right, float Top, float Bottom) GetCurrentPosition() + { + return _warmlyShip?.GetCurrentPosition() ?? default; + } + + public void MoveObject(Direction direction) + { + _warmlyShip?.MoveTransport(direction); + } + + public void SetObject(int x, int y, int width, int height) + { + _warmlyShip?.SetPosition(x, y, width, height); + } + } +} diff --git a/WarmlyShip/WarmlyShip/DrawningWarmlyShip.cs b/WarmlyShip/WarmlyShip/DrawningWarmlyShip.cs index 74f0c7b..d6624ae 100644 --- a/WarmlyShip/WarmlyShip/DrawningWarmlyShip.cs +++ b/WarmlyShip/WarmlyShip/DrawningWarmlyShip.cs @@ -114,5 +114,10 @@ namespace WarmlyShip } } + + public (float Left, float Right, float Top, float Bottom) GetCurrentPosition() + { + return (_startPosX, _startPosY, _startPosX + _warmlyShipWidth, _startPosY + _warmlyShipHeight); + } } } diff --git a/WarmlyShip/WarmlyShip/IDrawningObject.cs b/WarmlyShip/WarmlyShip/IDrawningObject.cs new file mode 100644 index 0000000..a732b2c --- /dev/null +++ b/WarmlyShip/WarmlyShip/IDrawningObject.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WarmlyShip +{ + internal interface IDrawningObject + { + public float Step { get; } + 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 7156ff90951240d3b83ae89a960cd73bace08979 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=20=D0=91=D0=BE=D0=BD=D0=B4=D0=B0?= =?UTF-8?q?=D1=80=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Tue, 4 Oct 2022 22:41:50 +0400 Subject: [PATCH 07/14] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BB=20?= =?UTF-8?q?=D1=84=D0=BE=D1=80=D0=BC=D1=83.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WarmlyShip/WarmlyShip/AbstractMap.cs | 87 ++++++++++++++++ WarmlyShip/WarmlyShip/FormMap.Designer.cs | 51 +++++++++ WarmlyShip/WarmlyShip/FormMap.cs | 20 ++++ WarmlyShip/WarmlyShip/FormMap.resx | 120 ++++++++++++++++++++++ WarmlyShip/WarmlyShip/SimpleMap.cs | 50 +++++++++ 5 files changed, 328 insertions(+) create mode 100644 WarmlyShip/WarmlyShip/AbstractMap.cs create mode 100644 WarmlyShip/WarmlyShip/FormMap.Designer.cs create mode 100644 WarmlyShip/WarmlyShip/FormMap.cs create mode 100644 WarmlyShip/WarmlyShip/FormMap.resx create mode 100644 WarmlyShip/WarmlyShip/SimpleMap.cs diff --git a/WarmlyShip/WarmlyShip/AbstractMap.cs b/WarmlyShip/WarmlyShip/AbstractMap.cs new file mode 100644 index 0000000..b488da9 --- /dev/null +++ b/WarmlyShip/WarmlyShip/AbstractMap.cs @@ -0,0 +1,87 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WarmlyShip +{ + internal abstract class AbstractMap + { + private IDrawningObject _drawningObject = 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, IDrawningObject drawningObject) + { + _width = width; + _height = height; + _drawningObject = drawningObject; + GenerateMap(); + while (!SetObjectOnMap()) + { + GenerateMap(); + } + return DrawMapWithObject(); + } + + public Bitmap MoveObject(Direction direction) + { + // TODO проверка, что объект может переместится в требуемомнаправлении + if (true) + { + _drawningObject.MoveObject(direction); + } + return DrawMapWithObject(); + } + private bool SetObjectOnMap() + { + if (_drawningObject == null || _map == null) + { + return false; + } + int x = _random.Next(0, 10); + int y = _random.Next(0, 10); + _drawningObject.SetObject(x, y, _width, _height); + // TODO првоерка, что объект не "накладывается" на закрытые участки + return true; + } + private Bitmap DrawMapWithObject() + { + Bitmap bmp = new(_width, _height); + if (_drawningObject == 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); + } + } + } + _drawningObject.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/WarmlyShip/WarmlyShip/FormMap.Designer.cs b/WarmlyShip/WarmlyShip/FormMap.Designer.cs new file mode 100644 index 0000000..820357b --- /dev/null +++ b/WarmlyShip/WarmlyShip/FormMap.Designer.cs @@ -0,0 +1,51 @@ +namespace WarmlyShip +{ + 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.components = new System.ComponentModel.Container(); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Text = "FormMap"; + } + + #endregion + + private PictureBox pictureBox; + private StatusStrip statusStrip; + private ToolStripStatusLabel toolStripStatusSpeed; + private ToolStripStatusLabel toolStripStatusWeight; + private ToolStripStatusLabel toolStripStatusLabelBodyColor; + private Button buttonRight; + private Button buttonUp; + private Button buttonLeft; + private Button buttonDown; + private Button ButtonCreate; + private Button buttonCreateModif; + } +} \ No newline at end of file diff --git a/WarmlyShip/WarmlyShip/FormMap.cs b/WarmlyShip/WarmlyShip/FormMap.cs new file mode 100644 index 0000000..1463ce6 --- /dev/null +++ b/WarmlyShip/WarmlyShip/FormMap.cs @@ -0,0 +1,20 @@ +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 WarmlyShip +{ + public partial class FormMap : Form + { + public FormMap() + { + InitializeComponent(); + } + } +} diff --git a/WarmlyShip/WarmlyShip/FormMap.resx b/WarmlyShip/WarmlyShip/FormMap.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/WarmlyShip/WarmlyShip/FormMap.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + \ No newline at end of file diff --git a/WarmlyShip/WarmlyShip/SimpleMap.cs b/WarmlyShip/WarmlyShip/SimpleMap.cs new file mode 100644 index 0000000..af1828d --- /dev/null +++ b/WarmlyShip/WarmlyShip/SimpleMap.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WarmlyShip +{ + internal class SimpleMap : AbstractMap + { + private readonly Brush barrierColor = new SolidBrush(Color.Black); + + 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, i * (_size_x + + 1), j * (_size_y + 1)); + } + protected override void DrawRoadPart(Graphics g, int i, int j) + { + g.FillRectangle(roadColor, 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 7e680a1319bbee41c91ef3e61517f7b032041b49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=20=D0=91=D0=BE=D0=BD=D0=B4=D0=B0?= =?UTF-8?q?=D1=80=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Tue, 4 Oct 2022 23:44:07 +0400 Subject: [PATCH 08/14] =?UTF-8?q?=D0=94=D0=BE=D0=B4=D0=B5=D0=BB=D0=B0?= =?UTF-8?q?=D0=BB=20=D0=BB=D0=B0=D0=B1=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WarmlyShip/WarmlyShip/AbstractMap.cs | 2 - WarmlyShip/WarmlyShip/Direction.cs | 1 + WarmlyShip/WarmlyShip/FormMap.Designer.cs | 159 +++++++++++++++++++++- WarmlyShip/WarmlyShip/FormMap.cs | 62 +++++++++ WarmlyShip/WarmlyShip/FormMap.resx | 65 +-------- WarmlyShip/WarmlyShip/Program.cs | 2 +- 6 files changed, 226 insertions(+), 65 deletions(-) diff --git a/WarmlyShip/WarmlyShip/AbstractMap.cs b/WarmlyShip/WarmlyShip/AbstractMap.cs index b488da9..d0fdf65 100644 --- a/WarmlyShip/WarmlyShip/AbstractMap.cs +++ b/WarmlyShip/WarmlyShip/AbstractMap.cs @@ -82,6 +82,4 @@ namespace WarmlyShip protected abstract void DrawRoadPart(Graphics g, int i, int j); protected abstract void DrawBarrierPart(Graphics g, int i, int j); } - -} } diff --git a/WarmlyShip/WarmlyShip/Direction.cs b/WarmlyShip/WarmlyShip/Direction.cs index fa7a4e8..09a6267 100644 --- a/WarmlyShip/WarmlyShip/Direction.cs +++ b/WarmlyShip/WarmlyShip/Direction.cs @@ -8,6 +8,7 @@ namespace WarmlyShip { internal enum Direction //Направление при перемещении { + None = 0, Left = 1, //Влево Up = 2, //Вверх Right = 3, //Вправо diff --git a/WarmlyShip/WarmlyShip/FormMap.Designer.cs b/WarmlyShip/WarmlyShip/FormMap.Designer.cs index 820357b..2b82e57 100644 --- a/WarmlyShip/WarmlyShip/FormMap.Designer.cs +++ b/WarmlyShip/WarmlyShip/FormMap.Designer.cs @@ -28,10 +28,166 @@ /// private void InitializeComponent() { - this.components = new System.ComponentModel.Container(); + this.pictureBox = new System.Windows.Forms.PictureBox(); + this.statusStrip = new System.Windows.Forms.StatusStrip(); + this.toolStripStatusSpeed = new System.Windows.Forms.ToolStripStatusLabel(); + this.toolStripStatusWeight = new System.Windows.Forms.ToolStripStatusLabel(); + this.toolStripStatusLabelBodyColor = new System.Windows.Forms.ToolStripStatusLabel(); + this.buttonRight = new System.Windows.Forms.Button(); + this.buttonUp = new System.Windows.Forms.Button(); + this.buttonLeft = new System.Windows.Forms.Button(); + this.buttonDown = new System.Windows.Forms.Button(); + this.ButtonCreate = new System.Windows.Forms.Button(); + this.buttonCreateModif = new System.Windows.Forms.Button(); + this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit(); + this.statusStrip.SuspendLayout(); + this.SuspendLayout(); + // + // pictureBox + // + this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill; + this.pictureBox.Location = new System.Drawing.Point(0, 0); + this.pictureBox.Name = "pictureBox"; + this.pictureBox.Size = new System.Drawing.Size(800, 428); + this.pictureBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; + this.pictureBox.TabIndex = 0; + this.pictureBox.TabStop = false; + // + // statusStrip + // + this.statusStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.toolStripStatusSpeed, + this.toolStripStatusWeight, + this.toolStripStatusLabelBodyColor}); + this.statusStrip.Location = new System.Drawing.Point(0, 428); + this.statusStrip.Name = "statusStrip"; + this.statusStrip.Size = new System.Drawing.Size(800, 22); + this.statusStrip.TabIndex = 1; + this.statusStrip.Text = "statusStrip1"; + // + // toolStripStatusSpeed + // + this.toolStripStatusSpeed.Name = "toolStripStatusSpeed"; + this.toolStripStatusSpeed.Size = new System.Drawing.Size(62, 17); + this.toolStripStatusSpeed.Text = "Скорость:"; + // + // toolStripStatusWeight + // + this.toolStripStatusWeight.Name = "toolStripStatusWeight"; + this.toolStripStatusWeight.Size = new System.Drawing.Size(29, 17); + this.toolStripStatusWeight.Text = "Вес:"; + // + // toolStripStatusLabelBodyColor + // + this.toolStripStatusLabelBodyColor.Name = "toolStripStatusLabelBodyColor"; + this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(36, 17); + this.toolStripStatusLabelBodyColor.Text = "Цвет:"; + // + // buttonRight + // + this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonRight.BackgroundImage = global::WarmlyShip.Properties.Resources.toright; + this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonRight.Location = new System.Drawing.Point(738, 375); + this.buttonRight.Name = "buttonRight"; + this.buttonRight.Size = new System.Drawing.Size(50, 50); + this.buttonRight.TabIndex = 3; + this.buttonRight.UseVisualStyleBackColor = true; + this.buttonRight.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::WarmlyShip.Properties.Resources.totop; + this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonUp.Location = new System.Drawing.Point(682, 319); + this.buttonUp.Name = "buttonUp"; + this.buttonUp.Size = new System.Drawing.Size(50, 50); + this.buttonUp.TabIndex = 4; + 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::WarmlyShip.Properties.Resources.toleft; + this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonLeft.Location = new System.Drawing.Point(626, 375); + this.buttonLeft.Name = "buttonLeft"; + this.buttonLeft.Size = new System.Drawing.Size(50, 50); + this.buttonLeft.TabIndex = 5; + this.buttonLeft.UseVisualStyleBackColor = true; + this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click); + // + // buttonDown + // + this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonDown.BackgroundImage = global::WarmlyShip.Properties.Resources.todown; + this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonDown.Location = new System.Drawing.Point(682, 375); + this.buttonDown.Name = "buttonDown"; + this.buttonDown.Size = new System.Drawing.Size(50, 50); + this.buttonDown.TabIndex = 6; + this.buttonDown.UseVisualStyleBackColor = true; + this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click); + // + // 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, 402); + this.ButtonCreate.Name = "ButtonCreate"; + this.ButtonCreate.Size = new System.Drawing.Size(75, 23); + this.ButtonCreate.TabIndex = 7; + this.ButtonCreate.Text = "Создать"; + this.ButtonCreate.UseVisualStyleBackColor = true; + this.ButtonCreate.Click += new System.EventHandler(this.ButtonCreate_Click); + // + // buttonCreateModif + // + this.buttonCreateModif.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.buttonCreateModif.Location = new System.Drawing.Point(93, 402); + this.buttonCreateModif.Name = "buttonCreateModif"; + this.buttonCreateModif.Size = new System.Drawing.Size(100, 23); + this.buttonCreateModif.TabIndex = 8; + this.buttonCreateModif.Text = "Модификация "; + 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 = 9; + this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.СomboBoxSelectorMap_SelectedIndexChanged); + // + // FormMap + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.comboBoxSelectorMap); + this.Controls.Add(this.buttonCreateModif); + this.Controls.Add(this.ButtonCreate); + this.Controls.Add(this.buttonDown); + this.Controls.Add(this.buttonLeft); + this.Controls.Add(this.buttonUp); + this.Controls.Add(this.buttonRight); + this.Controls.Add(this.pictureBox); + this.Controls.Add(this.statusStrip); + this.Name = "FormMap"; this.Text = "FormMap"; + ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit(); + this.statusStrip.ResumeLayout(false); + this.statusStrip.PerformLayout(); + this.ResumeLayout(false); + this.PerformLayout(); + } #endregion @@ -47,5 +203,6 @@ private Button buttonDown; private Button ButtonCreate; private Button buttonCreateModif; + private ComboBox comboBoxSelectorMap; } } \ No newline at end of file diff --git a/WarmlyShip/WarmlyShip/FormMap.cs b/WarmlyShip/WarmlyShip/FormMap.cs index 1463ce6..7dd8e94 100644 --- a/WarmlyShip/WarmlyShip/FormMap.cs +++ b/WarmlyShip/WarmlyShip/FormMap.cs @@ -12,9 +12,71 @@ namespace WarmlyShip { public partial class FormMap : Form { + private AbstractMap _abstractMap; + public FormMap() { InitializeComponent(); + _abstractMap = new SimpleMap(); + } + + private void SetData(DrawningWarmlyShip warmlyShip) + { + toolStripStatusSpeed.Text = $"Скорость: {warmlyShip.warmlyShip?.Speed}"; + toolStripStatusWeight.Text = $"Вес: {warmlyShip.warmlyShip?.Weight}"; + toolStripStatusLabelBodyColor.Text = $"Цвет: {warmlyShip.warmlyShip?.BodyColor}"; + pictureBox.Image = _abstractMap.CreateMap(pictureBox.Width, pictureBox.Height, new DrawningObjectShip(warmlyShip)); + } + + + private void ButtonCreate_Click(object sender, EventArgs e) + { + Random random = new Random(); + var warmlyShip = new DrawningWarmlyShip(random.Next(100, 300), random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256))); + SetData(warmlyShip); + } + + private void ButtonMove_Click(object sender, EventArgs e) + { + string name = ((Button)sender)?.Name ?? string.Empty; + Direction direction = Direction.None; + switch (name) + { + case "buttonLeft": + direction = Direction.Left; + break; + case "buttonUp": + direction = Direction.Up; + break; + case "buttonRight": + direction = Direction.Right; + break; + case "buttonDown": + direction = Direction.Down; + break; + } + pictureBox.Image = _abstractMap?.MoveObject(direction); + } + + private void ButtonCreateModif_Click(object sender, EventArgs e) + { + Random random = new Random(); + var warmlyShip = new DrawningMotorShip(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))); + SetData(warmlyShip); + } + + private void СomboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e) + { + switch (comboBoxSelectorMap.Text) + { + case "Простая карта": + _abstractMap = new SimpleMap(); + break; + } + } } } diff --git a/WarmlyShip/WarmlyShip/FormMap.resx b/WarmlyShip/WarmlyShip/FormMap.resx index 1af7de1..2c0949d 100644 --- a/WarmlyShip/WarmlyShip/FormMap.resx +++ b/WarmlyShip/WarmlyShip/FormMap.resx @@ -1,64 +1,4 @@ - - - + @@ -117,4 +57,7 @@ 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/WarmlyShip/WarmlyShip/Program.cs b/WarmlyShip/WarmlyShip/Program.cs index a894d54..9bf5de7 100644 --- a/WarmlyShip/WarmlyShip/Program.cs +++ b/WarmlyShip/WarmlyShip/Program.cs @@ -11,7 +11,7 @@ namespace WarmlyShip // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormClass()); + Application.Run(new FormMap()); } } } \ No newline at end of file -- 2.25.1 From 64eab1b261bd4a1dc55a26eaf574744254324ba3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=20=D0=91=D0=BE=D0=BD=D0=B4=D0=B0?= =?UTF-8?q?=D1=80=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Wed, 5 Oct 2022 00:01:13 +0400 Subject: [PATCH 09/14] =?UTF-8?q?=D0=9F=D0=BE=D1=87=D0=B8=D0=BD=D0=B8?= =?UTF-8?q?=D0=BB=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WarmlyShip/WarmlyShip/SimpleMap.cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/WarmlyShip/WarmlyShip/SimpleMap.cs b/WarmlyShip/WarmlyShip/SimpleMap.cs index af1828d..88588f1 100644 --- a/WarmlyShip/WarmlyShip/SimpleMap.cs +++ b/WarmlyShip/WarmlyShip/SimpleMap.cs @@ -14,13 +14,11 @@ namespace WarmlyShip 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)); + g.FillRectangle(barrierColor, i * _size_x, j * _size_y, 20, 20); } protected override void DrawRoadPart(Graphics g, int i, int j) { - g.FillRectangle(roadColor, i * _size_x, j * _size_y, i * (_size_x + - 1), j * (_size_y + 1)); + g.FillRectangle(roadColor, i * _size_x, j * _size_y, 20, 20); } protected override void GenerateMap() { -- 2.25.1 From 5aa3e08ed084493c92a65a20f87341c07af5c123 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=20=D0=91=D0=BE=D0=BD=D0=B4=D0=B0?= =?UTF-8?q?=D1=80=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Wed, 5 Oct 2022 00:41:14 +0400 Subject: [PATCH 10/14] =?UTF-8?q?=D0=A4=D0=B8=D0=BA=D1=81=D0=B0=D1=86?= =?UTF-8?q?=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WarmlyShip/WarmlyShip/AbstractMap.cs | 29 +++++++++++++++++++++++++++- WarmlyShip/WarmlyShip/SimpleMap.cs | 4 ++-- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/WarmlyShip/WarmlyShip/AbstractMap.cs b/WarmlyShip/WarmlyShip/AbstractMap.cs index d0fdf65..76b877b 100644 --- a/WarmlyShip/WarmlyShip/AbstractMap.cs +++ b/WarmlyShip/WarmlyShip/AbstractMap.cs @@ -32,10 +32,37 @@ namespace WarmlyShip return DrawMapWithObject(); } + private bool CanMove(Direction direction) + { + for (int i = 0; i < _map.GetLength(0); ++i) + { + for (int j = 0; j < _map.GetLength(1); ++j) + { + if (direction == Direction.Left && _drawningObject.GetCurrentPosition().Left - _drawningObject.Step < i * _size_x && _drawningObject.GetCurrentPosition().Left > i * _size_x + _size_x && _map[i,j] == _barrier) + { + return false; + } + else if (direction == Direction.Up && _drawningObject.GetCurrentPosition().Top - _drawningObject.Step < j * _size_y && _drawningObject.GetCurrentPosition().Top > j * _size_y + _size_y && _map[i, j] == _barrier) + { + return false; + } + else if (direction == Direction.Right && _drawningObject.GetCurrentPosition().Right < i * _size_x && _drawningObject.GetCurrentPosition().Right + _drawningObject.Step > i * _size_x + _size_x && _map[i, j] == _barrier) + { + return false; + } + else if (direction == Direction.Down && _drawningObject.GetCurrentPosition().Bottom < j * _size_y && _drawningObject.GetCurrentPosition().Bottom + _drawningObject.Step > j * _size_y + _size_y && _map[i, j] == _barrier) + { + return false; + } + } + } + return true; + } + public Bitmap MoveObject(Direction direction) { // TODO проверка, что объект может переместится в требуемомнаправлении - if (true) + if (CanMove(direction)) { _drawningObject.MoveObject(direction); } diff --git a/WarmlyShip/WarmlyShip/SimpleMap.cs b/WarmlyShip/WarmlyShip/SimpleMap.cs index 88588f1..9d9cd7d 100644 --- a/WarmlyShip/WarmlyShip/SimpleMap.cs +++ b/WarmlyShip/WarmlyShip/SimpleMap.cs @@ -14,11 +14,11 @@ namespace WarmlyShip protected override void DrawBarrierPart(Graphics g, int i, int j) { - g.FillRectangle(barrierColor, i * _size_x, j * _size_y, 20, 20); + 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, 20, 20); + g.FillRectangle(roadColor, i * _size_x, j * _size_y, _size_x, _size_y); } protected override void GenerateMap() { -- 2.25.1 From 18aeff98724341ff73546b935ec81a8e622fd28a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=20=D0=91=D0=BE=D0=BD=D0=B4=D0=B0?= =?UTF-8?q?=D1=80=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Wed, 5 Oct 2022 11:04:05 +0400 Subject: [PATCH 11/14] =?UTF-8?q?=D0=A4=D0=B8=D0=BA=D1=81=D0=B0=D1=86?= =?UTF-8?q?=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WarmlyShip/WarmlyShip/AbstractMap.cs | 53 +++++++++++-------- WarmlyShip/WarmlyShip/DrawningWarmlyShip.cs | 2 +- WarmlyShip/WarmlyShip/FormMap.Designer.cs | 4 +- WarmlyShip/WarmlyShip/FormMap.cs | 6 +++ WarmlyShip/WarmlyShip/LastMap.cs | 55 ++++++++++++++++++++ WarmlyShip/WarmlyShip/SecondMap.cs | 57 +++++++++++++++++++++ WarmlyShip/WarmlyShip/SimpleMap.cs | 4 +- 7 files changed, 155 insertions(+), 26 deletions(-) create mode 100644 WarmlyShip/WarmlyShip/LastMap.cs create mode 100644 WarmlyShip/WarmlyShip/SecondMap.cs diff --git a/WarmlyShip/WarmlyShip/AbstractMap.cs b/WarmlyShip/WarmlyShip/AbstractMap.cs index 76b877b..a28a2b6 100644 --- a/WarmlyShip/WarmlyShip/AbstractMap.cs +++ b/WarmlyShip/WarmlyShip/AbstractMap.cs @@ -32,28 +32,13 @@ namespace WarmlyShip return DrawMapWithObject(); } - private bool CanMove(Direction direction) + private bool CanMove(Direction direction, (float Left, float Right, float Top, float Bottom) position) { - for (int i = 0; i < _map.GetLength(0); ++i) + for (int i = (int)(position.Top / _size_y); i <= (int)(position.Bottom / _size_y); ++i) { - for (int j = 0; j < _map.GetLength(1); ++j) + for (int j = (int)(position.Left / _size_x); j <= (int)(position.Right / _size_x); ++j) { - if (direction == Direction.Left && _drawningObject.GetCurrentPosition().Left - _drawningObject.Step < i * _size_x && _drawningObject.GetCurrentPosition().Left > i * _size_x + _size_x && _map[i,j] == _barrier) - { - return false; - } - else if (direction == Direction.Up && _drawningObject.GetCurrentPosition().Top - _drawningObject.Step < j * _size_y && _drawningObject.GetCurrentPosition().Top > j * _size_y + _size_y && _map[i, j] == _barrier) - { - return false; - } - else if (direction == Direction.Right && _drawningObject.GetCurrentPosition().Right < i * _size_x && _drawningObject.GetCurrentPosition().Right + _drawningObject.Step > i * _size_x + _size_x && _map[i, j] == _barrier) - { - return false; - } - else if (direction == Direction.Down && _drawningObject.GetCurrentPosition().Bottom < j * _size_y && _drawningObject.GetCurrentPosition().Bottom + _drawningObject.Step > j * _size_y + _size_y && _map[i, j] == _barrier) - { - return false; - } + if (i >= 0 && j >= 0 && _map[i, j] == _barrier) return false; } } return true; @@ -61,13 +46,31 @@ namespace WarmlyShip public Bitmap MoveObject(Direction direction) { - // TODO проверка, что объект может переместится в требуемомнаправлении - if (CanMove(direction)) + (float Left, float Right, float Top, float Bottom) position = _drawningObject.GetCurrentPosition(); + if (direction == Direction.Left) + { + position.Left -= _drawningObject.Step; + } + else if (direction == Direction.Right) + { + position.Right += _drawningObject.Step; + } + else if (direction == Direction.Up) + { + position.Top -= _drawningObject.Step; + } + else if (direction == Direction.Down) + { + position.Bottom += _drawningObject.Step; + } + + if (CanMove(direction, position)) { _drawningObject.MoveObject(direction); } return DrawMapWithObject(); } + private bool SetObjectOnMap() { if (_drawningObject == null || _map == null) @@ -77,7 +80,13 @@ namespace WarmlyShip int x = _random.Next(0, 10); int y = _random.Next(0, 10); _drawningObject.SetObject(x, y, _width, _height); - // TODO првоерка, что объект не "накладывается" на закрытые участки + for (int i = (int)(_drawningObject.GetCurrentPosition().Top / _size_y); i <= (int)(_drawningObject.GetCurrentPosition().Bottom / _size_y); ++i) + { + for (int j = (int)(_drawningObject.GetCurrentPosition().Left / _size_x); j <= (int)(_drawningObject.GetCurrentPosition().Right / _size_x); ++j) + { + if (_map[i, j] == _barrier) return false; + } + } return true; } private Bitmap DrawMapWithObject() diff --git a/WarmlyShip/WarmlyShip/DrawningWarmlyShip.cs b/WarmlyShip/WarmlyShip/DrawningWarmlyShip.cs index d6624ae..b6df0c9 100644 --- a/WarmlyShip/WarmlyShip/DrawningWarmlyShip.cs +++ b/WarmlyShip/WarmlyShip/DrawningWarmlyShip.cs @@ -117,7 +117,7 @@ namespace WarmlyShip public (float Left, float Right, float Top, float Bottom) GetCurrentPosition() { - return (_startPosX, _startPosY, _startPosX + _warmlyShipWidth, _startPosY + _warmlyShipHeight); + return (_startPosX, _startPosX + _warmlyShipWidth, _startPosY, _startPosY + _warmlyShipHeight); } } } diff --git a/WarmlyShip/WarmlyShip/FormMap.Designer.cs b/WarmlyShip/WarmlyShip/FormMap.Designer.cs index 2b82e57..f89a930 100644 --- a/WarmlyShip/WarmlyShip/FormMap.Designer.cs +++ b/WarmlyShip/WarmlyShip/FormMap.Designer.cs @@ -159,7 +159,9 @@ 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/WarmlyShip/WarmlyShip/FormMap.cs b/WarmlyShip/WarmlyShip/FormMap.cs index 7dd8e94..57b6071 100644 --- a/WarmlyShip/WarmlyShip/FormMap.cs +++ b/WarmlyShip/WarmlyShip/FormMap.cs @@ -75,6 +75,12 @@ namespace WarmlyShip case "Простая карта": _abstractMap = new SimpleMap(); break; + case "Вторая карта": + _abstractMap = new SecondMap(); + break; + case "Последняя карта": + _abstractMap = new LastMap(); + break; } } diff --git a/WarmlyShip/WarmlyShip/LastMap.cs b/WarmlyShip/WarmlyShip/LastMap.cs new file mode 100644 index 0000000..9cede84 --- /dev/null +++ b/WarmlyShip/WarmlyShip/LastMap.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WarmlyShip +{ + internal class LastMap : AbstractMap + { + private readonly Brush barrierColor = new SolidBrush(Color.Red); + + private readonly Brush roadColor = new SolidBrush(Color.Green); + + protected override void DrawBarrierPart(Graphics g, int i, int j) + { + g.FillRectangle(barrierColor, j * _size_x, i * _size_y, _size_x, _size_y); + } + protected override void DrawRoadPart(Graphics g, int i, int j) + { + g.FillRectangle(roadColor, j * _size_x, i * _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; + } + } + while (counter < 45) + { + int x = _random.Next(0, 100); + int y = _random.Next(0, 100); + if (_map[x, y] == _freeRoad) + { + _map[x, y] = _barrier; + if (x > 0 && y > 0 && x < _map.GetLength(0) - 1 && y < _map.GetLength(1) - 1) + { + _map[x - 1, y] = _barrier; + _map[x + 1, y] = _barrier; + _map[x, y - 1] = _barrier; + _map[x, y + 1] = _barrier; + } + counter++; + } + } + } + } +} diff --git a/WarmlyShip/WarmlyShip/SecondMap.cs b/WarmlyShip/WarmlyShip/SecondMap.cs new file mode 100644 index 0000000..e3674f0 --- /dev/null +++ b/WarmlyShip/WarmlyShip/SecondMap.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WarmlyShip +{ + internal class SecondMap : AbstractMap + { + private readonly Brush barrierColor = new SolidBrush(Color.Gold); + + private readonly Brush roadColor = new SolidBrush(Color.Black); + + protected override void DrawBarrierPart(Graphics g, int i, int j) + { + g.FillRectangle(barrierColor, j * _size_x, i * _size_y, _size_x, _size_y); + } + protected override void DrawRoadPart(Graphics g, int i, int j) + { + g.FillRectangle(roadColor, j * _size_x, i * _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; + } + } + for (int i = 0; i < _map.GetLength(0); ++i) + { + _map[i, _map.GetLength(1) / 2] = _barrier; + _map[i, _map.GetLength(1) - 1] = _barrier; + } + for (int j = 0; j < _map.GetLength(1); ++j) + { + _map[_map.GetLength(0) - 1, j] = _barrier; + } + while (counter < 45) + { + int x = _random.Next(0, 100); + int y = _random.Next(0, 100); + if (_map[x, y] == _freeRoad) + { + _map[x, y] = _barrier; + counter++; + } + } + } + } +} diff --git a/WarmlyShip/WarmlyShip/SimpleMap.cs b/WarmlyShip/WarmlyShip/SimpleMap.cs index 9d9cd7d..88ac895 100644 --- a/WarmlyShip/WarmlyShip/SimpleMap.cs +++ b/WarmlyShip/WarmlyShip/SimpleMap.cs @@ -14,11 +14,11 @@ namespace WarmlyShip protected override void DrawBarrierPart(Graphics g, int i, int j) { - g.FillRectangle(barrierColor, i * _size_x, j * _size_y, _size_x, _size_y); + g.FillRectangle(barrierColor, j * _size_x, i * _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(roadColor, j * _size_x, i * _size_y, _size_x, _size_y); } protected override void GenerateMap() { -- 2.25.1 From 5c14d4e6ccce845aea177f55d843a60d8e72cc53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=20=D0=91=D0=BE=D0=BD=D0=B4=D0=B0?= =?UTF-8?q?=D1=80=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Tue, 18 Oct 2022 18:54:51 +0400 Subject: [PATCH 12/14] =?UTF-8?q?=D0=A4=D0=B8=D0=BA=D1=81=D0=B0=D1=86?= =?UTF-8?q?=D0=B8=D1=8F=20=D0=BB=D0=B0=D0=B1=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WarmlyShip/WarmlyShip/AbstractMap.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WarmlyShip/WarmlyShip/AbstractMap.cs b/WarmlyShip/WarmlyShip/AbstractMap.cs index a28a2b6..21023c3 100644 --- a/WarmlyShip/WarmlyShip/AbstractMap.cs +++ b/WarmlyShip/WarmlyShip/AbstractMap.cs @@ -32,7 +32,7 @@ namespace WarmlyShip return DrawMapWithObject(); } - private bool CanMove(Direction direction, (float Left, float Right, float Top, float Bottom) position) + private bool CanMove(Direction direction, (float Left, float Right, float Top, float Bottom) position) //Проверка на возможность шага { for (int i = (int)(position.Top / _size_y); i <= (int)(position.Bottom / _size_y); ++i) { -- 2.25.1 From 0584c4874c266e94e547ae5af68850df797df6e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=20=D0=91=D0=BE=D0=BD=D0=B4=D0=B0?= =?UTF-8?q?=D1=80=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Tue, 18 Oct 2022 18:57:38 +0400 Subject: [PATCH 13/14] =?UTF-8?q?=D0=BB=D0=B0=D1=81=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WarmlyShip/WarmlyShip/AbstractMap.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WarmlyShip/WarmlyShip/AbstractMap.cs b/WarmlyShip/WarmlyShip/AbstractMap.cs index 21023c3..b05b4fd 100644 --- a/WarmlyShip/WarmlyShip/AbstractMap.cs +++ b/WarmlyShip/WarmlyShip/AbstractMap.cs @@ -38,7 +38,7 @@ namespace WarmlyShip { for (int j = (int)(position.Left / _size_x); j <= (int)(position.Right / _size_x); ++j) { - if (i >= 0 && j >= 0 && _map[i, j] == _barrier) return false; + if (i >= 0 && j >= 0 && i < _map.GetLength(0) && j < _map.GetLength(1) && _map[i, j] == _barrier) return false; } } return true; -- 2.25.1 From e2a51ace3c4183e26f4edf585cf2b4266702df4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=20=D0=91=D0=BE=D0=BD=D0=B4=D0=B0?= =?UTF-8?q?=D1=80=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Tue, 18 Oct 2022 19:56:18 +0400 Subject: [PATCH 14/14] =?UTF-8?q?=D0=9F=D1=80=D0=BE=D0=B1=D0=B0=20=D0=BF?= =?UTF-8?q?=D0=B5=D1=80=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...ningWarmlyShip.cs => DrawingWarmlyShip.cs} | 26 +++++++++---------- WarmlyShip/WarmlyShip/DrawningMotorShip.cs | 2 +- WarmlyShip/WarmlyShip/DrawningObjectShip.cs | 4 +-- WarmlyShip/WarmlyShip/EntityWarmlyShip.cs | 1 + WarmlyShip/WarmlyShip/FormClass.cs | 4 +-- WarmlyShip/WarmlyShip/FormMap.cs | 4 +-- 6 files changed, 21 insertions(+), 20 deletions(-) rename WarmlyShip/WarmlyShip/{DrawningWarmlyShip.cs => DrawingWarmlyShip.cs} (83%) diff --git a/WarmlyShip/WarmlyShip/DrawningWarmlyShip.cs b/WarmlyShip/WarmlyShip/DrawingWarmlyShip.cs similarity index 83% rename from WarmlyShip/WarmlyShip/DrawningWarmlyShip.cs rename to WarmlyShip/WarmlyShip/DrawingWarmlyShip.cs index b6df0c9..de2d7a2 100644 --- a/WarmlyShip/WarmlyShip/DrawningWarmlyShip.cs +++ b/WarmlyShip/WarmlyShip/DrawingWarmlyShip.cs @@ -6,29 +6,29 @@ using System.Threading.Tasks; namespace WarmlyShip { - internal class DrawningWarmlyShip + internal class DrawingWarmlyShip { public EntityWarmlyShip warmlyShip { protected set; get; } //Класс-сущность - protected float _startPosX; //Координаты отрисовки по оси x - protected float _startPosY; //Координаты отрисовки по оси y + public float _startPosX; //Координаты отрисовки по оси x + public float _startPosY; //Координаты отрисовки по оси y private int? _pictureWidth = null; //Ширина окна private int? _pictureHeight = null; //Высота окна protected readonly int _warmlyShipWidth = 125; //Ширина отрисовки корабля protected readonly int _warmlyShipHeight = 50; //Высота отрисовки корабля - //Конструктор класса - public DrawningWarmlyShip(int speed, float weight, Color bodyColor) + //Инициализация + public DrawingWarmlyShip(int speed, float weight, Color bodyColor) { warmlyShip = new EntityWarmlyShip(speed, weight, bodyColor); } - protected DrawningWarmlyShip(int speed, float weight, Color bodyColor, int warmlyWidth, int warmlyHeight) : this(speed, weight, bodyColor) + protected DrawingWarmlyShip(int speed, float weight, Color bodyColor, int warmlyWidth, int warmlyHeight) : this(speed, weight, bodyColor) { _warmlyShipWidth = warmlyWidth; _warmlyShipHeight = warmlyHeight; } - //Начальная позиция коробля + //Начальные коордитанты public void SetPosition(int x, int y, int width, int height) { if (width < _warmlyShipWidth || height < _warmlyShipHeight) return; @@ -39,7 +39,7 @@ namespace WarmlyShip _pictureHeight = height; } - //Функция передвижения объекта + //Движение транспорта по координатам public void MoveTransport(Direction direction) { if (!_pictureWidth.HasValue || !_pictureHeight.HasValue) return; @@ -73,8 +73,8 @@ namespace WarmlyShip { new Point((int)(_startPosX), (int)(_startPosY + 20)), new Point((int)(_startPosX + _warmlyShipWidth), (int)(_startPosY + 20)), - new Point((int)(_startPosX + _warmlyShipWidth - 25), (int)(_startPosY + 50)), - new Point((int)(_startPosX + 25), (int)(_startPosY +50)) + new Point((int)(_startPosX + _warmlyShipWidth - 25), (int)(_startPosY + _warmlyShipHeight)), + new Point((int)(_startPosX + 25), (int)(_startPosY + _warmlyShipHeight)) }); g.FillRectangle(brush, _startPosX + _warmlyShipWidth / 5, _startPosY, _warmlyShipWidth * 3 / 5, 20); g.FillEllipse(new SolidBrush(Color.Aquamarine), _startPosX + _warmlyShipWidth / 5, _startPosY + 25, 20, 20); @@ -84,8 +84,8 @@ namespace WarmlyShip { new Point((int)(_startPosX), (int)(_startPosY + 20)), new Point((int)(_startPosX + _warmlyShipWidth), (int)(_startPosY + 20)), - new Point((int)(_startPosX + _warmlyShipWidth - 25), (int)(_startPosY + 50)), - new Point((int)(_startPosX + 25), (int)(_startPosY + 50)) + new Point((int)(_startPosX + _warmlyShipWidth - 25), (int)(_startPosY + _warmlyShipHeight)), + new Point((int)(_startPosX + 25), (int)(_startPosY + _warmlyShipHeight)) }); g.DrawRectangle(pen, _startPosX + _warmlyShipWidth / 5, _startPosY, _warmlyShipWidth * 3 / 5, 20); g.DrawEllipse(new(Color.Blue, 2), _startPosX + _warmlyShipWidth / 5, _startPosY + 25, 20, 20); @@ -93,7 +93,7 @@ namespace WarmlyShip g.DrawEllipse(new(Color.Blue, 2), _startPosX + _warmlyShipWidth * 2 / 5 + 2.5f, _startPosY + 25, 20, 20); } - //Изменение границ отрисовки + //Изменение границ отрисовки public void ChangeBorders(int width, int height) { _pictureWidth = width; diff --git a/WarmlyShip/WarmlyShip/DrawningMotorShip.cs b/WarmlyShip/WarmlyShip/DrawningMotorShip.cs index dd551ca..0d17867 100644 --- a/WarmlyShip/WarmlyShip/DrawningMotorShip.cs +++ b/WarmlyShip/WarmlyShip/DrawningMotorShip.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace WarmlyShip { - internal class DrawningMotorShip : DrawningWarmlyShip + internal class DrawningMotorShip : DrawingWarmlyShip { public DrawningMotorShip(int speed, float weight, Color bodyColor, Color dopColor, bool tubes, bool cistern) : base(speed, weight, bodyColor, 150, 75) { diff --git a/WarmlyShip/WarmlyShip/DrawningObjectShip.cs b/WarmlyShip/WarmlyShip/DrawningObjectShip.cs index eaecf5e..e9c2b8a 100644 --- a/WarmlyShip/WarmlyShip/DrawningObjectShip.cs +++ b/WarmlyShip/WarmlyShip/DrawningObjectShip.cs @@ -8,9 +8,9 @@ namespace WarmlyShip { internal class DrawningObjectShip : IDrawningObject { - private DrawningWarmlyShip _warmlyShip = null; + private DrawingWarmlyShip _warmlyShip = null; - public DrawningObjectShip(DrawningWarmlyShip warmlyShip) + public DrawningObjectShip(DrawingWarmlyShip warmlyShip) { _warmlyShip = warmlyShip; } diff --git a/WarmlyShip/WarmlyShip/EntityWarmlyShip.cs b/WarmlyShip/WarmlyShip/EntityWarmlyShip.cs index 0049f81..1da24c8 100644 --- a/WarmlyShip/WarmlyShip/EntityWarmlyShip.cs +++ b/WarmlyShip/WarmlyShip/EntityWarmlyShip.cs @@ -13,6 +13,7 @@ namespace WarmlyShip public Color BodyColor { get; private set; } //Цвет public float Step => Speed * 100 / Weight; //Шаг при перемещении + //Инициализация public EntityWarmlyShip(int speed, float weight, Color bodyColor) { Random random = new Random(); diff --git a/WarmlyShip/WarmlyShip/FormClass.cs b/WarmlyShip/WarmlyShip/FormClass.cs index 9348d08..5d1bf94 100644 --- a/WarmlyShip/WarmlyShip/FormClass.cs +++ b/WarmlyShip/WarmlyShip/FormClass.cs @@ -2,7 +2,7 @@ namespace WarmlyShip { public partial class FormClass : Form { - private DrawningWarmlyShip _warmlyShip; + private DrawingWarmlyShip _warmlyShip; public FormClass() { @@ -29,7 +29,7 @@ namespace WarmlyShip private void ButtonCreate_Click(object sender, EventArgs e) { Random random = new Random(); - _warmlyShip = new DrawningWarmlyShip(random.Next(100, 300), random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256))); + _warmlyShip = new DrawingWarmlyShip(random.Next(100, 300), random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256))); SetData(); Draw(); } diff --git a/WarmlyShip/WarmlyShip/FormMap.cs b/WarmlyShip/WarmlyShip/FormMap.cs index 57b6071..3d6c502 100644 --- a/WarmlyShip/WarmlyShip/FormMap.cs +++ b/WarmlyShip/WarmlyShip/FormMap.cs @@ -20,7 +20,7 @@ namespace WarmlyShip _abstractMap = new SimpleMap(); } - private void SetData(DrawningWarmlyShip warmlyShip) + private void SetData(DrawingWarmlyShip warmlyShip) { toolStripStatusSpeed.Text = $"Скорость: {warmlyShip.warmlyShip?.Speed}"; toolStripStatusWeight.Text = $"Вес: {warmlyShip.warmlyShip?.Weight}"; @@ -32,7 +32,7 @@ namespace WarmlyShip private void ButtonCreate_Click(object sender, EventArgs e) { Random random = new Random(); - var warmlyShip = new DrawningWarmlyShip(random.Next(100, 300), random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256))); + var warmlyShip = new DrawingWarmlyShip(random.Next(100, 300), random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256))); SetData(warmlyShip); } -- 2.25.1