From 94bd87f67f186b00298f2bd7be9891e9c965f2af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=BE=D0=BB=D0=BE=D0=B4=D1=8F?= Date: Mon, 3 Oct 2022 09:38:22 +0300 Subject: [PATCH] generic classes --- .../AirPlaneWithRadar/AbstractMap.cs | 73 +++++++++- ...DrawingObject.cs => DrawingObjectPlane.cs} | 11 +- .../AirPlaneWithRadar/DrawingPlain.cs | 2 +- .../AirPlaneWithRadar/DrawingRadarPlane.cs | 2 +- .../AirPlaneWithRadar/FormMap.Designer.cs | 28 ++-- .../AirPlaneWithRadar/FormMap.cs | 9 +- .../AirPlaneWithRadar/IDrawingObject.cs | 3 +- .../MapWithSetPlainGeneric.cs | 126 ++++++++++++++++++ .../AirPlaneWithRadar/SetPlaneGeneric.cs | 41 ++++++ .../AirPlaneWithRadar/SimpleMap.cs | 2 +- .../AirPlaneWithRadar/UserMap_BigBox.cs | 55 ++++++++ .../AirPlaneWithRadar/UserMap_Colums.cs | 54 ++++++++ 12 files changed, 380 insertions(+), 26 deletions(-) rename AirPlaneWithRadar/AirPlaneWithRadar/{DrawingObject.cs => DrawingObjectPlane.cs} (75%) create mode 100644 AirPlaneWithRadar/AirPlaneWithRadar/MapWithSetPlainGeneric.cs create mode 100644 AirPlaneWithRadar/AirPlaneWithRadar/SetPlaneGeneric.cs create mode 100644 AirPlaneWithRadar/AirPlaneWithRadar/UserMap_BigBox.cs create mode 100644 AirPlaneWithRadar/AirPlaneWithRadar/UserMap_Colums.cs diff --git a/AirPlaneWithRadar/AirPlaneWithRadar/AbstractMap.cs b/AirPlaneWithRadar/AirPlaneWithRadar/AbstractMap.cs index 1f32cf1..1541d6e 100644 --- a/AirPlaneWithRadar/AirPlaneWithRadar/AbstractMap.cs +++ b/AirPlaneWithRadar/AirPlaneWithRadar/AbstractMap.cs @@ -32,12 +32,66 @@ namespace AirPlaneWithRadar } public Bitmap MoveObject(Direction direction) { - // TODO проверка, что объект может переместится в требуемом направлении - if (true) + + switch (direction) { - _drawningObject.MoveObject(direction); + case Direction.Up: + for (int i = 0; i < _map.GetLength(0); i++) + { + for (int j = 0; j < _map.GetLength(1); j++) + { + if (_map[i, j] == _barrier && ((_drawningObject.GetCurrentPosition().Left < i * _size_x && _drawningObject.GetCurrentPosition().Top > i * _size_x)|| + (_drawningObject.GetCurrentPosition().Left < i * (_size_x+1) && _drawningObject.GetCurrentPosition().Top > i * (_size_x+1)))&& + j*(_size_y+1)< _drawningObject.GetCurrentPosition().Right && _drawningObject.GetCurrentPosition().Right - j * (_size_y + 1) <= _drawningObject.Step) + return DrawMapWithObject(); + + } + } + break; + case Direction.Down: + for (int i = 0; i < _map.GetLength(0); i++) + { + for (int j = 0; j < _map.GetLength(1); j++) + { + if (_map[i, j] == _barrier && ((_drawningObject.GetCurrentPosition().Left < i * _size_x && _drawningObject.GetCurrentPosition().Top > i * _size_x) || + (_drawningObject.GetCurrentPosition().Left < i * (_size_x + 1) && _drawningObject.GetCurrentPosition().Top > i * (_size_x + 1))) && + j * _size_y > _drawningObject.GetCurrentPosition().Bottom && j * _size_y - _drawningObject.GetCurrentPosition().Bottom <= _drawningObject.Step) + return DrawMapWithObject(); + + } + } + break; + case Direction.Left: + for (int i = 0; i < _map.GetLength(0); i++) + { + for (int j = 0; j < _map.GetLength(1); j++) + { + if (_map[i, j] == _barrier && ((_drawningObject.GetCurrentPosition().Right < j * _size_y && _drawningObject.GetCurrentPosition().Bottom > j * _size_y) || + (_drawningObject.GetCurrentPosition().Right < j * (_size_y + 1) && _drawningObject.GetCurrentPosition().Bottom > j * (_size_y + 1))) && + i * (_size_x+1)< _drawningObject.GetCurrentPosition().Left && _drawningObject.GetCurrentPosition().Left - i * (_size_x + 1) <= _drawningObject.Step) + return DrawMapWithObject(); + + } + } + break; + case Direction.Right: + for (int i = 0; i < _map.GetLength(0); i++) + { + for (int j = 0; j < _map.GetLength(1); j++) + { + if (_map[i, j] == _barrier && ((_drawningObject.GetCurrentPosition().Right < j * _size_y && _drawningObject.GetCurrentPosition().Bottom > j * _size_y) || + (_drawningObject.GetCurrentPosition().Right < j * (_size_y + 1) && _drawningObject.GetCurrentPosition().Bottom > j * (_size_y + 1))) && + i * (_size_x ) > _drawningObject.GetCurrentPosition().Top && i * (_size_x ) - _drawningObject.GetCurrentPosition().Top <= _drawningObject.Step) + return DrawMapWithObject(); + + } + } + break; } + _drawningObject.MoveObject(direction); return DrawMapWithObject(); + + } private bool SetObjectOnMap() { @@ -48,7 +102,18 @@ namespace AirPlaneWithRadar int x = _random.Next(0, 10); int y = _random.Next(0, 10); _drawningObject.SetObject(x, y, _width, _height); - // TODO првоерка, что объект не "накладывается" на закрытые участки + if(_drawningObject is DrawingObjectPlane ) + { + for (int i = 0; i < _map.GetLength(0); i++) + { + for (int j = 0; j < _map.GetLength(1); j++) + { + if (_map[i, j] == _barrier && _drawningObject.GetCurrentPosition().Left < i*_size_x && _drawningObject.GetCurrentPosition().Right < j*_size_y && _drawningObject.GetCurrentPosition().Top > i*_size_x && _drawningObject.GetCurrentPosition().Bottom > j*_size_y) + return false; + } + } + } + return true; } private Bitmap DrawMapWithObject() diff --git a/AirPlaneWithRadar/AirPlaneWithRadar/DrawingObject.cs b/AirPlaneWithRadar/AirPlaneWithRadar/DrawingObjectPlane.cs similarity index 75% rename from AirPlaneWithRadar/AirPlaneWithRadar/DrawingObject.cs rename to AirPlaneWithRadar/AirPlaneWithRadar/DrawingObjectPlane.cs index 8fa9368..c265b27 100644 --- a/AirPlaneWithRadar/AirPlaneWithRadar/DrawingObject.cs +++ b/AirPlaneWithRadar/AirPlaneWithRadar/DrawingObjectPlane.cs @@ -1,16 +1,17 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Security.Cryptography.X509Certificates; using System.Text; using System.Threading.Tasks; namespace AirPlaneWithRadar { - internal class DrawingObject : IDrawingObject + internal class DrawingObjectPlane : IDrawingObject { - private DrawingPlain _plain; + private DrawingPlain _plain = null; - public DrawingObject(DrawingPlain plain) + public DrawingObjectPlane(DrawingPlain plain) { _plain = plain; } @@ -19,14 +20,14 @@ namespace AirPlaneWithRadar public void DrawningObject(Graphics g) { - //TODO + _plain?.DrawTransoprt(g); } public (float Left, float Right, float Top, float Bottom) GetCurrentPosition() { return _plain?.GetCurrentPosition() ?? default; } - + public void MoveObject(Direction direction) { _plain?.MoveTransport(direction); diff --git a/AirPlaneWithRadar/AirPlaneWithRadar/DrawingPlain.cs b/AirPlaneWithRadar/AirPlaneWithRadar/DrawingPlain.cs index 2211625..2b6bea5 100644 --- a/AirPlaneWithRadar/AirPlaneWithRadar/DrawingPlain.cs +++ b/AirPlaneWithRadar/AirPlaneWithRadar/DrawingPlain.cs @@ -15,7 +15,7 @@ namespace AirPlaneWithRadar private int? pictureWidth = null; private int? pictureHeight = null; protected readonly int plainWidth = 120; - protected readonly int plainHeight = 70; + protected readonly int plainHeight = 80; public DrawingPlain(int speed, float weight, Color bodycolor) { Plain = new EntetyPlain(speed, weight, bodycolor); diff --git a/AirPlaneWithRadar/AirPlaneWithRadar/DrawingRadarPlane.cs b/AirPlaneWithRadar/AirPlaneWithRadar/DrawingRadarPlane.cs index 9747a0e..a033bbd 100644 --- a/AirPlaneWithRadar/AirPlaneWithRadar/DrawingRadarPlane.cs +++ b/AirPlaneWithRadar/AirPlaneWithRadar/DrawingRadarPlane.cs @@ -9,7 +9,7 @@ namespace AirPlaneWithRadar { internal class DrawingRadarPlane : DrawingPlain { - public DrawingRadarPlane(int speed, float weight, Color bodyColor,Color dopColor, bool radar, bool oilBox) : base(speed, weight, bodyColor, 110, 60) + public DrawingRadarPlane(int speed, float weight, Color bodyColor,Color dopColor, bool radar, bool oilBox) : base(speed, weight, bodyColor, 120, 80) { Plain = new RadioPlane(speed, weight, bodyColor, dopColor, radar, oilBox); } diff --git a/AirPlaneWithRadar/AirPlaneWithRadar/FormMap.Designer.cs b/AirPlaneWithRadar/AirPlaneWithRadar/FormMap.Designer.cs index 40e3196..7877bfa 100644 --- a/AirPlaneWithRadar/AirPlaneWithRadar/FormMap.Designer.cs +++ b/AirPlaneWithRadar/AirPlaneWithRadar/FormMap.Designer.cs @@ -49,7 +49,7 @@ this.pictureBoxPlain.Dock = System.Windows.Forms.DockStyle.Fill; this.pictureBoxPlain.Location = new System.Drawing.Point(0, 0); this.pictureBoxPlain.Name = "pictureBoxPlain"; - this.pictureBoxPlain.Size = new System.Drawing.Size(535, 292); + this.pictureBoxPlain.Size = new System.Drawing.Size(908, 470); this.pictureBoxPlain.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; this.pictureBoxPlain.TabIndex = 0; this.pictureBoxPlain.TabStop = false; @@ -61,9 +61,9 @@ this.toolStripStatusLabelSpeed, this.toolStripStatusLabelWeight, this.toolStripStatusLabelColor}); - this.statusStrip.Location = new System.Drawing.Point(0, 292); + this.statusStrip.Location = new System.Drawing.Point(0, 470); this.statusStrip.Name = "statusStrip"; - this.statusStrip.Size = new System.Drawing.Size(535, 26); + this.statusStrip.Size = new System.Drawing.Size(908, 26); this.statusStrip.TabIndex = 1; // // toolStripStatusLabelSpeed @@ -89,7 +89,7 @@ this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonUp.BackgroundImage = global::AirPlaneWithRadar.Properties.Resources.up; this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonUp.Location = new System.Drawing.Point(383, 223); + this.buttonUp.Location = new System.Drawing.Point(756, 401); this.buttonUp.Name = "buttonUp"; this.buttonUp.Size = new System.Drawing.Size(30, 30); this.buttonUp.TabIndex = 3; @@ -102,7 +102,7 @@ this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonLeft.BackgroundImage = global::AirPlaneWithRadar.Properties.Resources.left; this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonLeft.Location = new System.Drawing.Point(347, 259); + this.buttonLeft.Location = new System.Drawing.Point(720, 437); this.buttonLeft.Name = "buttonLeft"; this.buttonLeft.Size = new System.Drawing.Size(30, 30); this.buttonLeft.TabIndex = 4; @@ -115,7 +115,7 @@ this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonDown.BackgroundImage = global::AirPlaneWithRadar.Properties.Resources.down; this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonDown.Location = new System.Drawing.Point(383, 259); + this.buttonDown.Location = new System.Drawing.Point(756, 437); this.buttonDown.Name = "buttonDown"; this.buttonDown.Size = new System.Drawing.Size(30, 30); this.buttonDown.TabIndex = 5; @@ -128,7 +128,7 @@ this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonRight.BackgroundImage = global::AirPlaneWithRadar.Properties.Resources.right; this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonRight.Location = new System.Drawing.Point(419, 259); + this.buttonRight.Location = new System.Drawing.Point(792, 437); this.buttonRight.Name = "buttonRight"; this.buttonRight.Size = new System.Drawing.Size(30, 30); this.buttonRight.TabIndex = 6; @@ -139,7 +139,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(12, 259); + this.ButtonCreate.Location = new System.Drawing.Point(12, 437); this.ButtonCreate.Name = "ButtonCreate"; this.ButtonCreate.Size = new System.Drawing.Size(94, 29); this.ButtonCreate.TabIndex = 7; @@ -149,7 +149,8 @@ // // buttonCreateModif // - this.buttonCreateModif.Location = new System.Drawing.Point(125, 259); + this.buttonCreateModif.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.buttonCreateModif.Location = new System.Drawing.Point(112, 437); this.buttonCreateModif.Name = "buttonCreateModif"; this.buttonCreateModif.Size = new System.Drawing.Size(134, 29); this.buttonCreateModif.TabIndex = 8; @@ -159,12 +160,15 @@ // // comboBoxMap // + this.comboBoxMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.comboBoxMap.FormattingEnabled = true; this.comboBoxMap.Items.AddRange(new object[] { - "Простая карта"}); + "Простая карта", + "Пользовательская карта №1", + "Пользовательская карта №2"}); this.comboBoxMap.Location = new System.Drawing.Point(24, 12); this.comboBoxMap.Name = "comboBoxMap"; - this.comboBoxMap.Size = new System.Drawing.Size(151, 28); + this.comboBoxMap.Size = new System.Drawing.Size(188, 28); this.comboBoxMap.TabIndex = 9; this.comboBoxMap.SelectedIndexChanged += new System.EventHandler(this.comboBoxMap_SelectedIndexChanged); // @@ -172,7 +176,7 @@ // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(535, 318); + this.ClientSize = new System.Drawing.Size(908, 496); this.Controls.Add(this.comboBoxMap); this.Controls.Add(this.buttonCreateModif); this.Controls.Add(this.ButtonCreate); diff --git a/AirPlaneWithRadar/AirPlaneWithRadar/FormMap.cs b/AirPlaneWithRadar/AirPlaneWithRadar/FormMap.cs index 82e202c..3f3fcb4 100644 --- a/AirPlaneWithRadar/AirPlaneWithRadar/FormMap.cs +++ b/AirPlaneWithRadar/AirPlaneWithRadar/FormMap.cs @@ -23,7 +23,7 @@ namespace AirPlaneWithRadar toolStripStatusLabelSpeed.Text = $"Скорость: {plain.Plain.Speed}"; toolStripStatusLabelWeight.Text = $"Вес: {plain.Plain.Weight}"; toolStripStatusLabelColor.Text = $"Цвет: {plain.Plain.BodyColor.Name}"; - pictureBoxPlain.Image = _abstractMap.CreateMap(pictureBoxPlain.Width, pictureBoxPlain.Height,new DrawingObject(plain)) ; + pictureBoxPlain.Image = _abstractMap.CreateMap(pictureBoxPlain.Width, pictureBoxPlain.Height,new DrawingObjectPlane(plain)) ; } private void ButtonCreate_Click(object sender, EventArgs e) { @@ -73,6 +73,13 @@ namespace AirPlaneWithRadar case "Простая карта": _abstractMap = new SimpleMap(); break; + + case "Пользовательская карта №1": + _abstractMap = new UserMap_BigBox(); + break; + case "Пользовательская карта №2": + _abstractMap = new UserMap_Colums(); + break; } } } diff --git a/AirPlaneWithRadar/AirPlaneWithRadar/IDrawingObject.cs b/AirPlaneWithRadar/AirPlaneWithRadar/IDrawingObject.cs index 6fec5b5..4099d45 100644 --- a/AirPlaneWithRadar/AirPlaneWithRadar/IDrawingObject.cs +++ b/AirPlaneWithRadar/AirPlaneWithRadar/IDrawingObject.cs @@ -13,7 +13,8 @@ namespace AirPlaneWithRadar void MoveObject(Direction direction); void DrawningObject(Graphics g); - + + (float Left, float Right, float Top, float Bottom) GetCurrentPosition(); } } diff --git a/AirPlaneWithRadar/AirPlaneWithRadar/MapWithSetPlainGeneric.cs b/AirPlaneWithRadar/AirPlaneWithRadar/MapWithSetPlainGeneric.cs new file mode 100644 index 0000000..559a16d --- /dev/null +++ b/AirPlaneWithRadar/AirPlaneWithRadar/MapWithSetPlainGeneric.cs @@ -0,0 +1,126 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AirPlaneWithRadar +{ + internal class MapWithSetPlainGeneric + where T : class, IDrawingObject + where U : AbstractMap + { + private readonly int _pictureWidth; + + private readonly int _pictureHeight; + + private readonly int _placeSizeWidth = 180; + + private readonly int _placeSizeHeight = 90; + + private readonly SetPlaneGeneric _setPlains; + + private readonly U _map; + + public MapWithSetPlainGeneric(int picWidth, int picHeight, U map) + { + int width = picWidth / _placeSizeWidth; + int height = picHeight / _placeSizeHeight; + _setPlains = new SetPlaneGeneric(width * height); + _pictureWidth = picWidth; + _pictureHeight = picHeight; + _map = map; + } + + public static bool operator +(MapWithSetPlainGeneric map, T car) + { + return map._setPlains.Insert(car); + } + + public static bool operator -(MapWithSetPlainGeneric map, int position) + { + return map._setPlains.Remove(position); + } + + public Bitmap ShowSet() + { + Bitmap bmp = new(_pictureWidth, _pictureHeight); + Graphics gr = Graphics.FromImage(bmp); + DrawBackground(gr); + DrawPlains(gr); + return bmp; + } + + public Bitmap ShowOnMap() + { + Shaking(); + for (int i = 0; i < _setPlains.Count; i++) + { + var car = _setPlains.Get(i); + if (car != null) + { + return _map.CreateMap(_pictureWidth, _pictureHeight, car); + } + } + return new(_pictureWidth, _pictureHeight); + } + + public Bitmap MoveObject(Direction direction) + { + if (_map != null) + { + return _map.MoveObject(direction); + } + return new(_pictureWidth, _pictureHeight); + } + + private void Shaking() + { + int j = _setPlains.Count - 1; + for (int i = 0; i < _setPlains.Count; i++) + { + if (_setPlains.Get(i) == null) + { + for (; j > i; j--) + { + var car = _setPlains.Get(j); + if (car != null) + { + _setPlains.Insert(car, i); + _setPlains.Remove(j); + break; + } + } + if (j <= i) + { + return; + } + } + } + } + + private void DrawBackground(Graphics g) + { + + Pen pen = new(Color.White, 5); + for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++) + { + for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j) + { + + g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight); + } + g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, (_pictureHeight / _placeSizeHeight) * _placeSizeHeight); + } + } + private void DrawPlains(Graphics g) + { + + for (int i = 0; i < _setPlains.Count; i++) + { + + _setPlains.Get(i)?.DrawningObject(g); + } + } + } +} diff --git a/AirPlaneWithRadar/AirPlaneWithRadar/SetPlaneGeneric.cs b/AirPlaneWithRadar/AirPlaneWithRadar/SetPlaneGeneric.cs new file mode 100644 index 0000000..b49139f --- /dev/null +++ b/AirPlaneWithRadar/AirPlaneWithRadar/SetPlaneGeneric.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AirPlaneWithRadar +{ + internal class SetPlaneGeneric + where T : class + { + private readonly T[] _places; + public int Count => _places.Length; + public SetPlaneGeneric(int count) + { + _places = new T[count]; + } + public bool Insert(T plain) + { + + + return true; + } + public bool Insert(T plain, int position) + { + + return true; + + } + public bool Remove(int position) + { + + return false; + } + public T Get(int position) + { + return _places[position]; + } + + } +} diff --git a/AirPlaneWithRadar/AirPlaneWithRadar/SimpleMap.cs b/AirPlaneWithRadar/AirPlaneWithRadar/SimpleMap.cs index 92dd4c3..053304e 100644 --- a/AirPlaneWithRadar/AirPlaneWithRadar/SimpleMap.cs +++ b/AirPlaneWithRadar/AirPlaneWithRadar/SimpleMap.cs @@ -9,7 +9,7 @@ namespace AirPlaneWithRadar internal class SimpleMap : AbstractMap { Brush barrierColor = new SolidBrush(Color.DarkGray); - Brush roadColor = new SolidBrush(Color.Blue); + Brush roadColor = new SolidBrush(Color.Aqua); 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)); diff --git a/AirPlaneWithRadar/AirPlaneWithRadar/UserMap_BigBox.cs b/AirPlaneWithRadar/AirPlaneWithRadar/UserMap_BigBox.cs new file mode 100644 index 0000000..f974b16 --- /dev/null +++ b/AirPlaneWithRadar/AirPlaneWithRadar/UserMap_BigBox.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AirPlaneWithRadar +{ + internal class UserMap_BigBox : AbstractMap + { + Brush barrierColor = new SolidBrush(Color.DarkGray); + Brush roadColor = new SolidBrush(Color.Aqua); + 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 sizeKub = 5; + 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 < 10) + { + Random rand = new Random(); + int i = rand.Next(0,100); + int j = rand.Next(0,100); + if (i > _map.GetLength(0) - sizeKub || j > _map.GetLength(0) - sizeKub) + continue; + for(int iKub = i; iKub < i+sizeKub; iKub++) + { + for(int jKub = j; jKub < j+ sizeKub; jKub++) + { + _map[iKub,jKub] = _barrier; + } + } + counter++; + } + + } + } +} diff --git a/AirPlaneWithRadar/AirPlaneWithRadar/UserMap_Colums.cs b/AirPlaneWithRadar/AirPlaneWithRadar/UserMap_Colums.cs new file mode 100644 index 0000000..5c36628 --- /dev/null +++ b/AirPlaneWithRadar/AirPlaneWithRadar/UserMap_Colums.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AirPlaneWithRadar +{ + internal class UserMap_Colums : AbstractMap + { + Brush barrierColor = new SolidBrush(Color.DarkGray); + Brush roadColor = new SolidBrush(Color.Aqua); + 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 sizeHole = 30; + 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 < 3) + { + Random rand = new Random(); + int iWall = rand.Next(0, 100); + int jWall = rand.Next(0, 100); + if (iWall > _map.GetLength(0) - sizeHole) + continue; + for (int i = 0; i < _map.GetLength(0); i++) + { + + if(iiWall+sizeHole) + _map[jWall, i] = _barrier; + + } + counter++; + } + } + } +}