From a71b990a512ac70b2387e7dabd36ef766c7c94aa Mon Sep 17 00:00:00 2001 From: "Nikolaeva_Y.A" Date: Mon, 21 Nov 2022 22:22:00 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=B0?= =?UTF-8?q?=D1=86=D0=B8=D1=8F=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F=20=D0=BE=D0=B1=D1=8A=D0=B5=D0=BA=D1=82=D0=BE?= =?UTF-8?q?=D0=B2=20=D0=B2=20=D1=85=D1=80=D0=B0=D0=BD=D0=B8=D0=BB=D0=B8?= =?UTF-8?q?=D1=89=D0=B5.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Airbus/Airbus/DrawningAirbus.cs | 18 ++--- Airbus/Airbus/FormAirbus.Designer.cs | 1 + Airbus/Airbus/FormAirbus.cs | 30 ++++++- .../Airbus/FormMapWithSetPlanes.Designer.cs | 8 +- Airbus/Airbus/FormMapWithSetPlanes.cs | 17 ++-- Airbus/Airbus/MapWithSetPlanesGeneric.cs | 80 +++++++++++++++++-- Airbus/Airbus/SetPlanesGeneric.cs | 74 +++++++++++++---- 7 files changed, 184 insertions(+), 44 deletions(-) diff --git a/Airbus/Airbus/DrawningAirbus.cs b/Airbus/Airbus/DrawningAirbus.cs index a983dd7..d2b6097 100644 --- a/Airbus/Airbus/DrawningAirbus.cs +++ b/Airbus/Airbus/DrawningAirbus.cs @@ -100,7 +100,7 @@ namespace Airbus return; } Pen pen = new Pen(Color.Black); - Brush brBlack = new SolidBrush(Color.Black); + Brush selectedBrush = new SolidBrush(Airbus.CorpusColor); Brush br = new SolidBrush(Airbus?.CorpusColor ?? Color.Black); //хвостовое крыло @@ -110,7 +110,7 @@ namespace Airbus PointF point3 = new PointF(_startPosX + 30, _startPosY + 30); PointF[] nose = { point1, point2, point3 }; g.DrawPolygon(pen, nose); - g.FillPolygon(brBlack, nose); + g.FillPolygon(selectedBrush, nose); //корпус @@ -120,7 +120,7 @@ namespace Airbus PointF point7 = new PointF(_startPosX, _startPosY + 50); PointF[] rwing = { point4, point5, point6, point7 }; g.DrawPolygon(pen, rwing); - g.FillPolygon(brBlack, rwing); + g.FillPolygon(selectedBrush, rwing); // нос самолёта @@ -129,7 +129,7 @@ namespace Airbus PointF point10 = new PointF(_startPosX + 100, _startPosY + 40); PointF[] lwing = { point8, point9, point10 }; g.DrawPolygon(pen, lwing); - g.FillPolygon(brBlack, lwing); + g.FillPolygon(selectedBrush, lwing); //задние шасси @@ -149,12 +149,12 @@ namespace Airbus //задние шасси - g.FillEllipse(brBlack, _startPosX + 10, _startPosY + 55, 10, 10); - g.FillEllipse(brBlack, _startPosX + 45, _startPosY + 55, 10, 10); + g.FillEllipse(selectedBrush, _startPosX + 10, _startPosY + 55, 10, 10); + g.FillEllipse(selectedBrush, _startPosX + 45, _startPosY + 55, 10, 10); //переднее шасси - g.FillEllipse(brBlack, _startPosX, _startPosY + 55, 10, 10); + g.FillEllipse(selectedBrush, _startPosX, _startPosY + 55, 10, 10); g.FillPolygon(br, lwing); @@ -166,11 +166,11 @@ namespace Airbus //заднее поперечное крыло - g.FillEllipse(brBlack, _startPosX, _startPosY + 25, 25, 10); + g.FillEllipse(selectedBrush, _startPosX, _startPosY + 25, 25, 10); //крыло - g.FillEllipse(brBlack, _startPosX + 20, _startPosY + 35, 50, 10); + g.FillEllipse(selectedBrush, _startPosX + 20, _startPosY + 35, 50, 10); } //смена границ формы отрисовки diff --git a/Airbus/Airbus/FormAirbus.Designer.cs b/Airbus/Airbus/FormAirbus.Designer.cs index 299eb03..03db08c 100644 --- a/Airbus/Airbus/FormAirbus.Designer.cs +++ b/Airbus/Airbus/FormAirbus.Designer.cs @@ -165,6 +165,7 @@ this.buttonSelectPlane.TabIndex = 8; this.buttonSelectPlane.Text = "Выбрать"; this.buttonSelectPlane.UseVisualStyleBackColor = true; + this.buttonSelectPlane.Click += new System.EventHandler(this.buttonSelectPlane_Click); // // FormAirbus // diff --git a/Airbus/Airbus/FormAirbus.cs b/Airbus/Airbus/FormAirbus.cs index 4653d19..8d5be2c 100644 --- a/Airbus/Airbus/FormAirbus.cs +++ b/Airbus/Airbus/FormAirbus.cs @@ -42,7 +42,15 @@ namespace Airbus private void ButtonCreate_Click(object sender, EventArgs e) { Random rnd = new(); - _airbus = new DrawningAirbus(rnd.Next(100, 300), rnd.Next(1000, 2000),Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); + Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)); + ColorDialog dialog = new(); + + if (dialog.ShowDialog() == DialogResult.OK) + { + color = dialog.Color; + } + + _airbus = new DrawningAirbus(rnd.Next(100, 300), rnd.Next(1000, 2000), color); SetData(); Draw(); } @@ -80,9 +88,23 @@ namespace Airbus private void ButtonCreateModif_Click(object sender, EventArgs e) { Random rnd = new(); - _airbus = new DrawningSuperAirbus(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)), + Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)); + ColorDialog dialog = new(); + + if (dialog.ShowDialog() == DialogResult.OK) + { + color = dialog.Color; + } + + Color addColor = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)); + ColorDialog dialogAdd = new(); + + if (dialogAdd.ShowDialog() == DialogResult.OK) + { + addColor = dialogAdd.Color; + } + + _airbus = new DrawningSuperAirbus(rnd.Next(100, 300), rnd.Next(1000, 2000), color, addColor, Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2))); SetData(); Draw(); diff --git a/Airbus/Airbus/FormMapWithSetPlanes.Designer.cs b/Airbus/Airbus/FormMapWithSetPlanes.Designer.cs index 85d8ea3..d390d67 100644 --- a/Airbus/Airbus/FormMapWithSetPlanes.Designer.cs +++ b/Airbus/Airbus/FormMapWithSetPlanes.Designer.cs @@ -81,7 +81,7 @@ // // maskedTextBoxPosition // - this.maskedTextBoxPosition.Location = new System.Drawing.Point(21, 203); + this.maskedTextBoxPosition.Location = new System.Drawing.Point(21, 141); this.maskedTextBoxPosition.Name = "maskedTextBoxPosition"; this.maskedTextBoxPosition.Size = new System.Drawing.Size(167, 23); this.maskedTextBoxPosition.TabIndex = 8; @@ -98,7 +98,7 @@ // // buttonRemovePlane // - this.buttonRemovePlane.Location = new System.Drawing.Point(21, 151); + this.buttonRemovePlane.Location = new System.Drawing.Point(21, 181); this.buttonRemovePlane.Name = "buttonRemovePlane"; this.buttonRemovePlane.Size = new System.Drawing.Size(167, 25); this.buttonRemovePlane.TabIndex = 6; @@ -114,7 +114,7 @@ this.buttonShowStorage.TabIndex = 5; this.buttonShowStorage.Text = "Посмотреть хранилище"; this.buttonShowStorage.UseVisualStyleBackColor = true; - this.buttonShowStorage.Click += new System.EventHandler(this.buttonShowStorage_Click); + this.buttonShowStorage.Click += new System.EventHandler(this.ButtonShowStorage_Click); // // buttonShowOnMap // @@ -124,7 +124,7 @@ this.buttonShowOnMap.TabIndex = 4; this.buttonShowOnMap.Text = "Посмотреть карту"; this.buttonShowOnMap.UseVisualStyleBackColor = true; - this.buttonShowOnMap.Click += new System.EventHandler(this.buttonShowOnMap_Click); + this.buttonShowOnMap.Click += new System.EventHandler(this.ButtonShowOnMap_Click); // // buttonLeft // diff --git a/Airbus/Airbus/FormMapWithSetPlanes.cs b/Airbus/Airbus/FormMapWithSetPlanes.cs index 2a30ca5..11d7c16 100644 --- a/Airbus/Airbus/FormMapWithSetPlanes.cs +++ b/Airbus/Airbus/FormMapWithSetPlanes.cs @@ -30,6 +30,12 @@ namespace Airbus case "Простая карта": map = new SimpleMap(); break; + case "Пустыня": + map = new DesertMap(); + break; + case "Космос": + map = new SpaceMap(); + break; } if (map != null) @@ -40,6 +46,7 @@ namespace Airbus else { _mapPlanesCollectionGeneric = null; + } } @@ -57,7 +64,7 @@ namespace Airbus { DrawningObjectPlane plane = new(form.SelectedPlane); - if (_mapPlanesCollectionGeneric + plane) + if (_mapPlanesCollectionGeneric + plane != -1) { MessageBox.Show("Объект добавлен"); pictureBox.Image = _mapPlanesCollectionGeneric.ShowSet(); @@ -68,7 +75,7 @@ namespace Airbus } } } - + //удаление объекта private void ButtonRemovePlane_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(maskedTextBoxPosition.Text)) @@ -84,7 +91,7 @@ namespace Airbus int pos = Convert.ToInt32(maskedTextBoxPosition.Text); - if (_mapPlanesCollectionGeneric - pos) + if (_mapPlanesCollectionGeneric - pos != null) { MessageBox.Show("Объект удалён"); pictureBox.Image = _mapPlanesCollectionGeneric.ShowSet(); @@ -96,7 +103,7 @@ namespace Airbus } //вывод набора - private void buttonShowStorage_Click(object sender, EventArgs e) + private void ButtonShowStorage_Click(object sender, EventArgs e) { if (_mapPlanesCollectionGeneric == null) { @@ -107,7 +114,7 @@ namespace Airbus } //вывод карты - private void buttonShowOnMap_Click(object sender, EventArgs e) + private void ButtonShowOnMap_Click(object sender, EventArgs e) { if (_mapPlanesCollectionGeneric == null) { diff --git a/Airbus/Airbus/MapWithSetPlanesGeneric.cs b/Airbus/Airbus/MapWithSetPlanesGeneric.cs index c81f30b..28114e5 100644 --- a/Airbus/Airbus/MapWithSetPlanesGeneric.cs +++ b/Airbus/Airbus/MapWithSetPlanesGeneric.cs @@ -1,6 +1,8 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Numerics; +using System.Runtime.Intrinsics.Arm; using System.Text; using System.Threading.Tasks; @@ -36,13 +38,13 @@ namespace Airbus } //пеергрузка оператора сложения - public static bool operator +(MapWithSetPlanesGeneric map, T plane) + public static int operator +(MapWithSetPlanesGeneric map, T plane) { return map._setPlanes.Insert(plane); } //перегрузка оператора вычитания - public static bool operator -(MapWithSetPlanesGeneric map, int position) + public static T operator -(MapWithSetPlanesGeneric map, int position) { return map._setPlanes.Remove(position); } @@ -119,25 +121,89 @@ namespace Airbus public void DrawBackground(Graphics g) { Pen pen = new(Color.Black, 3); + Pen marcupPen = new(Color.White, 5); + Pen signalFirePen = new(Color.OrangeRed, 5); + Brush concreteBrush = new SolidBrush(Color.LightGray); + Brush asphaltBrush = new SolidBrush(Color.DarkGray); + Brush marcupBrush = new SolidBrush(Color.White); - for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++) + g.FillRectangle(concreteBrush, 0, 0, _pictureWidth, _pictureHeight); //заливаем область в цвет бетона + + + for (int i = 0; i < _pictureWidth / _placeSizeWidth - 1; i++) { - for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j) + for (int j = 2; j < _pictureHeight / _placeSizeHeight + 1; ++j) {//линия разметки места - g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight); + g.DrawLine(pen, i * _placeSizeWidth + 5, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2 + 5, j * _placeSizeHeight); } - g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, (_pictureHeight / _placeSizeHeight) * _placeSizeHeight); + g.DrawLine(pen, i * _placeSizeWidth + 5, _placeSizeHeight * 2, i * _placeSizeWidth + 5, (_pictureHeight / _placeSizeHeight) * _placeSizeHeight); + + } + //отрисовка разметки взлётной полосы + g.FillRectangle(marcupBrush, _placeSizeWidth * 2 + 30, 0, 185, _pictureHeight); + g.FillRectangle(asphaltBrush, _placeSizeWidth * 2 + 35, 0, 175, _pictureHeight); + g.DrawLine(marcupPen, _placeSizeWidth * 2 + 210, 0, _placeSizeWidth * 2 + 210, _pictureHeight); + g.DrawLine(marcupPen, _placeSizeWidth * 2 + 35, 0, _placeSizeWidth * 2 + 35, _pictureHeight); + g.DrawLine(marcupPen, _placeSizeWidth * 2 + 215, 0, _placeSizeWidth * 2 + 215, _pictureHeight); + g.DrawLine(marcupPen, _placeSizeWidth * 2 + 30, 0, _placeSizeWidth * 2 + 30, _pictureHeight); + + for (int i = 0; i < _pictureHeight / _placeSizeHeight; ++i) + { + g.DrawLine(marcupPen, _placeSizeWidth * 2 + 125, 20 + i * _placeSizeHeight, _placeSizeWidth * 2 + 125, (i + 1) * _placeSizeHeight - 20); + } + + for (int i = 0; i < _pictureHeight / 20; i++) + { + g.DrawLine(signalFirePen, _placeSizeWidth * 2 + 15, 20 + i * _placeSizeHeight / 2, _placeSizeWidth * 2 + 15, (i + 1) * _placeSizeHeight / 2 - 20); + g.DrawLine(signalFirePen, _placeSizeWidth * 3 + 20, 20 + i * _placeSizeHeight / 2, _placeSizeWidth * 3 + 20, (i + 1) * _placeSizeHeight / 2 - 20); + } + + //отрисовка сочков + Brush pinkBrush = new SolidBrush(Color.LightPink); + for (int i = 1; i < 6; i++) + { + Point[] point = new Point[] + { + new Point((i * 70 - 10) + 45, 30), + new Point(i * 70 - 10, 50), + new Point( i * 70 - 10 , 10) + }; + g.FillPolygon(pinkBrush, point); + + g.DrawLine(pen, i * 70 - 10, 10, i * 70 - 10, 80); + g.DrawLine(pen, i * 70 - 10, 10, (i * 70 - 10) + 45, 30); + g.DrawLine(pen, i * 70 - 10, 50, (i * 70 - 10) + 45, 30); + } } + //метод прорисовки объеков public void DrawPlanes(Graphics g) { + int width = _pictureWidth / _placeSizeWidth; + int height = _pictureHeight / _placeSizeHeight; + + int position = 0; + int currentWidth = 1; + int currentHeight = 5; for (int i = 0; i < _setPlanes.Count; i++) { - //TODO установка позиции + _setPlanes.Get(i)?.SetObject(currentWidth * _placeSizeWidth + 20, currentHeight * _placeSizeHeight + 20, _pictureWidth, _pictureHeight); _setPlanes.Get(i)?.DrawningObject(g); + + if (position % 2 == 0) + { + position++; + currentWidth--; + } + else + { + position = 0; + currentWidth = 1; + currentHeight--; + } } } } diff --git a/Airbus/Airbus/SetPlanesGeneric.cs b/Airbus/Airbus/SetPlanesGeneric.cs index ef06526..81cfdc7 100644 --- a/Airbus/Airbus/SetPlanesGeneric.cs +++ b/Airbus/Airbus/SetPlanesGeneric.cs @@ -22,38 +22,82 @@ namespace Airbus } //добавление объекта в набор - public bool Insert(T plane) + public int Insert(T plane) { - //TODO вставка в начало набора - return true; + return Insert(plane, 0); } //добавление объекта в набор на конкретную позицию - public bool Insert(T plane, int position) + public int Insert(T plane, int position) { - //TODO проверка позиции - //TODO проверка, что элемент массива на этой позиции пустой, если нет, то - // проверка, что после вставляемого элемента в массиве есть пустой элемент - // сдвиг всех элементов, находящихся справа от позиции до первого пустого элемента - //TODO втсавка по позиции + // проверка позиции + if (position >= _places.Length || position < 0) + { + return -1; + } + //проверка, что элемент массива по этой позиции пустой, если нет, то + if (_places[position] == null) + { + _places[position] = plane; + return position; + } + + //проверка, что после вставляемого элемента в массиве есть пустой элемент + int findEmptyPos = -1; + + for (int i = position + 1; i < Count; i++) + { + if (_places[i] == null) + { + findEmptyPos = i; + break; + } + } + + if (findEmptyPos < 0) + { + return -1; + } + + //сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента + for (int i = findEmptyPos; i > position; i--) + { + _places[i] = _places[i - 1]; + } + + // вставка по позиции _places[position] = plane; - return true; + return position; } //удаление объекта из набора с конкретной позиции - public bool Remove(int position) + public T Remove(int position) { - //TODO проверка позиции - //TODO удаление объекта из массива, присвоив элементу массива значение null + // проверка позиции + if (position >= _places.Length || position < 0) + { + return null; + } - return true; + // удаление объекта из массива, присовив элементу массива значение null + T temp = _places[position]; + _places[position] = null; + + return temp; } //получение объекта из набора по позиции public T Get(int position) { - //TODO проверка позиции + if (position >= _places.Length || position < 0) + { + return null; + } + else if (_places[position] == null) + { + return null; + } return _places[position]; }