From f69a83eccac9661e484a7d19a88586789e4cb3d3 Mon Sep 17 00:00:00 2001 From: Danil Markov Date: Sat, 8 Oct 2022 15:20:39 +0400 Subject: [PATCH 1/4] =?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 --- ContainerShip/ContainerShip/DrawingShip.cs | 6 +++--- ContainerShip/ContainerShip/EntityShip.cs | 2 +- ContainerShip/ContainerShip/FormShip.Designer.cs | 1 + ContainerShip/ContainerShip/FormShip.cs | 8 ++++++-- ContainerShip/ContainerShip/FormShip.resx | 8 ++++---- 5 files changed, 15 insertions(+), 10 deletions(-) diff --git a/ContainerShip/ContainerShip/DrawingShip.cs b/ContainerShip/ContainerShip/DrawingShip.cs index e6478e7..f424618 100644 --- a/ContainerShip/ContainerShip/DrawingShip.cs +++ b/ContainerShip/ContainerShip/DrawingShip.cs @@ -17,10 +17,10 @@ namespace ContainerShip protected readonly int _shipWidth = 100; protected readonly int _shipHeight = 60; - public void Init(int speed, float weight, Color bodyColor) + public DrawingShip(int speed, float weight, Color bodyColor) { - Ship = new EntityShip(); - Ship.Init(speed, weight, bodyColor); + Ship = new EntityShip(speed, weight, bodyColor); + } public void SetPosition(int x, int y, int width, int height) diff --git a/ContainerShip/ContainerShip/EntityShip.cs b/ContainerShip/ContainerShip/EntityShip.cs index 9709ab0..d02adf8 100644 --- a/ContainerShip/ContainerShip/EntityShip.cs +++ b/ContainerShip/ContainerShip/EntityShip.cs @@ -13,7 +13,7 @@ namespace ContainerShip public Color BodyColor { get; private set; } public int Step => (int)Speed * 100 / (int)Weight; - public void Init(int speed, float weight, Color bodyColor) + public EntityShip(int speed, float weight, Color bodyColor) { Random random = new Random(); Speed = speed <= 0 ? random.Next(50, 150) : speed; diff --git a/ContainerShip/ContainerShip/FormShip.Designer.cs b/ContainerShip/ContainerShip/FormShip.Designer.cs index a6db5ae..36ee96d 100644 --- a/ContainerShip/ContainerShip/FormShip.Designer.cs +++ b/ContainerShip/ContainerShip/FormShip.Designer.cs @@ -155,6 +155,7 @@ this.Controls.Add(this.statusStrip); this.Name = "FormShip"; this.Text = "FormShip"; + this.Load += new System.EventHandler(this.FormShip_Load); this.Resize += new System.EventHandler(this.PictureBoxShip_Resize); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxShip)).EndInit(); this.statusStrip.ResumeLayout(false); diff --git a/ContainerShip/ContainerShip/FormShip.cs b/ContainerShip/ContainerShip/FormShip.cs index 569ae8d..2c2735d 100644 --- a/ContainerShip/ContainerShip/FormShip.cs +++ b/ContainerShip/ContainerShip/FormShip.cs @@ -51,8 +51,7 @@ namespace ContainerShip private void ButtonCreate_Click(object sender, EventArgs e) { Random rnd = new(); - _ship = new DrawingShip(); - _ship.Init(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), + _ship = new DrawingShip(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); _ship.SetPosition(rnd.Next(10, 100), rnd.Next(60, 100), pictureBoxShip.Width, pictureBoxShip.Height); toolStripStatusSpeed.Text = $"Скорость: {_ship.Ship.Speed}"; @@ -65,5 +64,10 @@ namespace ContainerShip _ship?.ChangeBorders(pictureBoxShip.Width, pictureBoxShip.Height); Draw(); } + + private void FormShip_Load(object sender, EventArgs e) + { + + } } } diff --git a/ContainerShip/ContainerShip/FormShip.resx b/ContainerShip/ContainerShip/FormShip.resx index b324199..af27dc3 100644 --- a/ContainerShip/ContainerShip/FormShip.resx +++ b/ContainerShip/ContainerShip/FormShip.resx @@ -61,7 +61,7 @@ iVBORw0KGgoAAAANSUhEUgAAAE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VJREFUeF7tkEFuxDAMA/P/T6f1YYtgO1HoxHYowwPMTZAobvvilFVOwConYJUT + vAAADrwBlbxySQAAAaVJREFUeF7tkEFuxDAMA/P/T6f1YYtgO1HoxHYowwPMTZAobvvilFVOwConYJUT sMoJWOUEvFrOtm1/OvJaqmMxrgW9koiKKboxPBGV8tGNoYmokKNuDEtEZXzrxpBEVATpRvdEVMKZbnRN RAVEutEtET1/pRtdEtHjim40T0RPq7rRNBE9XKMbzRLRs47W0KQcCuGsyuNy6Li7Ko/KocMZVLldDh3N osqtcuhgJlWqy6Fj2VSpKocOZVRFnqQjWVWRJulAZlUuJ2l5dlXCSVo8gyqnk7R0FlVwkhbOpMq/SVo2 @@ -97,7 +97,7 @@ iVBORw0KGgoAAAANSUhEUgAAAEMAAABHCAYAAABcW/plAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO - vQAADr0BR/uQrQAAAVdJREFUeF7t0MsOgzAQQ1H+/6epvGhlVQYSMjMJyEfyNo+77fbjGMQxiGMQxyCO + vAAADrwBlbxySQAAAVdJREFUeF7t0MsOgzAQQ1H+/6epvGhlVQYSMjMJyEfyNo+77fbjGMQxiGMQxyCO QRyDOAZxDOIYJDzGtm3lixIaQz20ahEcgzgGcQziGMQxiGMQxyCOQRyDOAZxDOIYxDGIYxDHII5BHIM4 BnEM4hjEMYhjEMcgjkFOT1GXvmXKYQx1wNv2zzGIY5DDGKAOeMuU0xigDnr6jlzGAHXgU3emKQaog5+2 K80xQF3wlLXoigHqotXXqjsGqAtXXY9bMUBdvNp63Y4B6gGr7I6hGKAeMnt3DccA9aBZGxESA9TDqjcq -- 2.25.1 From 86fefa46bf26beec5d0c8ed12efe15c1c3d850ef Mon Sep 17 00:00:00 2001 From: Danil Markov Date: Sat, 8 Oct 2022 17:02:17 +0400 Subject: [PATCH 2/4] =?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 --- .../ContainerShip/DrawingContainerShip.cs | 75 +++++++++++++++++++ ContainerShip/ContainerShip/DrawingShip.cs | 20 +++-- .../ContainerShip/EntityContainerShip.cs | 25 +++++++ .../ContainerShip/FormShip.Designer.cs | 14 +++- ContainerShip/ContainerShip/FormShip.cs | 33 +++++--- ContainerShip/ContainerShip/FormShip.resx | 2 +- 6 files changed, 150 insertions(+), 19 deletions(-) create mode 100644 ContainerShip/ContainerShip/DrawingContainerShip.cs create mode 100644 ContainerShip/ContainerShip/EntityContainerShip.cs diff --git a/ContainerShip/ContainerShip/DrawingContainerShip.cs b/ContainerShip/ContainerShip/DrawingContainerShip.cs new file mode 100644 index 0000000..6901245 --- /dev/null +++ b/ContainerShip/ContainerShip/DrawingContainerShip.cs @@ -0,0 +1,75 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ContainerShip +{ + internal class DrawingContainerShip : DrawingShip + { + public DrawingContainerShip(int speed, float weight, Color bodyColor, Color + dopColor, bool crane, bool containers) : + base(speed, weight, bodyColor, 110, 60) + { + Ship = new EntityContainerShip(speed, weight, bodyColor, dopColor, crane, containers); + } + public override void DrawTransport(Graphics g) + { + if (Ship is not EntityContainerShip containerShip) + { + return; + } + + Pen pen = new(Color.Black); + Brush dopBrush = new SolidBrush(containerShip.DopColor); + Brush brOrange = new SolidBrush(Color.Orange); + + base.DrawTransport(g); + + if (containerShip.Containers) + { + //Границы контейнеров + g.DrawRectangle(pen, _startPosX + 15, _startPosY + 15, 30, 15); + g.DrawRectangle(pen, _startPosX + 55, _startPosY + 15, 30, 15); + //Заливка контейнеров + g.FillRectangle(dopBrush, _startPosX + 16, _startPosY + 16, 29, 14); + g.FillRectangle(dopBrush, _startPosX + 56, _startPosY + 16, 29, 14); + //Заливка центральных полос на контейнерах + g.FillRectangle(brOrange, _startPosX + 16, _startPosY + 20, 29, 5); + g.FillRectangle(brOrange, _startPosX + 56, _startPosY + 20, 29, 5); + } + + if (containerShip.Crane) + { + //Граница стрелы крана + PointF point1 = new PointF(_startPosX + 50, _startPosY + 10); + PointF point2 = new PointF(_startPosX + 90, _startPosY + 13); + PointF point3 = new PointF(_startPosX + 50, _startPosY + 16); + PointF[] craneArrowBorder = new PointF[3] { point1, point2, point3 }; + + //Граница заливки стрелы крана + PointF point4 = new PointF(_startPosX + 51, _startPosY + 10); + PointF point5 = new PointF(_startPosX + 84, _startPosY + 13); + PointF point6 = new PointF(_startPosX + 51, _startPosY + 16); + PointF[] craneArrowFill = new PointF[3] { point4, point5, point6 }; + + g.DrawRectangle(pen, _startPosX + 45, _startPosY, 10, 30); + g.FillRectangle(brOrange, _startPosX + 46, _startPosY + 1, 9, 29); + + g.DrawPolygon(pen, craneArrowBorder); + g.FillPolygon(dopBrush, craneArrowFill); + + //Трос и крепление + g.DrawLine(pen, _startPosX + 90, _startPosY + 14, _startPosX + 90, _startPosY + 40); + g.DrawLine(pen, _startPosX + 90, _startPosY + 40, _startPosX + 85, _startPosY + 43); + g.DrawLine(pen, _startPosX + 90, _startPosY + 40, _startPosX + 90, _startPosY + 45); + g.DrawLine(pen, _startPosX + 90, _startPosY + 40, _startPosX + 95, _startPosY + 43); + } + + + + + } + } +} \ No newline at end of file diff --git a/ContainerShip/ContainerShip/DrawingShip.cs b/ContainerShip/ContainerShip/DrawingShip.cs index f424618..c3e967f 100644 --- a/ContainerShip/ContainerShip/DrawingShip.cs +++ b/ContainerShip/ContainerShip/DrawingShip.cs @@ -8,19 +8,23 @@ namespace ContainerShip { internal class DrawingShip { - public EntityShip Ship { get; private set; } - private float _startPosX; - private float _startPosY; + public EntityShip Ship { get; protected set; } + protected float _startPosX; + protected float _startPosY; private int? _pictureWidth = null; private int? _pictureHeight = null; - protected readonly int _shipWidth = 100; - protected readonly int _shipHeight = 60; - + private readonly int _shipWidth = 100; + private readonly int _shipHeight = 60; public DrawingShip(int speed, float weight, Color bodyColor) { Ship = new EntityShip(speed, weight, bodyColor); - + } + protected DrawingShip(int speed, float weight, Color bodyColor, int shipWidth, + int shipHeight) : this(speed, weight, bodyColor) + { + _shipWidth = shipWidth; + _shipHeight = shipHeight; } public void SetPosition(int x, int y, int width, int height) @@ -77,7 +81,7 @@ namespace ContainerShip } } - public void DrawTransport(Graphics g) + public virtual void DrawTransport(Graphics g) { if (_startPosX < 0 || _startPosY < 0 || !_pictureHeight.HasValue || !_pictureWidth.HasValue) diff --git a/ContainerShip/ContainerShip/EntityContainerShip.cs b/ContainerShip/ContainerShip/EntityContainerShip.cs new file mode 100644 index 0000000..38f8b88 --- /dev/null +++ b/ContainerShip/ContainerShip/EntityContainerShip.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ContainerShip +{ + internal class EntityContainerShip : EntityShip + { + public Color DopColor { get; private set; } + public bool Crane { get; private set; } + public bool Containers { get; private set; } + + public EntityContainerShip(int speed, float weight, Color bodyColor, Color + dopColor, bool crane, bool containers) : + base(speed, weight, bodyColor) + { + DopColor = dopColor; + Crane = crane; + Containers = containers; + } + } + +} diff --git a/ContainerShip/ContainerShip/FormShip.Designer.cs b/ContainerShip/ContainerShip/FormShip.Designer.cs index 36ee96d..408ac3a 100644 --- a/ContainerShip/ContainerShip/FormShip.Designer.cs +++ b/ContainerShip/ContainerShip/FormShip.Designer.cs @@ -39,6 +39,7 @@ this.toolStripStatusSpeed = new System.Windows.Forms.ToolStripStatusLabel(); this.toolStripStatusWeight = new System.Windows.Forms.ToolStripStatusLabel(); this.toolStripStatusBodyColor = new System.Windows.Forms.ToolStripStatusLabel(); + this.buttonCreateModif = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxShip)).BeginInit(); this.statusStrip.SuspendLayout(); this.SuspendLayout(); @@ -141,11 +142,22 @@ this.toolStripStatusBodyColor.Size = new System.Drawing.Size(39, 17); this.toolStripStatusBodyColor.Text = "Цвет: "; // + // buttonCreateModif + // + this.buttonCreateModif.Location = new System.Drawing.Point(94, 402); + this.buttonCreateModif.Name = "buttonCreateModif"; + this.buttonCreateModif.Size = new System.Drawing.Size(110, 23); + this.buttonCreateModif.TabIndex = 10; + this.buttonCreateModif.Text = "Модификация"; + this.buttonCreateModif.UseVisualStyleBackColor = true; + this.buttonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_Click); + // // FormShip // 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.buttonDown); this.Controls.Add(this.buttonLeft); this.Controls.Add(this.buttonRight); @@ -155,7 +167,6 @@ this.Controls.Add(this.statusStrip); this.Name = "FormShip"; this.Text = "FormShip"; - this.Load += new System.EventHandler(this.FormShip_Load); this.Resize += new System.EventHandler(this.PictureBoxShip_Resize); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxShip)).EndInit(); this.statusStrip.ResumeLayout(false); @@ -177,5 +188,6 @@ private ToolStripStatusLabel toolStripStatusSpeed; private ToolStripStatusLabel toolStripStatusWeight; private ToolStripStatusLabel toolStripStatusBodyColor; + private Button buttonCreateModif; } } \ No newline at end of file diff --git a/ContainerShip/ContainerShip/FormShip.cs b/ContainerShip/ContainerShip/FormShip.cs index 2c2735d..bdf915b 100644 --- a/ContainerShip/ContainerShip/FormShip.cs +++ b/ContainerShip/ContainerShip/FormShip.cs @@ -48,26 +48,41 @@ namespace ContainerShip Draw(); } + private void SetData() + { + Random rnd = new(); + toolStripStatusSpeed.Text = $"Скорость: {_ship.Ship.Speed}"; + toolStripStatusWeight.Text = $"Вес: {_ship.Ship.Weight}"; + toolStripStatusBodyColor.Text = $"Цвет: {_ship.Ship.BodyColor.Name}"; + _ship.SetPosition(rnd.Next(10, 100), rnd.Next(60, 100), pictureBoxShip.Width, pictureBoxShip.Height); + } + private void ButtonCreate_Click(object sender, EventArgs e) { Random rnd = new(); _ship = new DrawingShip(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), - rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); - _ship.SetPosition(rnd.Next(10, 100), rnd.Next(60, 100), pictureBoxShip.Width, pictureBoxShip.Height); - toolStripStatusSpeed.Text = $"Скорость: {_ship.Ship.Speed}"; - toolStripStatusWeight.Text = $"Вес: {_ship.Ship.Weight}"; - toolStripStatusBodyColor.Text = $"Цвет: {_ship.Ship.BodyColor.Name}"; + rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); + SetData(); Draw(); } + + private void ButtonCreateModif_Click(object sender, EventArgs e) + { + + Random rnd = new(); + _ship = new DrawingContainerShip(rnd.Next(100, 300), rnd.Next(1000, 2000), + Color.FromArgb(255, rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), + Color.FromArgb(255, rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), + Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2))); + SetData(); + Draw(); + } + private void PictureBoxShip_Resize(object sender, EventArgs e) { _ship?.ChangeBorders(pictureBoxShip.Width, pictureBoxShip.Height); Draw(); } - private void FormShip_Load(object sender, EventArgs e) - { - - } } } diff --git a/ContainerShip/ContainerShip/FormShip.resx b/ContainerShip/ContainerShip/FormShip.resx index af27dc3..a6be4ca 100644 --- a/ContainerShip/ContainerShip/FormShip.resx +++ b/ContainerShip/ContainerShip/FormShip.resx @@ -61,7 +61,7 @@ iVBORw0KGgoAAAANSUhEUgAAAEMAAABHCAIAAADTOW0yAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO - vQAADr0BR/uQrQAAAVVJREFUaEPtz0ESgzAMQ9He/9J08zsDNECUWMVl/HYtsWS/lqeoS/KpS/q8Pvjt + vAAADrwBlbxySQAAAVVJREFUaEPtz0ESgzAMQ9He/9J08zsDNECUWMVl/HYtsWS/lqeoS/KpS/q8Pvjt ZOzgiA/+tXEVsP4W3zws6SzewguD+GhWPsa7aMG5LHuF16EiQ1mzDzNxwhJZUMFkkJg4VtMxHyEgi6VG kTJtNoh15pA1ZyqFRSKQOGE8ghXikDtqcJ7yaKQPGRmm1oMOnTxJoRNNIm2MKj/6FMIMJb9Ca7feAeJ/ i+4+Xa8JvgMbdLh+SuR92OPKxTvC7sY2p84eEZMDOx07fEFAJmx2oP2Z0XzYr6XxjaGs2PLL/gPPc2PX -- 2.25.1 From e4768be709994453bb51d8b464f9d71e141446ae Mon Sep 17 00:00:00 2001 From: Danil Markov Date: Sat, 8 Oct 2022 17:23:17 +0400 Subject: [PATCH 3/4] =?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 --- .../ContainerShip/DrawingObjectShip.cs | 36 +++++++++++++++++++ ContainerShip/ContainerShip/DrawingShip.cs | 4 +++ ContainerShip/ContainerShip/IDrawingObject.cs | 21 +++++++++++ 3 files changed, 61 insertions(+) create mode 100644 ContainerShip/ContainerShip/DrawingObjectShip.cs create mode 100644 ContainerShip/ContainerShip/IDrawingObject.cs diff --git a/ContainerShip/ContainerShip/DrawingObjectShip.cs b/ContainerShip/ContainerShip/DrawingObjectShip.cs new file mode 100644 index 0000000..eefa850 --- /dev/null +++ b/ContainerShip/ContainerShip/DrawingObjectShip.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ContainerShip +{ + internal class DrawingObjectShip : IDrawingObject + { + private DrawingShip _ship = null; + public DrawingObjectShip(DrawingShip ship) + { + _ship = ship; + } + public float Step => _ship?.Ship?.Step ?? 0; + + public (float Left, float Right, float Top, float Bottom) GetCurrentPosition() + { + return _ship?.GetCurrentPosition() ?? default; + } + public void MoveObject(Direction direction) + { + _ship?.MoveShip(direction); + } + public void SetObject(int x, int y, int width, int height) + { + _ship.SetPosition(x, y, width, height); + } + + void IDrawingObject.DrawingObject(Graphics g) + { + // TODO + } + } +} diff --git a/ContainerShip/ContainerShip/DrawingShip.cs b/ContainerShip/ContainerShip/DrawingShip.cs index c3e967f..7dc8639 100644 --- a/ContainerShip/ContainerShip/DrawingShip.cs +++ b/ContainerShip/ContainerShip/DrawingShip.cs @@ -128,5 +128,9 @@ namespace ContainerShip _startPosY = _pictureHeight.Value - _shipHeight; } } + public (float Left, float Right, float Top, float Bottom) GetCurrentPosition() + { + return (_startPosX, _startPosY, _startPosX + _shipWidth, _startPosY + _shipHeight); + } } } diff --git a/ContainerShip/ContainerShip/IDrawingObject.cs b/ContainerShip/ContainerShip/IDrawingObject.cs new file mode 100644 index 0000000..e283741 --- /dev/null +++ b/ContainerShip/ContainerShip/IDrawingObject.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ContainerShip +{ + internal interface IDrawingObject + { + public float Step { get; } + + void SetObject(int x, int y, int width, int height); + + void MoveObject(Direction direction); + + void DrawingObject(Graphics g); + + (float Left, float Right, float Top, float Bottom) GetCurrentPosition(); + } +} -- 2.25.1 From 6fa80234119e2e7c4a82e08540b173774bf5e78c Mon Sep 17 00:00:00 2001 From: Danil Markov Date: Sun, 9 Oct 2022 17:13:54 +0400 Subject: [PATCH 4/4] =?UTF-8?q?=D0=A1=D0=B4=D0=B5=D0=BB=D0=B0=D0=BD=D1=8B?= =?UTF-8?q?=20=D0=B2=D1=81=D0=B5=20TODO?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ContainerShip/ContainerShip/AbstractMap.cs | 221 ++++++++++++++++++ .../ContainerShip/ContainerShip.csproj | 15 ++ ContainerShip/ContainerShip/Direction.cs | 1 + .../ContainerShip/DrawingContainerShip.cs | 6 +- .../ContainerShip/DrawingObjectShip.cs | 2 +- .../ContainerShip/FormMap.Designer.cs | 209 +++++++++++++++++ ContainerShip/ContainerShip/FormMap.cs | 93 ++++++++ ContainerShip/ContainerShip/FormMap.resx | 63 +++++ .../ContainerShip/FormShip.Designer.cs | 10 +- ContainerShip/ContainerShip/FormShip.cs | 4 + ContainerShip/ContainerShip/FormShip.resx | 49 ---- ContainerShip/ContainerShip/IslandsMap.cs | 58 +++++ ContainerShip/ContainerShip/Program.cs | 2 +- .../Properties/Resources.Designer.cs | 103 ++++++++ .../ContainerShip/Properties/Resources.resx | 133 +++++++++++ ContainerShip/ContainerShip/RocksMap.cs | 52 +++++ ContainerShip/ContainerShip/SimpleMap.cs | 48 ++++ 17 files changed, 1008 insertions(+), 61 deletions(-) create mode 100644 ContainerShip/ContainerShip/AbstractMap.cs create mode 100644 ContainerShip/ContainerShip/FormMap.Designer.cs create mode 100644 ContainerShip/ContainerShip/FormMap.cs create mode 100644 ContainerShip/ContainerShip/FormMap.resx create mode 100644 ContainerShip/ContainerShip/IslandsMap.cs create mode 100644 ContainerShip/ContainerShip/Properties/Resources.Designer.cs create mode 100644 ContainerShip/ContainerShip/Properties/Resources.resx create mode 100644 ContainerShip/ContainerShip/RocksMap.cs create mode 100644 ContainerShip/ContainerShip/SimpleMap.cs diff --git a/ContainerShip/ContainerShip/AbstractMap.cs b/ContainerShip/ContainerShip/AbstractMap.cs new file mode 100644 index 0000000..ec8ce46 --- /dev/null +++ b/ContainerShip/ContainerShip/AbstractMap.cs @@ -0,0 +1,221 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ContainerShip +{ + internal abstract class AbstractMap + { + private IDrawingObject _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 _water = 0; + protected readonly int _barrier = 1; + public Bitmap CreateMap(int width, int height, IDrawingObject + drawningObject) + { + _width = width; + _height = height; + _drawningObject = drawningObject; + GenerateMap(); + while (!SetObjectOnMap()) + { + GenerateMap(); + } + return DrawMapWithObject(); + } + public Bitmap MoveObject(Direction direction) + { + bool moveAccept = true; + + (float Left, float Top, float Right, float Bottom) = _drawningObject.GetCurrentPosition(); + int xObjWidth = (int)Math.Ceiling((Right - Left) / _size_x); + int yObjHeight = (int)Math.Ceiling((Bottom - Top) / _size_y); + int vertStep = (int)Math.Ceiling(_drawningObject.Step / _size_y); + int horizStep = (int)Math.Ceiling(_drawningObject.Step / _size_x); + int xObjLeftBorder = (int)Math.Floor(Left / _size_x); + int xObjRightBorder = (int)Math.Ceiling(Right / _size_x); + int yObjTopBorder = (int)Math.Floor(Top / _size_y); + int yObjBottomBorder = (int)Math.Ceiling(Bottom / _size_y); + + switch (direction) + { + case Direction.Up: + for (int i = 0; i < vertStep; i++) + { + if (!moveAccept) + { + break; + } + for (int j = 0; j < xObjWidth; j++) + { + if (yObjTopBorder - i < 0 || xObjLeftBorder + j >= _map.GetLength(1)) + { + break; + } + if (_map[xObjLeftBorder + j, yObjTopBorder - i] == _barrier) + { + moveAccept = false; + break; + } + } + } + break; + + case Direction.Down: + for (int i = 0; i < vertStep; i++) + { + if (!moveAccept) + { + break; + } + for (int j = 0; j < xObjWidth; j++) + { + if (yObjBottomBorder + i >= _map.GetLength(0) || xObjLeftBorder + j >= _map.GetLength(1)) + { + break; + } + if (_map[xObjLeftBorder + j, yObjBottomBorder + i] == _barrier) + { + moveAccept = false; + break; + } + } + } + break; + + case Direction.Left: + for (int i = 0; i < yObjHeight; i++) + { + if (!moveAccept) + { + break; + } + for (int j = 0; j < horizStep; j++) + { + if (yObjTopBorder + i >= _map.GetLength(0) || xObjLeftBorder - j < 0) + { + break; + } + if (_map[xObjLeftBorder - j, yObjTopBorder + i] == _barrier) + { + moveAccept = false; + break; + } + } + } + break; + + case Direction.Right: + for (int i = 0; i < yObjHeight; i++) + { + if (!moveAccept) + { + break; + } + for (int j = 0; j < horizStep; j++) + { + if (yObjTopBorder + i >= _map.GetLength(0) || xObjRightBorder + j >= _map.GetLength(1)) + { + break; + } + if (_map[xObjRightBorder + j, yObjTopBorder + i] == _barrier) + { + moveAccept = false; + break; + } + } + } + break; + } + if (moveAccept) + { + _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); + + (float Left, float Top, float Right, float Bottom) = _drawningObject.GetCurrentPosition(); + int xObjWidth = (int)Math.Ceiling((Right - Left) / _size_x); + int yObjHeight = (int)Math.Ceiling((Bottom - Top) / _size_y); + int xObjLeftBorder = (int)Math.Floor(Left / _size_x); + int yObjTopBorder = (int)Math.Floor(Top / _size_y); + + while (y < _height - (Bottom - Top)) + { + while (x < _width - (Right - Left)) + { + if (CheckSpawnArea(xObjWidth, yObjHeight, xObjLeftBorder, yObjTopBorder)) + { + _drawningObject.SetObject(x, y, _width, _height); + return true; + } + x += (int)_size_x; + xObjLeftBorder = (int)(x / _size_x); + } + x = 0; + y += (int)_size_y; + yObjTopBorder = (int)(y / _size_y); + } + + return false; + } + private bool CheckSpawnArea(int xObjWidth, int yObjHeight, int xObjLeftBorder, int yObjTopBorder) + { + for (int i = 0; i <= yObjHeight; i++) + { + for (int j = 0; j <= xObjWidth; j++) + { + if (yObjTopBorder + i >= _map.GetLength(0) || xObjLeftBorder + j >= _map.GetLength(1) || _map[xObjLeftBorder + j, yObjTopBorder + i] == _barrier) + { + return false; + } + } + } + + 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] == _water) + { + DrawWaterPart(gr, i, j); + } + else if (_map[i, j] == _barrier) + { + DrawBarrierPart(gr, i, j); + } + } + } + _drawningObject.DrawingObject(gr); + return bmp; + } + protected abstract void GenerateMap(); + protected abstract void DrawWaterPart(Graphics g, int i, int j); + protected abstract void DrawBarrierPart(Graphics g, int i, int j); + } +} diff --git a/ContainerShip/ContainerShip/ContainerShip.csproj b/ContainerShip/ContainerShip/ContainerShip.csproj index b57c89e..13ee123 100644 --- a/ContainerShip/ContainerShip/ContainerShip.csproj +++ b/ContainerShip/ContainerShip/ContainerShip.csproj @@ -8,4 +8,19 @@ enable + + + True + True + Resources.resx + + + + + + ResXFileCodeGenerator + Resources.Designer.cs + + + \ No newline at end of file diff --git a/ContainerShip/ContainerShip/Direction.cs b/ContainerShip/ContainerShip/Direction.cs index 9db3867..3f6e02b 100644 --- a/ContainerShip/ContainerShip/Direction.cs +++ b/ContainerShip/ContainerShip/Direction.cs @@ -8,6 +8,7 @@ namespace ContainerShip { internal enum Direction { + None = 0, Up = 1, Down = 2, Left = 3, diff --git a/ContainerShip/ContainerShip/DrawingContainerShip.cs b/ContainerShip/ContainerShip/DrawingContainerShip.cs index 6901245..e64b91f 100644 --- a/ContainerShip/ContainerShip/DrawingContainerShip.cs +++ b/ContainerShip/ContainerShip/DrawingContainerShip.cs @@ -65,11 +65,7 @@ namespace ContainerShip g.DrawLine(pen, _startPosX + 90, _startPosY + 40, _startPosX + 85, _startPosY + 43); g.DrawLine(pen, _startPosX + 90, _startPosY + 40, _startPosX + 90, _startPosY + 45); g.DrawLine(pen, _startPosX + 90, _startPosY + 40, _startPosX + 95, _startPosY + 43); - } - - - - + } } } } \ No newline at end of file diff --git a/ContainerShip/ContainerShip/DrawingObjectShip.cs b/ContainerShip/ContainerShip/DrawingObjectShip.cs index eefa850..1a69124 100644 --- a/ContainerShip/ContainerShip/DrawingObjectShip.cs +++ b/ContainerShip/ContainerShip/DrawingObjectShip.cs @@ -30,7 +30,7 @@ namespace ContainerShip void IDrawingObject.DrawingObject(Graphics g) { - // TODO + _ship?.DrawTransport(g); } } } diff --git a/ContainerShip/ContainerShip/FormMap.Designer.cs b/ContainerShip/ContainerShip/FormMap.Designer.cs new file mode 100644 index 0000000..4d3b4b3 --- /dev/null +++ b/ContainerShip/ContainerShip/FormMap.Designer.cs @@ -0,0 +1,209 @@ +namespace ContainerShip +{ + 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.pictureBoxShip = new System.Windows.Forms.PictureBox(); + this.buttonCreate = new System.Windows.Forms.Button(); + this.buttonUp = new System.Windows.Forms.Button(); + this.buttonRight = new System.Windows.Forms.Button(); + this.buttonLeft = new System.Windows.Forms.Button(); + this.buttonDown = new System.Windows.Forms.Button(); + this.statusStrip = new System.Windows.Forms.StatusStrip(); + this.toolStripStatusSpeed = new System.Windows.Forms.ToolStripStatusLabel(); + this.toolStripStatusWeight = new System.Windows.Forms.ToolStripStatusLabel(); + this.toolStripStatusBodyColor = new System.Windows.Forms.ToolStripStatusLabel(); + this.buttonCreateModif = new System.Windows.Forms.Button(); + this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxShip)).BeginInit(); + this.statusStrip.SuspendLayout(); + this.SuspendLayout(); + // + // pictureBoxShip + // + this.pictureBoxShip.Dock = System.Windows.Forms.DockStyle.Fill; + this.pictureBoxShip.Location = new System.Drawing.Point(0, 0); + this.pictureBoxShip.Margin = new System.Windows.Forms.Padding(0); + this.pictureBoxShip.Name = "pictureBoxShip"; + this.pictureBoxShip.Size = new System.Drawing.Size(800, 428); + this.pictureBoxShip.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; + this.pictureBoxShip.TabIndex = 3; + this.pictureBoxShip.TabStop = false; + // + // 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 = 4; + this.buttonCreate.Text = "Создать"; + this.buttonCreate.UseVisualStyleBackColor = true; + this.buttonCreate.Click += new System.EventHandler(this.ButtonCreate_Click); + // + // buttonUp + // + this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonUp.BackgroundImage = global::ContainerShip.Properties.Resources.ArrowUp; + this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonUp.Location = new System.Drawing.Point(722, 359); + this.buttonUp.Name = "buttonUp"; + this.buttonUp.Size = new System.Drawing.Size(30, 30); + this.buttonUp.TabIndex = 5; + this.buttonUp.UseVisualStyleBackColor = true; + this.buttonUp.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::ContainerShip.Properties.Resources.ArrowRight; + this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonRight.Location = new System.Drawing.Point(758, 395); + this.buttonRight.Name = "buttonRight"; + this.buttonRight.Size = new System.Drawing.Size(30, 30); + this.buttonRight.TabIndex = 6; + this.buttonRight.UseVisualStyleBackColor = true; + this.buttonRight.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::ContainerShip.Properties.Resources.ArrowLeft; + this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonLeft.Location = new System.Drawing.Point(686, 395); + this.buttonLeft.Name = "buttonLeft"; + this.buttonLeft.Size = new System.Drawing.Size(30, 30); + this.buttonLeft.TabIndex = 7; + 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::ContainerShip.Properties.Resources.ArrowDown; + this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonDown.Location = new System.Drawing.Point(722, 395); + this.buttonDown.Name = "buttonDown"; + this.buttonDown.Size = new System.Drawing.Size(30, 30); + this.buttonDown.TabIndex = 8; + this.buttonDown.UseVisualStyleBackColor = true; + this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click); + // + // statusStrip + // + this.statusStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.toolStripStatusSpeed, + this.toolStripStatusWeight, + this.toolStripStatusBodyColor}); + 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 = 9; + // + // toolStripStatusSpeed + // + this.toolStripStatusSpeed.Name = "toolStripStatusSpeed"; + this.toolStripStatusSpeed.Size = new System.Drawing.Size(65, 17); + this.toolStripStatusSpeed.Text = "Скорость: "; + // + // toolStripStatusWeight + // + this.toolStripStatusWeight.Name = "toolStripStatusWeight"; + this.toolStripStatusWeight.Size = new System.Drawing.Size(32, 17); + this.toolStripStatusWeight.Text = "Вес: "; + // + // toolStripStatusBodyColor + // + this.toolStripStatusBodyColor.Name = "toolStripStatusBodyColor"; + this.toolStripStatusBodyColor.Size = new System.Drawing.Size(39, 17); + this.toolStripStatusBodyColor.Text = "Цвет: "; + // + // 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(94, 402); + this.buttonCreateModif.Name = "buttonCreateModif"; + this.buttonCreateModif.Size = new System.Drawing.Size(110, 23); + this.buttonCreateModif.TabIndex = 10; + 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 = 11; + 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(800, 450); + this.Controls.Add(this.comboBoxSelectorMap); + this.Controls.Add(this.buttonCreateModif); + this.Controls.Add(this.buttonDown); + this.Controls.Add(this.buttonLeft); + this.Controls.Add(this.buttonRight); + this.Controls.Add(this.buttonUp); + this.Controls.Add(this.buttonCreate); + this.Controls.Add(this.pictureBoxShip); + this.Controls.Add(this.statusStrip); + this.Name = "FormMap"; + this.Text = "FormMap"; + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxShip)).EndInit(); + this.statusStrip.ResumeLayout(false); + this.statusStrip.PerformLayout(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + private PictureBox pictureBoxShip; + private Button buttonCreate; + private Button buttonUp; + private Button buttonRight; + private Button buttonLeft; + private Button buttonDown; + private StatusStrip statusStrip; + private ToolStripStatusLabel toolStripStatusSpeed; + private ToolStripStatusLabel toolStripStatusWeight; + private ToolStripStatusLabel toolStripStatusBodyColor; + private Button buttonCreateModif; + private ComboBox comboBoxSelectorMap; + } +} \ No newline at end of file diff --git a/ContainerShip/ContainerShip/FormMap.cs b/ContainerShip/ContainerShip/FormMap.cs new file mode 100644 index 0000000..b3eb5b4 --- /dev/null +++ b/ContainerShip/ContainerShip/FormMap.cs @@ -0,0 +1,93 @@ +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 ContainerShip +{ + public partial class FormMap : Form + { + private AbstractMap _abstractMap; + + public FormMap() + { + InitializeComponent(); + + + + + _abstractMap = new SimpleMap(); + } + + + private void SetData(DrawingShip ship) + { + Random rnd = new(); + toolStripStatusSpeed.Text = $"Скорость: {ship.Ship.Speed}"; + toolStripStatusWeight.Text = $"Вес: {ship.Ship.Weight}"; + toolStripStatusBodyColor.Text = $"Цвет: {ship.Ship.BodyColor.Name}"; + pictureBoxShip.Image = _abstractMap.CreateMap(pictureBoxShip.Width, pictureBoxShip.Height, + new DrawingObjectShip(ship)); + } + + private void ButtonCreate_Click(object sender, EventArgs e) + { + Random rnd = new(); + var ship = new DrawingShip(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), + rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); + SetData(ship); + } + 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; + } + pictureBoxShip.Image = _abstractMap?.MoveObject(dir); + } + private void ButtonCreateModif_Click(object sender, EventArgs e) + { + + Random rnd = new(); + var ship = new DrawingContainerShip(rnd.Next(100, 300), rnd.Next(1000, 2000), + Color.FromArgb(255, rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), + Color.FromArgb(255, rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), + Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2))); + SetData(ship); + } + + private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e) + { + switch (comboBoxSelectorMap.Text) + { + case "Простая карта": + _abstractMap = new SimpleMap(); + break; + case "Острова": + _abstractMap = new IslandsMap(); + break; + case "Скалы": + _abstractMap = new RocksMap(); + break; + } + } + } +} diff --git a/ContainerShip/ContainerShip/FormMap.resx b/ContainerShip/ContainerShip/FormMap.resx new file mode 100644 index 0000000..2c0949d --- /dev/null +++ b/ContainerShip/ContainerShip/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/ContainerShip/ContainerShip/FormShip.Designer.cs b/ContainerShip/ContainerShip/FormShip.Designer.cs index 408ac3a..985a4c6 100644 --- a/ContainerShip/ContainerShip/FormShip.Designer.cs +++ b/ContainerShip/ContainerShip/FormShip.Designer.cs @@ -28,7 +28,6 @@ /// private void InitializeComponent() { - System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormShip)); this.pictureBoxShip = new System.Windows.Forms.PictureBox(); this.buttonCreate = new System.Windows.Forms.Button(); this.buttonUp = new System.Windows.Forms.Button(); @@ -68,7 +67,7 @@ // buttonUp // this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonUp.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("buttonUp.BackgroundImage"))); + this.buttonUp.BackgroundImage = global::ContainerShip.Properties.Resources.ArrowUp; this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.buttonUp.Location = new System.Drawing.Point(722, 359); this.buttonUp.Name = "buttonUp"; @@ -80,7 +79,7 @@ // buttonRight // this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonRight.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("buttonRight.BackgroundImage"))); + this.buttonRight.BackgroundImage = global::ContainerShip.Properties.Resources.ArrowRight; this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.buttonRight.Location = new System.Drawing.Point(758, 395); this.buttonRight.Name = "buttonRight"; @@ -92,7 +91,7 @@ // buttonLeft // this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonLeft.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("buttonLeft.BackgroundImage"))); + this.buttonLeft.BackgroundImage = global::ContainerShip.Properties.Resources.ArrowLeft; this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.buttonLeft.Location = new System.Drawing.Point(686, 395); this.buttonLeft.Name = "buttonLeft"; @@ -104,7 +103,7 @@ // buttonDown // this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonDown.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("buttonDown.BackgroundImage"))); + this.buttonDown.BackgroundImage = global::ContainerShip.Properties.Resources.ArrowDown; this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.buttonDown.Location = new System.Drawing.Point(722, 395); this.buttonDown.Name = "buttonDown"; @@ -167,6 +166,7 @@ this.Controls.Add(this.statusStrip); this.Name = "FormShip"; this.Text = "FormShip"; + this.Load += new System.EventHandler(this.FormShip_Load); this.Resize += new System.EventHandler(this.PictureBoxShip_Resize); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxShip)).EndInit(); this.statusStrip.ResumeLayout(false); diff --git a/ContainerShip/ContainerShip/FormShip.cs b/ContainerShip/ContainerShip/FormShip.cs index bdf915b..85bc29a 100644 --- a/ContainerShip/ContainerShip/FormShip.cs +++ b/ContainerShip/ContainerShip/FormShip.cs @@ -84,5 +84,9 @@ namespace ContainerShip Draw(); } + private void FormShip_Load(object sender, EventArgs e) + { + + } } } diff --git a/ContainerShip/ContainerShip/FormShip.resx b/ContainerShip/ContainerShip/FormShip.resx index a6be4ca..2c0949d 100644 --- a/ContainerShip/ContainerShip/FormShip.resx +++ b/ContainerShip/ContainerShip/FormShip.resx @@ -57,55 +57,6 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - - iVBORw0KGgoAAAANSUhEUgAAAEMAAABHCAIAAADTOW0yAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO - vAAADrwBlbxySQAAAVVJREFUaEPtz0ESgzAMQ9He/9J08zsDNECUWMVl/HYtsWS/lqeoS/KpS/q8Pvjt - ZOzgiA/+tXEVsP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lMUB9+GiVpsQA9fH/VZsWA1SA72aYGgNWCQHTY8AKIWCJGKtwDOIYxDF+9v0DSS3i - +O80JVAAAAAASUVORK5CYII= - - 17, 17 diff --git a/ContainerShip/ContainerShip/IslandsMap.cs b/ContainerShip/ContainerShip/IslandsMap.cs new file mode 100644 index 0000000..838c7be --- /dev/null +++ b/ContainerShip/ContainerShip/IslandsMap.cs @@ -0,0 +1,58 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ContainerShip +{ + internal class IslandsMap : AbstractMap + { + private readonly Brush islandColor = new SolidBrush(Color.Yellow); + + private readonly Brush waterColor = new SolidBrush(Color.Aqua); + protected override void DrawBarrierPart(Graphics g, int i, int j) + { + g.FillRectangle(islandColor, i * _size_x, j * _size_y, _size_x, _size_y); + } + protected override void DrawWaterPart(Graphics g, int i, int j) + { + g.FillRectangle(waterColor, 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] = _water; + } + } + while (counter < 10) + { + int x = _random.Next(0, 100); + int y = _random.Next(0, 100); + if (_map[x, y] == _water && x < 97 && y < 97) + { + _map[x + 1, y] = _barrier; + _map[x + 2, y] = _barrier; + _map[x, y + 1] = _barrier; + _map[x + 1, y + 1] = _barrier; + _map[x + 2, y + 1] = _barrier; + _map[x + 3, y + 1] = _barrier; + _map[x, y + 2] = _barrier; + _map[x + 1, y + 2] = _barrier; + _map[x + 2, y + 2] = _barrier; + _map[x + 3, y + 2] = _barrier; + _map[x + 1, y + 3] = _barrier; + _map[x + 2, y + 3] = _barrier; + counter++; + } + } + } + } +} diff --git a/ContainerShip/ContainerShip/Program.cs b/ContainerShip/ContainerShip/Program.cs index 3274551..8f4b98f 100644 --- a/ContainerShip/ContainerShip/Program.cs +++ b/ContainerShip/ContainerShip/Program.cs @@ -11,7 +11,7 @@ namespace ContainerShip // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormShip()); + Application.Run(new FormMap()); } } } \ No newline at end of file diff --git a/ContainerShip/ContainerShip/Properties/Resources.Designer.cs b/ContainerShip/ContainerShip/Properties/Resources.Designer.cs new file mode 100644 index 0000000..ec0680d --- /dev/null +++ b/ContainerShip/ContainerShip/Properties/Resources.Designer.cs @@ -0,0 +1,103 @@ +//------------------------------------------------------------------------------ +// +// Этот код создан программой. +// Исполняемая версия:4.0.30319.42000 +// +// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае +// повторной генерации кода. +// +//------------------------------------------------------------------------------ + +namespace ContainerShip.Properties { + using System; + + + /// + /// Класс ресурса со строгой типизацией для поиска локализованных строк и т.д. + /// + // Этот класс создан автоматически классом StronglyTypedResourceBuilder + // с помощью такого средства, как ResGen или Visual Studio. + // Чтобы добавить или удалить член, измените файл .ResX и снова запустите ResGen + // с параметром /str или перестройте свой проект VS. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Возвращает кэшированный экземпляр ResourceManager, использованный этим классом. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ContainerShip.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Перезаписывает свойство CurrentUICulture текущего потока для всех + /// обращений к ресурсу с помощью этого класса ресурса со строгой типизацией. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap ArrowDown { + get { + object obj = ResourceManager.GetObject("ArrowDown", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap ArrowLeft { + get { + object obj = ResourceManager.GetObject("ArrowLeft", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap ArrowRight { + get { + object obj = ResourceManager.GetObject("ArrowRight", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap ArrowUp { + get { + object obj = ResourceManager.GetObject("ArrowUp", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + } +} diff --git a/ContainerShip/ContainerShip/Properties/Resources.resx b/ContainerShip/ContainerShip/Properties/Resources.resx new file mode 100644 index 0000000..b0dd770 --- /dev/null +++ b/ContainerShip/ContainerShip/Properties/Resources.resx @@ -0,0 +1,133 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + + ..\img\ArrowDown.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\img\ArrowLeft.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\img\ArrowRight.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\img\ArrowUp.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + \ No newline at end of file diff --git a/ContainerShip/ContainerShip/RocksMap.cs b/ContainerShip/ContainerShip/RocksMap.cs new file mode 100644 index 0000000..ebc7abd --- /dev/null +++ b/ContainerShip/ContainerShip/RocksMap.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ContainerShip +{ + internal class RocksMap : AbstractMap + { + private readonly Brush rockColor = new SolidBrush(Color.Gray); + + private readonly Brush waterColor = new SolidBrush(Color.Aqua); + protected override void DrawBarrierPart(Graphics g, int i, int j) + { + g.FillRectangle(rockColor, i * _size_x, j * _size_y, i * (_size_x + + 1), j * (_size_y + 1)); + } + protected override void DrawWaterPart(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] = _water; + } + } + while (counter < 10) + { + int x = _random.Next(0, 100); + int y = _random.Next(0, 100); + if (_map[x, y] == _water && x < 98 && y < 99) + { + _map[x, y] = _barrier; + _map[x + 1, y] = _barrier; + _map[x + 2, y] = _barrier; + _map[x + 1, y + 1] = _barrier; + + counter++; + } + } + } + } +} diff --git a/ContainerShip/ContainerShip/SimpleMap.cs b/ContainerShip/ContainerShip/SimpleMap.cs new file mode 100644 index 0000000..736b7c3 --- /dev/null +++ b/ContainerShip/ContainerShip/SimpleMap.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ContainerShip +{ + internal class SimpleMap : AbstractMap + { + private readonly Brush bombColor = new SolidBrush(Color.Black); + + private readonly Brush waterColor = new SolidBrush(Color.Aqua); + protected override void DrawBarrierPart(Graphics g, int i, int j) + { + g.FillRectangle(bombColor, i * _size_x, j * _size_y, i * (_size_x + + 1), j * (_size_y + 1)); + } + protected override void DrawWaterPart(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 = _width / _map.GetLength(0); + _size_y = _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] = _water; + } + } + while (counter < 20) + { + int x = _random.Next(0, 100); + int y = _random.Next(0, 100); + if (_map[x, y] == _water) + { + _map[x, y] = _barrier; + counter++; + } + } + } + } +} -- 2.25.1