From c8d2e3c46d31a26513c3b3bbcab893575a5e2863 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D0=B5=D0=BC=20=D0=A5=D0=B0=D1=80=D0=BB?= =?UTF-8?q?=D0=B0=D0=BC=D0=BE=D0=B2?= Date: Thu, 10 Nov 2022 19:43:59 +0400 Subject: [PATCH] =?UTF-8?q?=D0=90=D0=B1=D1=81=D1=82=D1=80=D0=B0=D0=BA?= =?UTF-8?q?=D1=82=D0=BD=D1=8B=D0=B9=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Stormtrooper/Stormtrooper/AbstractMap.cs | 111 +++++++++++++++--- Stormtrooper/Stormtrooper/Drawning.cs | 5 +- Stormtrooper/Stormtrooper/DrawningMilitary.cs | 1 + .../Stormtrooper/DrawningObjectStorm.cs | 2 + Stormtrooper/Stormtrooper/FormMap.Designer.cs | 27 +++-- Stormtrooper/Stormtrooper/FormMap.cs | 8 +- Stormtrooper/Stormtrooper/FormMap.resx | 2 +- Stormtrooper/Stormtrooper/SecondMap.cs | 52 ++++++++ Stormtrooper/Stormtrooper/SimpleMap.cs | 6 +- Stormtrooper/Stormtrooper/ThirdMap.cs | 69 +++++++++++ 10 files changed, 244 insertions(+), 39 deletions(-) create mode 100644 Stormtrooper/Stormtrooper/SecondMap.cs create mode 100644 Stormtrooper/Stormtrooper/ThirdMap.cs diff --git a/Stormtrooper/Stormtrooper/AbstractMap.cs b/Stormtrooper/Stormtrooper/AbstractMap.cs index 22d3c4e..f00311e 100644 --- a/Stormtrooper/Stormtrooper/AbstractMap.cs +++ b/Stormtrooper/Stormtrooper/AbstractMap.cs @@ -31,9 +31,76 @@ namespace Stormtrooper return DrawMapWithObject(); } public Bitmap MoveObject(Direction direction) - { - //TODO - if (true) + { + int LefTopX = Convert.ToInt32(_drawningObject.GetCurrentPosition().Left / _size_x); + int LefTopY = Convert.ToInt32(_drawningObject.GetCurrentPosition().Top / _size_y); + int objwidth = Convert.ToInt32(_drawningObject.GetCurrentPosition().Right / _size_x); + int objheigh = Convert.ToInt32(_drawningObject.GetCurrentPosition().Bottom / _size_y); + + bool CanStep = true; + switch (direction) + { + case Direction.Left: + for (int i = LefTopX; i >= Math.Abs(LefTopX - Convert.ToInt32(_drawningObject.Step / _size_x)); i--) + { + for (int j = LefTopY; j <= objheigh && j<_map.GetLength(1); j++) + { + + if (_map[i, j] == _barrier) + { + CanStep = false; + break; + } + } + } + break; + + case Direction.Right: + for (int i = objwidth; i <= objwidth + Convert.ToInt32(_drawningObject.Step / _size_x) && i < _map.GetLength(0); i++) + { + for (int j = LefTopY; j <= objheigh && j < _map.GetLength(1); j++) + { + if (_map[i, j] == _barrier) + { + CanStep = false; + break; + } + } + } + + break; + + case Direction.Down: + for (int i = LefTopX; i <= objwidth && i < _map.GetLength(0); i++) + { + for (int j = objheigh; j <= objheigh + Convert.ToInt32(_drawningObject.Step / _size_y) && j < _map.GetLength(1); j++) + { + + if (_map[i, j] == _barrier) + { + CanStep = false; + break; + } + } + } + + break; + case Direction.Up: + for (int i = LefTopX; i <= objwidth && i<_map.GetLength(0); i++) + { + for (int j = LefTopY; j >= Math.Abs(LefTopY - Convert.ToInt32(_drawningObject.Step / _size_y)) ; j--) + { + if (_map[i, j] == _barrier) + { + CanStep = false; + break; + } + } + } + break; + } + + if (CanStep) { _drawningObject.MoveObject(direction); } @@ -45,10 +112,24 @@ namespace Stormtrooper { return false; } - int x = _random.Next(0, 10); - int y = _random.Next(0, 10); + int x = _random.Next(0, 150); + int y = _random.Next(100, 300); + + for (int i = 0; i < _map.GetLength(0); ++i) + { + for (int j = 0; j < _map.GetLength(1); ++j) + { + if (i * _size_x >= x && j * _size_y <= y && + i * _size_x <= x + _drawningObject.GetCurrentPosition().Right && + j * _size_y >= j - _drawningObject.GetCurrentPosition().Bottom && _map[i, j] == _barrier) + { + return false; + } + } + } + _drawningObject.SetObject(x, y, _width, _height); - // TODO првоерка, что объект не "накладывается" на закрытые участки + return true; } private Bitmap DrawMapWithObject() @@ -60,19 +141,13 @@ namespace Stormtrooper } 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); - } - } - } + DrawRoadPart(gr, i, j); + + for (int i = 0; i < _map.GetLength(0); ++i) + for (int j = 0; j < _map.GetLength(1); ++j) + if (_map[i, j] == 1) DrawBarrierPart(gr, i, j); + _drawningObject.DrawningObject(gr); return bmp; } diff --git a/Stormtrooper/Stormtrooper/Drawning.cs b/Stormtrooper/Stormtrooper/Drawning.cs index a5673b9..000a1d3 100644 --- a/Stormtrooper/Stormtrooper/Drawning.cs +++ b/Stormtrooper/Stormtrooper/Drawning.cs @@ -175,7 +175,7 @@ namespace Stormtrooper g.FillPolygon(brBl, N); //фюзеляж - Brush brGr = new SolidBrush(Color.Gray); + Brush brGr = new SolidBrush(Color.White); g.FillRectangle(brGr, _startPosX + 20, _startPosY - 60, 100, 20); //крыло и стаб @@ -184,6 +184,7 @@ namespace Stormtrooper g.FillPolygon(br, S); } + /// /// Смена границ формы отрисовки /// @@ -214,7 +215,7 @@ namespace Stormtrooper /// public (float Left, float Right, float Top, float Bottom) GetCurrentPosition() { - return (_startPosX, _startPosY, _startPosX + _StormWidth, _startPosY + _StormHeight); + return (_startPosX, _startPosX + _StormWidth, _startPosY - _StormHeight, _startPosY); } } } diff --git a/Stormtrooper/Stormtrooper/DrawningMilitary.cs b/Stormtrooper/Stormtrooper/DrawningMilitary.cs index da40c2d..0781a3f 100644 --- a/Stormtrooper/Stormtrooper/DrawningMilitary.cs +++ b/Stormtrooper/Stormtrooper/DrawningMilitary.cs @@ -23,6 +23,7 @@ namespace Stormtrooper { Storm = new EntityMilitaryStormtrooper(speed, weight, bodyColor, dopColor, bodyKit, rocket, sportLine); } + public override void DrawTransport(Graphics g) { if (Storm is not EntityMilitaryStormtrooper militaryTrop) diff --git a/Stormtrooper/Stormtrooper/DrawningObjectStorm.cs b/Stormtrooper/Stormtrooper/DrawningObjectStorm.cs index 859af1e..6dac87e 100644 --- a/Stormtrooper/Stormtrooper/DrawningObjectStorm.cs +++ b/Stormtrooper/Stormtrooper/DrawningObjectStorm.cs @@ -28,6 +28,8 @@ namespace Stormtrooper } void IDrawningObject.DrawningObject(Graphics g) { + if (_storm is DrawningMilitary) + ((DrawningMilitary)_storm).DrawTransport(g); _storm.DrawTransport(g); } diff --git a/Stormtrooper/Stormtrooper/FormMap.Designer.cs b/Stormtrooper/Stormtrooper/FormMap.Designer.cs index 316d332..3ca409c 100644 --- a/Stormtrooper/Stormtrooper/FormMap.Designer.cs +++ b/Stormtrooper/Stormtrooper/FormMap.Designer.cs @@ -46,11 +46,10 @@ // // pictureBoxStormtrooper // - this.pictureBoxStormtrooper.Dock = System.Windows.Forms.DockStyle.Fill; this.pictureBoxStormtrooper.Location = new System.Drawing.Point(0, 0); this.pictureBoxStormtrooper.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.pictureBoxStormtrooper.Name = "pictureBoxStormtrooper"; - this.pictureBoxStormtrooper.Size = new System.Drawing.Size(914, 446); + this.pictureBoxStormtrooper.Size = new System.Drawing.Size(1000, 500); this.pictureBoxStormtrooper.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; this.pictureBoxStormtrooper.TabIndex = 0; this.pictureBoxStormtrooper.TabStop = false; @@ -62,10 +61,10 @@ this.toolStripStatusLabelSpeed, this.toolStripStatusLabelWeight, this.toolStripStatusLabelBodyColor}); - this.statusStrip.Location = new System.Drawing.Point(0, 446); + this.statusStrip.Location = new System.Drawing.Point(0, 501); this.statusStrip.Name = "statusStrip"; this.statusStrip.Padding = new System.Windows.Forms.Padding(1, 0, 16, 0); - this.statusStrip.Size = new System.Drawing.Size(914, 26); + this.statusStrip.Size = new System.Drawing.Size(1000, 26); this.statusStrip.TabIndex = 1; // // toolStripStatusLabelSpeed @@ -89,7 +88,7 @@ // 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(14, 392); + this.buttonCreate.Location = new System.Drawing.Point(14, 447); this.buttonCreate.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.buttonCreate.Name = "buttonCreate"; this.buttonCreate.Size = new System.Drawing.Size(86, 31); @@ -103,7 +102,7 @@ this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonUp.BackgroundImage = global::Stormtrooper.Properties.Resources.arrowUp; this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonUp.Location = new System.Drawing.Point(815, 334); + this.buttonUp.Location = new System.Drawing.Point(901, 389); this.buttonUp.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.buttonUp.Name = "buttonUp"; this.buttonUp.Size = new System.Drawing.Size(34, 40); @@ -117,7 +116,7 @@ this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonLeft.BackgroundImage = global::Stormtrooper.Properties.Resources.arrowLeft; this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonLeft.Location = new System.Drawing.Point(770, 382); + this.buttonLeft.Location = new System.Drawing.Point(856, 437); this.buttonLeft.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.buttonLeft.Name = "buttonLeft"; this.buttonLeft.Size = new System.Drawing.Size(34, 40); @@ -131,7 +130,7 @@ this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonRight.BackgroundImage = global::Stormtrooper.Properties.Resources.arrowRight; this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonRight.Location = new System.Drawing.Point(858, 382); + this.buttonRight.Location = new System.Drawing.Point(944, 437); this.buttonRight.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.buttonRight.Name = "buttonRight"; this.buttonRight.Size = new System.Drawing.Size(34, 40); @@ -145,7 +144,7 @@ this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonDown.BackgroundImage = global::Stormtrooper.Properties.Resources.arrowDown; this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonDown.Location = new System.Drawing.Point(815, 382); + this.buttonDown.Location = new System.Drawing.Point(901, 437); this.buttonDown.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.buttonDown.Name = "buttonDown"; this.buttonDown.Size = new System.Drawing.Size(34, 40); @@ -157,7 +156,7 @@ // 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(116, 392); + this.buttonCreateModif.Location = new System.Drawing.Point(116, 447); this.buttonCreateModif.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.buttonCreateModif.Name = "buttonCreateModif"; this.buttonCreateModif.Size = new System.Drawing.Size(126, 31); @@ -171,8 +170,10 @@ 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(14, 16); + "Простая карта", + "Ясное небо", + "Пасмурное небо"}); + this.comboBoxSelectorMap.Location = new System.Drawing.Point(14, 13); this.comboBoxSelectorMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; this.comboBoxSelectorMap.Size = new System.Drawing.Size(138, 28); @@ -183,7 +184,7 @@ // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(914, 472); + this.ClientSize = new System.Drawing.Size(1000, 527); this.Controls.Add(this.comboBoxSelectorMap); this.Controls.Add(this.buttonCreateModif); this.Controls.Add(this.buttonDown); diff --git a/Stormtrooper/Stormtrooper/FormMap.cs b/Stormtrooper/Stormtrooper/FormMap.cs index 7efa783..c87fe12 100644 --- a/Stormtrooper/Stormtrooper/FormMap.cs +++ b/Stormtrooper/Stormtrooper/FormMap.cs @@ -79,7 +79,7 @@ namespace Stormtrooper var storm = new DrawningMilitary(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), - Convert.ToBoolean(rnd.Next(0, 1)), Convert.ToBoolean(rnd.Next(0, 1)), Convert.ToBoolean(rnd.Next(0, 1))); + Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2))); SetData(storm); } @@ -90,6 +90,12 @@ namespace Stormtrooper case "Простая карта": _abstractMap = new SimpleMap(); break; + case "Ясное небо": + _abstractMap = new SecondMap(); + break; + case "Пасмурное небо": + _abstractMap = new ThirdMap(); + break; } } diff --git a/Stormtrooper/Stormtrooper/FormMap.resx b/Stormtrooper/Stormtrooper/FormMap.resx index bc70819..30aae67 100644 --- a/Stormtrooper/Stormtrooper/FormMap.resx +++ b/Stormtrooper/Stormtrooper/FormMap.resx @@ -61,6 +61,6 @@ 17, 17 - 51 + 25 \ No newline at end of file diff --git a/Stormtrooper/Stormtrooper/SecondMap.cs b/Stormtrooper/Stormtrooper/SecondMap.cs new file mode 100644 index 0000000..49aae09 --- /dev/null +++ b/Stormtrooper/Stormtrooper/SecondMap.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Stormtrooper +{ + internal class SecondMap:AbstractMap + { + /// + /// Цвет участка закрытого + /// + private readonly Brush barrierColor = new SolidBrush(Color.White); + /// + /// Цвет участка открытого + /// + private readonly Brush roadColor = new SolidBrush(Color.LightBlue); + protected override void DrawBarrierPart(Graphics g, int i, int j) + { + g.FillEllipse(barrierColor, i * _size_x, j * _size_y, _size_x+3, _size_y+3); + } + protected override void DrawRoadPart(Graphics g, int i, int j) + { + g.FillRectangle(roadColor, i * _size_x, j * _size_y, _size_x, _size_y); + } + protected override void GenerateMap() + { + _map = new int[100, 100]; + _size_x = (float)_width / _map.GetLength(0); + _size_y = (float)_height / _map.GetLength(1); + int counter = 0; + for (int i = 0; i < _map.GetLength(0); ++i) + { + for (int j = 0; j < _map.GetLength(1); ++j) + { + _map[i, j] = _freeRoad; + } + } + while (counter < 30) + { + 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/Stormtrooper/Stormtrooper/SimpleMap.cs b/Stormtrooper/Stormtrooper/SimpleMap.cs index d2bace6..07cb62a 100644 --- a/Stormtrooper/Stormtrooper/SimpleMap.cs +++ b/Stormtrooper/Stormtrooper/SimpleMap.cs @@ -18,13 +18,11 @@ namespace Stormtrooper 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)); + 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, i * (_size_x + - 1), j * (_size_y + 1)); + g.FillRectangle(roadColor, i * _size_x, j * _size_y, _size_x, _size_y); } protected override void GenerateMap() { diff --git a/Stormtrooper/Stormtrooper/ThirdMap.cs b/Stormtrooper/Stormtrooper/ThirdMap.cs new file mode 100644 index 0000000..a12c413 --- /dev/null +++ b/Stormtrooper/Stormtrooper/ThirdMap.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace Stormtrooper +{ + internal class ThirdMap:AbstractMap + { + /// + /// Цвет участка закрытого + /// + private readonly Brush barrierColor = new SolidBrush(Color.Gray); + /// + /// Цвет участка открытого + /// + private readonly Brush roadColor = new SolidBrush(Color.LightGray); + protected override void DrawBarrierPart(Graphics g, int i, int j) + { + g.FillEllipse(barrierColor, i * _size_x, j * _size_y, _size_x + 3, _size_y + 3); + } + protected override void DrawRoadPart(Graphics g, int i, int j) + { + g.FillRectangle(roadColor, i * _size_x, j * _size_y, _size_x, _size_y); + } + protected override void GenerateMap() + { + _map = new int[100, 100]; + _size_x = (float)_width / _map.GetLength(0); + _size_y = (float)_height / _map.GetLength(1); + int counter = 0; + for (int i = 0; i < _map.GetLength(0); ++i) + { + for (int j = 0; j < _map.GetLength(1); ++j) + { + _map[i, j] = _freeRoad; + } + } + while (counter < 30) + { + int x = _random.Next(0, 30); + int y = _random.Next(0, 30); + if (_map[x, y] == _freeRoad) + { + _map[x, y] = _barrier; + counter++; + } + + x = _random.Next(70, 100); + y = _random.Next(0, 30); + if (_map[x, y] == _freeRoad) + { + _map[x, y] = _barrier; + counter++; + } + + x = _random.Next(40, 60); + y = _random.Next(50, 90); + if (_map[x, y] == _freeRoad) + { + _map[x, y] = _barrier; + counter++; + } + } + } + } +}