From e086076f00315c7c0d90ecd90ad1b278c3139f76 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, 10 Oct 2022 18:49:01 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AirPlaneWithRadar/DrawingPlain.cs | 2 +- .../AirPlaneWithRadar/FormMapWithSetPlains.cs | 9 ++- .../MapWithSetPlainGeneric.cs | 43 ++++++++++++-- .../AirPlaneWithRadar/SetPlaneGeneric.cs | 57 +++++++++++++++++-- .../AirPlaneWithRadar/UserMap_BigBox.cs | 55 ++++++++++++++++++ .../AirPlaneWithRadar/UserMap_Colums.cs | 54 ++++++++++++++++++ 6 files changed, 207 insertions(+), 13 deletions(-) create mode 100644 AirPlaneWithRadar/AirPlaneWithRadar/UserMap_BigBox.cs create mode 100644 AirPlaneWithRadar/AirPlaneWithRadar/UserMap_Colums.cs diff --git a/AirPlaneWithRadar/AirPlaneWithRadar/DrawingPlain.cs b/AirPlaneWithRadar/AirPlaneWithRadar/DrawingPlain.cs index 4599993..f4601a2 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 = 60; public DrawingPlain(int speed, float weight, Color bodycolor) { Plain = new EntetyPlain(speed, weight, bodycolor); diff --git a/AirPlaneWithRadar/AirPlaneWithRadar/FormMapWithSetPlains.cs b/AirPlaneWithRadar/AirPlaneWithRadar/FormMapWithSetPlains.cs index 27d8793..e45d9f6 100644 --- a/AirPlaneWithRadar/AirPlaneWithRadar/FormMapWithSetPlains.cs +++ b/AirPlaneWithRadar/AirPlaneWithRadar/FormMapWithSetPlains.cs @@ -26,7 +26,12 @@ namespace AirPlaneWithRadar case "Простая карта": map = new SimpleMap(); break; - + case "Пользовательская карта №1": + map = new UserMap_BigBox(); + break; + case "Пользовательская карта №2": + map = new UserMap_Colums(); + break; } if (map != null) { @@ -51,7 +56,7 @@ namespace AirPlaneWithRadar { DrawingObjectPlane plain = new(form.SelectedPlain); - if (_mapPlainsCollectionGeneric + plain) + if ((_mapPlainsCollectionGeneric + plain) >= 0) { MessageBox.Show("Объект добавлен"); pictureBox.Image = _mapPlainsCollectionGeneric.ShowSet(); diff --git a/AirPlaneWithRadar/AirPlaneWithRadar/MapWithSetPlainGeneric.cs b/AirPlaneWithRadar/AirPlaneWithRadar/MapWithSetPlainGeneric.cs index b607f05..58687aa 100644 --- a/AirPlaneWithRadar/AirPlaneWithRadar/MapWithSetPlainGeneric.cs +++ b/AirPlaneWithRadar/AirPlaneWithRadar/MapWithSetPlainGeneric.cs @@ -33,12 +33,12 @@ namespace AirPlaneWithRadar _map = map; } - public static bool operator +(MapWithSetPlainGeneric map, T plain) + public static int operator +(MapWithSetPlainGeneric map, T plain) { return map._setPlains.Insert(plain); } - public static bool operator -(MapWithSetPlainGeneric map, int position) + public static T operator -(MapWithSetPlainGeneric map, int position) { return map._setPlains.Remove(position); } @@ -103,7 +103,7 @@ namespace AirPlaneWithRadar private void DrawBackground(Graphics g) { Brush BrushRazmetka = new SolidBrush(Color.DarkGray); - + g.FillRectangle(BrushRazmetka, 0, 0, _pictureWidth, _pictureHeight); Pen pen = new(Color.White, 5); for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++) { @@ -117,7 +117,42 @@ namespace AirPlaneWithRadar } private void DrawPlains(Graphics g) { - + int CountWidth = _pictureWidth / _placeSizeWidth; + + int x = _pictureWidth - _placeSizeWidth - _placeSizeWidth / 2 - _placeSizeWidth / 4; + int y = _placeSizeHeight / 4; + + for (int k = 0; k < _setPlains.Count; k++) + { + if (_setPlains.Get(k) != null) + { + if ((k + 1) % CountWidth != 0 || k == 0) + { + _setPlains.Get(k)?.SetObject(x, y, _pictureWidth, _pictureHeight); + _setPlains.Get(k)?.DrawningObject(g); + x -= _placeSizeWidth; + } + else + { + + _setPlains.Get(k)?.SetObject(x, y, _pictureWidth, _pictureHeight); + _setPlains.Get(k)?.DrawningObject(g); + x = _pictureWidth - _placeSizeWidth - _placeSizeWidth / 2 - _placeSizeWidth / 4; + y += _placeSizeHeight; + + } + } + if (_setPlains.Get(k) == null) + { + if ((k + 1) % CountWidth != 0 || k == 0) + x -= _placeSizeWidth; + else + { + x = _pictureWidth - _placeSizeWidth - _placeSizeWidth / 2 - _placeSizeWidth / 4; + y += _placeSizeHeight; + } + } + } } } diff --git a/AirPlaneWithRadar/AirPlaneWithRadar/SetPlaneGeneric.cs b/AirPlaneWithRadar/AirPlaneWithRadar/SetPlaneGeneric.cs index b1505bd..4196693 100644 --- a/AirPlaneWithRadar/AirPlaneWithRadar/SetPlaneGeneric.cs +++ b/AirPlaneWithRadar/AirPlaneWithRadar/SetPlaneGeneric.cs @@ -16,18 +16,63 @@ namespace AirPlaneWithRadar { _places = new T[count]; } - public bool Insert(T plain) + public int Insert(T plain) { - return true; + int i; + for (i = 0; i < Count; i++) + { + if (_places[i] == null) + { + for (int j = i; j >= 1; j--) + { + _places[j] = _places[j - 1]; + } + _places[0] = plain; + return i; + } + } + + return -1; } - public bool Insert(T plain, int position) + public int Insert(T plain, int position) { - return true; + if (position > Count || position < 0) + return -1; + if (_places[position] == null) + { + _places[position] = plain; + return position; + } + else + { + for (int i = position; i < Count; i++) + { + if (_places[i] == null) + { + for (int j = i; j >= position + 1; j--) + { + _places[j] = _places[j - 1]; + } + _places[position] = plain; + return position; + } + } + } + return -1; } - public bool Remove(int position) + public T Remove(int position) { - return false; + T mid; + if (_places[position] != null && position < _places.Length) + { + mid = _places[position]; + _places[position] = null; + return mid; + + } + else + return null; } public T Get(int position) { diff --git a/AirPlaneWithRadar/AirPlaneWithRadar/UserMap_BigBox.cs b/AirPlaneWithRadar/AirPlaneWithRadar/UserMap_BigBox.cs new file mode 100644 index 0000000..86e9459 --- /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..f6b112b --- /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 (i < iWall || i > iWall + sizeHole) + _map[jWall, i] = _barrier; + + } + counter++; + } + } + } +}