From 96b1b664a7b7ec8e773b1713acdc483e341a994f Mon Sep 17 00:00:00 2001 From: ArtemEmelyanov Date: Sun, 16 Oct 2022 12:44:39 +0400 Subject: [PATCH 1/6] generic classes --- Airbus/Airbus/MapWithSetPlanesGeneric.cs | 173 +++++++++++++++++++++++ Airbus/Airbus/SetPlanesGeneric.cs | 77 ++++++++++ 2 files changed, 250 insertions(+) create mode 100644 Airbus/Airbus/MapWithSetPlanesGeneric.cs create mode 100644 Airbus/Airbus/SetPlanesGeneric.cs diff --git a/Airbus/Airbus/MapWithSetPlanesGeneric.cs b/Airbus/Airbus/MapWithSetPlanesGeneric.cs new file mode 100644 index 0000000..2cbbb46 --- /dev/null +++ b/Airbus/Airbus/MapWithSetPlanesGeneric.cs @@ -0,0 +1,173 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Airbus +{ + internal class MapWithSetPlanesGeneric + where T : class, IDrawningObject + where U : AbstractMap + { + /// + /// Ширина окна отрисовки + /// + private readonly int _pictureWidth; + /// + /// Высота окна отрисовки + /// + private readonly int _pictureHeight; + /// + /// Размер занимаемого объектом места (ширина) + /// + private readonly int _placeSizeWidth = 210; + /// + /// Размер занимаемого объектом места (высота) + /// + private readonly int _placeSizeHeight = 90; + /// + /// Набор объектов + /// + private readonly SetPlanesGeneric _setPlanes; + /// + /// Карта + /// + private readonly U _map; + /// + /// Конструктор + /// + /// + /// + /// + public MapWithSetPlanesGeneric(int picWidth, int picHeight, U map) + { + int width = picWidth / _placeSizeWidth; + int height = picHeight / _placeSizeHeight; + _setPlanes = new SetPlanesGeneric(width * height); + _pictureWidth = picWidth; + _pictureHeight = picHeight; + _map = map; + } + /// + /// Перегрузка оператора сложения + /// + /// + /// + /// + public static bool operator +(MapWithSetPlanesGeneric map, T planes) + { + return map._setPlanes.Insert(planes); + } + /// + /// Перегрузка оператора вычитания + /// + /// + /// + /// + public static bool operator -(MapWithSetPlanesGeneric map, int position) + { + return map._setPlanes.Remove(position); + } + /// + /// Вывод всего набора объектов + /// + /// + public Bitmap ShowSet() + { + Bitmap bmp = new(_pictureWidth, _pictureHeight); + Graphics gr = Graphics.FromImage(bmp); + DrawBackground(gr); + DrawPlanes(gr); + return bmp; + } + /// + /// Просмотр объекта на карте + /// + /// + public Bitmap ShowOnMap() + { + Shaking(); + for (int i = 0; i < _setPlanes.Count; i++) + { + var plane = _setPlanes.Get(i); + if (plane != null) + { + return _map.CreateMap(_pictureWidth, _pictureHeight, plane); + } + } + 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 = _setPlanes.Count - 1; + for (int i = 0; i < _setPlanes.Count; i++) + { + if (_setPlanes.Get(i) == null) + { + for (; j > i; j--) + { + var plane = _setPlanes.Get(j); + if (plane != null) + { + _setPlanes.Insert(plane, i); + _setPlanes.Remove(j); + break; + } + } + if (j <= i) + { + return; + } + } + } + } + /// + /// Метод отрисовки фона + /// + /// + private void DrawBackground(Graphics g) + { + Pen pen = new(Color.Black, 3); + 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 DrawPlanes(Graphics g) + { + for (int i = 0; i < _setPlanes.Count; i++) + { + // TODO установка позиции + _setPlanes.Get(i)?.DrawningObject(g); + } + } + } + +} diff --git a/Airbus/Airbus/SetPlanesGeneric.cs b/Airbus/Airbus/SetPlanesGeneric.cs new file mode 100644 index 0000000..8e20371 --- /dev/null +++ b/Airbus/Airbus/SetPlanesGeneric.cs @@ -0,0 +1,77 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Airbus +{ + internal class SetPlanesGeneric + where T : class + { + /// + /// Массив объектов, которые храним + /// + private readonly T[] _places; + /// + /// Количество объектов в массиве + /// + public int Count => _places.Length; + /// + /// Конструктор + /// + /// + public SetPlanesGeneric(int count) + { + _places = new T[count]; + } + /// + /// Добавление объекта в набор + /// + /// Добавляемый автомобиль + /// + public bool Insert(T plane) + { + // TODO вставка в начало набора + return true; + } + /// + /// Добавление объекта в набор на конкретную позицию + /// + /// Добавляемый автомобиль + /// Позиция + /// + public bool Insert(T plane, int position) + { + // TODO проверка позиции + // TODO проверка, что элемент массива по этой позиции пустой, если нет, то + // проверка, что после вставляемого элемента в массиве есть пустой элемент + // сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента + // TODO вставка по позиции + _places[position] = plane; + return true; + } + /// + /// Удаление объекта из набора с конкретной позиции + /// + /// + /// + public bool Remove(int position) + { + // TODO проверка позиции + // TODO удаление объекта из массива, присовив элементу массива значение null + return true; + } + /// + /// Получение объекта из набора по позиции + /// + /// + /// + public T Get(int position) + { + // TODO проверка позиции + return _places[position]; + } + } + +} From 80f867986dbcf5394ec0df924bc950cfdc41df37 Mon Sep 17 00:00:00 2001 From: ArtemEmelyanov Date: Sun, 16 Oct 2022 13:14:33 +0400 Subject: [PATCH 2/6] changes forms --- Airbus/Airbus/Direction.cs | 2 +- Airbus/Airbus/DrawningPlane.cs | 2 +- Airbus/Airbus/EntityPlane.cs | 2 +- Airbus/Airbus/FormMap.Designer.cs | 216 ------------------ Airbus/Airbus/FormMap.cs | 114 --------- .../Airbus/FormMapWithSetPlanes.Designer.cs | 199 ++++++++++++++++ Airbus/Airbus/FormMapWithSetPlanes.cs | 161 +++++++++++++ ...FormMap.resx => FormMapWithSetPlanes.resx} | 3 - Airbus/Airbus/FormPlane.Designer.cs | 13 ++ Airbus/Airbus/FormPlane.cs | 8 + Airbus/Airbus/Program.cs | 2 +- 11 files changed, 385 insertions(+), 337 deletions(-) delete mode 100644 Airbus/Airbus/FormMap.Designer.cs delete mode 100644 Airbus/Airbus/FormMap.cs create mode 100644 Airbus/Airbus/FormMapWithSetPlanes.Designer.cs create mode 100644 Airbus/Airbus/FormMapWithSetPlanes.cs rename Airbus/Airbus/{FormMap.resx => FormMapWithSetPlanes.resx} (93%) diff --git a/Airbus/Airbus/Direction.cs b/Airbus/Airbus/Direction.cs index 63fb1f0..643938c 100644 --- a/Airbus/Airbus/Direction.cs +++ b/Airbus/Airbus/Direction.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace Airbus { - internal enum Direction + public enum Direction { None = 0, Up = 1, diff --git a/Airbus/Airbus/DrawningPlane.cs b/Airbus/Airbus/DrawningPlane.cs index f1d3c95..b981fe1 100644 --- a/Airbus/Airbus/DrawningPlane.cs +++ b/Airbus/Airbus/DrawningPlane.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace Airbus { - internal class DrawningPlane + public class DrawningPlane { /// /// Класс-сущность diff --git a/Airbus/Airbus/EntityPlane.cs b/Airbus/Airbus/EntityPlane.cs index ebe0d63..a86e8b2 100644 --- a/Airbus/Airbus/EntityPlane.cs +++ b/Airbus/Airbus/EntityPlane.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace Airbus { - internal class EntityPlane + public class EntityPlane { /// /// Скорость diff --git a/Airbus/Airbus/FormMap.Designer.cs b/Airbus/Airbus/FormMap.Designer.cs deleted file mode 100644 index c034a37..0000000 --- a/Airbus/Airbus/FormMap.Designer.cs +++ /dev/null @@ -1,216 +0,0 @@ -namespace Airbus -{ - 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.pictureBoxPlane = new System.Windows.Forms.PictureBox(); - this.statusStrip1 = new System.Windows.Forms.StatusStrip(); - this.toolStripStatusLabelSpeed = new System.Windows.Forms.ToolStripStatusLabel(); - this.toolStripStatusLabelWeight = new System.Windows.Forms.ToolStripStatusLabel(); - this.toolStripStatusLabelBodyColor = new System.Windows.Forms.ToolStripStatusLabel(); - this.buttonCreate = new System.Windows.Forms.Button(); - this.buttonRight = new System.Windows.Forms.Button(); - this.buttonLeft = new System.Windows.Forms.Button(); - this.buttonUp = new System.Windows.Forms.Button(); - this.buttonDown = new System.Windows.Forms.Button(); - this.buttonCreateModif = new System.Windows.Forms.Button(); - this.comboBoxSelector = new System.Windows.Forms.ComboBox(); - ((System.ComponentModel.ISupportInitialize)(this.pictureBoxPlane)).BeginInit(); - this.statusStrip1.SuspendLayout(); - this.SuspendLayout(); - // - // pictureBoxPlane - // - this.pictureBoxPlane.Dock = System.Windows.Forms.DockStyle.Fill; - this.pictureBoxPlane.Location = new System.Drawing.Point(0, 0); - this.pictureBoxPlane.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); - this.pictureBoxPlane.Name = "pictureBoxPlane"; - this.pictureBoxPlane.Size = new System.Drawing.Size(700, 338); - this.pictureBoxPlane.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; - this.pictureBoxPlane.TabIndex = 0; - this.pictureBoxPlane.TabStop = false; - // - // statusStrip1 - // - this.statusStrip1.ImageScalingSize = new System.Drawing.Size(20, 20); - this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.toolStripStatusLabelSpeed, - this.toolStripStatusLabelWeight, - this.toolStripStatusLabelBodyColor}); - this.statusStrip1.Location = new System.Drawing.Point(0, 316); - this.statusStrip1.Name = "statusStrip1"; - this.statusStrip1.Padding = new System.Windows.Forms.Padding(1, 0, 12, 0); - this.statusStrip1.Size = new System.Drawing.Size(700, 22); - this.statusStrip1.TabIndex = 1; - this.statusStrip1.Text = "statusStrip1"; - // - // toolStripStatusLabelSpeed - // - this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed"; - this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(59, 17); - this.toolStripStatusLabelSpeed.Text = "Скорость"; - // - // toolStripStatusLabelWeight - // - this.toolStripStatusLabelWeight.Name = "toolStripStatusLabelWeight"; - this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(26, 17); - this.toolStripStatusLabelWeight.Text = "Вес"; - // - // toolStripStatusLabelBodyColor - // - this.toolStripStatusLabelBodyColor.Name = "toolStripStatusLabelBodyColor"; - this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(33, 17); - this.toolStripStatusLabelBodyColor.Text = "Цвет"; - // - // 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(10, 286); - this.buttonCreate.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); - this.buttonCreate.Name = "buttonCreate"; - this.buttonCreate.Size = new System.Drawing.Size(82, 22); - this.buttonCreate.TabIndex = 2; - this.buttonCreate.Text = "Создать"; - this.buttonCreate.UseVisualStyleBackColor = true; - this.buttonCreate.Click += new System.EventHandler(this.ButtonCreate_Click); - // - // buttonRight - // - this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonRight.BackgroundImage = global::Airbus.Properties.Resources.arrowRight; - this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonRight.Location = new System.Drawing.Point(658, 286); - this.buttonRight.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); - this.buttonRight.Name = "buttonRight"; - this.buttonRight.Size = new System.Drawing.Size(26, 22); - this.buttonRight.TabIndex = 3; - 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::Airbus.Properties.Resources.arrowLeft; - this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonLeft.Location = new System.Drawing.Point(595, 286); - this.buttonLeft.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); - this.buttonLeft.Name = "buttonLeft"; - this.buttonLeft.Size = new System.Drawing.Size(26, 22); - this.buttonLeft.TabIndex = 4; - this.buttonLeft.UseVisualStyleBackColor = true; - this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click); - // - // buttonUp - // - this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonUp.BackgroundImage = global::Airbus.Properties.Resources.arrowUp; - this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonUp.Location = new System.Drawing.Point(626, 260); - this.buttonUp.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); - this.buttonUp.Name = "buttonUp"; - this.buttonUp.Size = new System.Drawing.Size(26, 22); - this.buttonUp.TabIndex = 5; - this.buttonUp.UseVisualStyleBackColor = true; - this.buttonUp.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::Airbus.Properties.Resources.arrowDown; - this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonDown.Location = new System.Drawing.Point(626, 286); - this.buttonDown.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); - this.buttonDown.Name = "buttonDown"; - this.buttonDown.Size = new System.Drawing.Size(26, 22); - this.buttonDown.TabIndex = 6; - this.buttonDown.UseVisualStyleBackColor = true; - this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click); - // - // buttonCreateModif - // - this.buttonCreateModif.Location = new System.Drawing.Point(98, 285); - this.buttonCreateModif.Name = "buttonCreateModif"; - this.buttonCreateModif.Size = new System.Drawing.Size(99, 23); - this.buttonCreateModif.TabIndex = 7; - this.buttonCreateModif.Text = "Модификация"; - this.buttonCreateModif.UseVisualStyleBackColor = true; - this.buttonCreateModif.Click += new System.EventHandler(this.buttonCreateModif_Click); - // - // comboBoxSelector - // - this.comboBoxSelector.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.comboBoxSelector.FormattingEnabled = true; - this.comboBoxSelector.Items.AddRange(new object[] { - "Простая карта", - "Вторая карта"}); - this.comboBoxSelector.Location = new System.Drawing.Point(8, 8); - this.comboBoxSelector.Name = "comboBoxSelector"; - this.comboBoxSelector.Size = new System.Drawing.Size(121, 23); - this.comboBoxSelector.TabIndex = 8; - this.comboBoxSelector.SelectedIndexChanged += new System.EventHandler(this.comboBoxSelector_SelectedIndexChanged); - // - // FormMap - // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(700, 338); - this.Controls.Add(this.comboBoxSelector); - this.Controls.Add(this.buttonCreateModif); - this.Controls.Add(this.buttonDown); - this.Controls.Add(this.buttonUp); - this.Controls.Add(this.buttonLeft); - this.Controls.Add(this.buttonRight); - this.Controls.Add(this.buttonCreate); - this.Controls.Add(this.statusStrip1); - this.Controls.Add(this.pictureBoxPlane); - this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); - this.Name = "FormMap"; - this.Text = "Карта"; - ((System.ComponentModel.ISupportInitialize)(this.pictureBoxPlane)).EndInit(); - this.statusStrip1.ResumeLayout(false); - this.statusStrip1.PerformLayout(); - this.ResumeLayout(false); - this.PerformLayout(); - - } - - #endregion - private PictureBox pictureBoxPlane; - private StatusStrip statusStrip1; - private ToolStripStatusLabel toolStripStatusLabelSpeed; - private ToolStripStatusLabel toolStripStatusLabelWeight; - private ToolStripStatusLabel toolStripStatusLabelBodyColor; - private Button buttonCreate; - private Button buttonRight; - private Button buttonLeft; - private Button buttonUp; - private Button buttonDown; - private Button buttonCreateModif; - private ComboBox comboBoxSelector; - } -} \ No newline at end of file diff --git a/Airbus/Airbus/FormMap.cs b/Airbus/Airbus/FormMap.cs deleted file mode 100644 index 52583e3..0000000 --- a/Airbus/Airbus/FormMap.cs +++ /dev/null @@ -1,114 +0,0 @@ -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 Airbus -{ - public partial class FormMap : Form - { - private AbstractMap _abstractMap; - public FormMap() - { - InitializeComponent(); - _abstractMap = new SimpleMap(); - } - /// - /// Заполнение информации по объекту - /// - /// - private void SetData(DrawningPlane plane) - { - toolStripStatusLabelSpeed.Text = $"Скорость: {plane.Plane.Speed}"; - toolStripStatusLabelWeight.Text = $"Вес: {plane.Plane.Weight}"; - toolStripStatusLabelBodyColor.Text = $"Цвет: {plane.Plane.BodyColor.Name}"; - pictureBoxPlane.Image = _abstractMap.CreateMap(pictureBoxPlane.Width, pictureBoxPlane.Height, new DrawningObjectPlane(plane)); - } - /// - /// Обработка нажатия кнопки "Создать" - /// - /// - /// - private void ButtonCreate_Click(object sender, EventArgs e) - { - Random rnd = new(); - var plane = new DrawningPlane(rnd.Next(100, 300), rnd.Next(1000, 2000), - Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); - SetData(plane); - } - /// - /// Изменение размеров формы - /// - /// - /// - 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; - } - pictureBoxPlane.Image = _abstractMap?.MoveObject(dir); - } - /// - /// Обработка нажатия кнопки "Модификация" - /// - /// - /// - private void buttonCreateModif_Click(object sender, EventArgs e) - { - Random rnd = new(); - var plane = 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.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, - 256)), - Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, - 2)), Convert.ToBoolean(rnd.Next(0, 2))); - SetData(plane); - } - /// - /// Смена карты - /// - /// - /// - private void comboBoxSelector_SelectedIndexChanged(object sender, EventArgs e) - { - switch (comboBoxSelector.Text) - { - case "Простая карта": - _abstractMap = new SimpleMap(); - break; - case "Вторая карта": - _abstractMap = new MyMap(); - break; - } - } - - - - } - - - -} - diff --git a/Airbus/Airbus/FormMapWithSetPlanes.Designer.cs b/Airbus/Airbus/FormMapWithSetPlanes.Designer.cs new file mode 100644 index 0000000..df42df7 --- /dev/null +++ b/Airbus/Airbus/FormMapWithSetPlanes.Designer.cs @@ -0,0 +1,199 @@ +namespace Airbus +{ + partial class FormMapWithSetPlanes + { + /// + /// 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.groupBox1 = new System.Windows.Forms.GroupBox(); + this.pictureBox = new System.Windows.Forms.PictureBox(); + this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox(); + this.buttonAddPlane = new System.Windows.Forms.Button(); + this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox(); + this.buttonRemovePlane = new System.Windows.Forms.Button(); + this.buttonShowStorage = new System.Windows.Forms.Button(); + this.buttonShowOnMap = new System.Windows.Forms.Button(); + this.buttonUp = new System.Windows.Forms.Button(); + this.buttonDown = new System.Windows.Forms.Button(); + this.buttonRight = new System.Windows.Forms.Button(); + this.buttonLeft = new System.Windows.Forms.Button(); + this.groupBox1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit(); + this.SuspendLayout(); + // + // groupBox1 + // + this.groupBox1.Controls.Add(this.buttonLeft); + this.groupBox1.Controls.Add(this.buttonRight); + this.groupBox1.Controls.Add(this.buttonDown); + this.groupBox1.Controls.Add(this.buttonUp); + this.groupBox1.Controls.Add(this.buttonShowOnMap); + this.groupBox1.Controls.Add(this.buttonShowStorage); + this.groupBox1.Controls.Add(this.buttonRemovePlane); + this.groupBox1.Controls.Add(this.maskedTextBoxPosition); + this.groupBox1.Controls.Add(this.buttonAddPlane); + this.groupBox1.Controls.Add(this.comboBoxSelectorMap); + this.groupBox1.Dock = System.Windows.Forms.DockStyle.Right; + this.groupBox1.Location = new System.Drawing.Point(600, 0); + this.groupBox1.Name = "groupBox1"; + this.groupBox1.Size = new System.Drawing.Size(200, 450); + this.groupBox1.TabIndex = 0; + this.groupBox1.TabStop = false; + this.groupBox1.Text = "Инструменты"; + // + // pictureBox1 + // + this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill; + this.pictureBox.Location = new System.Drawing.Point(0, 0); + this.pictureBox.Name = "pictureBox1"; + this.pictureBox.Size = new System.Drawing.Size(600, 450); + this.pictureBox.TabIndex = 0; + this.pictureBox.TabStop = false; + // + // comboBoxSelectorMap + // + this.comboBoxSelectorMap.FormattingEnabled = true; + this.comboBoxSelectorMap.Location = new System.Drawing.Point(17, 22); + this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; + this.comboBoxSelectorMap.Size = new System.Drawing.Size(171, 23); + this.comboBoxSelectorMap.TabIndex = 0; + // + // buttonAddPlane + // + this.buttonAddPlane.Location = new System.Drawing.Point(17, 64); + this.buttonAddPlane.Name = "buttonAddPlane"; + this.buttonAddPlane.Size = new System.Drawing.Size(171, 31); + this.buttonAddPlane.TabIndex = 1; + this.buttonAddPlane.Text = "Добавить самолёт"; + this.buttonAddPlane.UseVisualStyleBackColor = true; + // + // maskedTextBoxPosition + // + this.maskedTextBoxPosition.Location = new System.Drawing.Point(17, 126); + this.maskedTextBoxPosition.Mask = "00"; + this.maskedTextBoxPosition.Name = "maskedTextBoxPosition"; + this.maskedTextBoxPosition.Size = new System.Drawing.Size(171, 23); + this.maskedTextBoxPosition.TabIndex = 2; + // + // buttonRemovePlane + // + this.buttonRemovePlane.Location = new System.Drawing.Point(17, 169); + this.buttonRemovePlane.Name = "buttonRemovePlane"; + this.buttonRemovePlane.Size = new System.Drawing.Size(171, 31); + this.buttonRemovePlane.TabIndex = 3; + this.buttonRemovePlane.Text = "Удалить самолёт"; + this.buttonRemovePlane.UseVisualStyleBackColor = true; + // + // buttonShowStorage + // + this.buttonShowStorage.Location = new System.Drawing.Point(17, 259); + this.buttonShowStorage.Name = "buttonShowStorage"; + this.buttonShowStorage.Size = new System.Drawing.Size(171, 34); + this.buttonShowStorage.TabIndex = 4; + this.buttonShowStorage.Text = "Посмотреть хранилище"; + this.buttonShowStorage.UseVisualStyleBackColor = true; + // + // buttonShowOnMap + // + this.buttonShowOnMap.Location = new System.Drawing.Point(17, 308); + this.buttonShowOnMap.Name = "buttonShowOnMap"; + this.buttonShowOnMap.Size = new System.Drawing.Size(171, 31); + this.buttonShowOnMap.TabIndex = 5; + this.buttonShowOnMap.Text = "Посмотреть карту"; + this.buttonShowOnMap.UseVisualStyleBackColor = true; + // + // buttonUp + // + this.buttonUp.BackgroundImage = global::Airbus.Properties.Resources.arrowUp; + this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonUp.Location = new System.Drawing.Point(92, 370); + this.buttonUp.Name = "buttonUp"; + this.buttonUp.Size = new System.Drawing.Size(30, 30); + this.buttonUp.TabIndex = 6; + this.buttonUp.UseVisualStyleBackColor = true; + // + // buttonDown + // + this.buttonDown.BackgroundImage = global::Airbus.Properties.Resources.arrowDown; + this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonDown.Location = new System.Drawing.Point(92, 406); + this.buttonDown.Name = "buttonDown"; + this.buttonDown.Size = new System.Drawing.Size(30, 30); + this.buttonDown.TabIndex = 7; + this.buttonDown.UseVisualStyleBackColor = true; + // + // buttonRight + // + this.buttonRight.BackgroundImage = global::Airbus.Properties.Resources.arrowRight; + this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonRight.Location = new System.Drawing.Point(128, 406); + this.buttonRight.Name = "buttonRight"; + this.buttonRight.Size = new System.Drawing.Size(30, 30); + this.buttonRight.TabIndex = 8; + this.buttonRight.UseVisualStyleBackColor = true; + // + // buttonLeft + // + this.buttonLeft.BackgroundImage = global::Airbus.Properties.Resources.arrowLeft; + this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonLeft.Location = new System.Drawing.Point(56, 406); + this.buttonLeft.Name = "buttonLeft"; + this.buttonLeft.Size = new System.Drawing.Size(30, 30); + this.buttonLeft.TabIndex = 9; + this.buttonLeft.UseVisualStyleBackColor = true; + // + // FormMapWithSetPlanes + // + 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.pictureBox); + this.Controls.Add(this.groupBox1); + this.Name = "FormMapWithSetPlanes"; + this.Text = "FormMapWithSetPlanes"; + this.groupBox1.ResumeLayout(false); + this.groupBox1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private GroupBox groupBox1; + private Button buttonLeft; + private Button buttonRight; + private Button buttonDown; + private Button buttonUp; + private Button buttonShowOnMap; + private Button buttonShowStorage; + private Button buttonRemovePlane; + private MaskedTextBox maskedTextBoxPosition; + private Button buttonAddPlane; + private ComboBox comboBoxSelectorMap; + private PictureBox pictureBox; + } +} \ No newline at end of file diff --git a/Airbus/Airbus/FormMapWithSetPlanes.cs b/Airbus/Airbus/FormMapWithSetPlanes.cs new file mode 100644 index 0000000..41d291f --- /dev/null +++ b/Airbus/Airbus/FormMapWithSetPlanes.cs @@ -0,0 +1,161 @@ +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; +using static System.Windows.Forms.DataFormats; + +namespace Airbus +{ + public partial class FormMapWithSetPlanes : Form + { + /// + /// Объект от класса карты с набором объектов + /// + private MapWithSetPlanesGeneric _mapPlanesCollectionGeneric; + /// + /// Конструктор + /// + public FormMapWithSetPlanes() + { + InitializeComponent(); + } + /// + /// Выбор карты + /// + /// + /// + private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e) + { + AbstractMap map = null; + switch (comboBoxSelectorMap.Text) + { + case "Простая карта": + map = new SimpleMap(); + break; + } + if (map != null) + { + _mapPlanesCollectionGeneric = new + MapWithSetPlanesGeneric(pictureBox.Width, pictureBox.Height, map); + } + else + { + _mapPlanesCollectionGeneric = null; + } + } + /// + /// Добавление объекта + /// + /// + /// + private void ButtonAddPlane_Click(object sender, EventArgs e) + { + if (_mapPlanesCollectionGeneric == null) + { + return; + } + FormPlane form = new(); + if (form.ShowDialog() == DialogResult.OK) + { + DrawningObjectPlane plane = new(form.SelectedPlane); + if (_mapPlanesCollectionGeneric + plane) + { + MessageBox.Show("Объект добавлен"); + pictureBox.Image = _mapPlanesCollectionGeneric.ShowSet(); + } + else + { + MessageBox.Show("Не удалось добавить объект"); + } + } + } + /// + /// Удаление объекта + /// + /// + /// + private void ButtonRemovePlane_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(maskedTextBoxPosition.Text)) + { + return; + } + if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) + { + return; + } + int pos = Convert.ToInt32(maskedTextBoxPosition.Text); + if (_mapPlanesCollectionGeneric - pos) + { + MessageBox.Show("Объект удален"); + pictureBox.Image = _mapPlanesCollectionGeneric.ShowSet(); + } + else + { + MessageBox.Show("Не удалось удалить объект"); + } + } + /// + /// Вывод набора + /// + /// + /// + private void ButtonShowStorage_Click(object sender, EventArgs e) + { + if (_mapPlanesCollectionGeneric == null) + { + return; + } + pictureBox.Image = _mapPlanesCollectionGeneric.ShowSet(); + } + /// + /// Вывод карты + /// + /// + /// + private void ButtonShowOnMap_Click(object sender, EventArgs e) + { + if (_mapPlanesCollectionGeneric == null) + { + return; + } + pictureBox.Image = _mapPlanesCollectionGeneric.ShowOnMap(); + } + /// + /// Перемещение + /// + /// + /// + private void ButtonMove_Click(object sender, EventArgs e) + { + if (_mapPlanesCollectionGeneric == null) + { + return; + } + //получаем имя кнопки + 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; + } + pictureBox.Image = _mapPlanesCollectionGeneric.MoveObject(dir); + } + } +} diff --git a/Airbus/Airbus/FormMap.resx b/Airbus/Airbus/FormMapWithSetPlanes.resx similarity index 93% rename from Airbus/Airbus/FormMap.resx rename to Airbus/Airbus/FormMapWithSetPlanes.resx index 5cb320f..f298a7b 100644 --- a/Airbus/Airbus/FormMap.resx +++ b/Airbus/Airbus/FormMapWithSetPlanes.resx @@ -57,7 +57,4 @@ 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/Airbus/Airbus/FormPlane.Designer.cs b/Airbus/Airbus/FormPlane.Designer.cs index 693b54d..67a511d 100644 --- a/Airbus/Airbus/FormPlane.Designer.cs +++ b/Airbus/Airbus/FormPlane.Designer.cs @@ -39,6 +39,7 @@ this.buttonUp = new System.Windows.Forms.Button(); this.buttonDown = new System.Windows.Forms.Button(); this.buttonCreateModif = new System.Windows.Forms.Button(); + this.buttonSelectPlane = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxAirbus)).BeginInit(); this.statusStrip1.SuspendLayout(); this.SuspendLayout(); @@ -160,11 +161,22 @@ this.buttonCreateModif.UseVisualStyleBackColor = true; this.buttonCreateModif.Click += new System.EventHandler(this.buttonCreateModif_Click); // + // buttonSelectPlane + // + this.buttonSelectPlane.Location = new System.Drawing.Point(514, 285); + this.buttonSelectPlane.Name = "buttonSelectPlane"; + this.buttonSelectPlane.Size = new System.Drawing.Size(75, 23); + this.buttonSelectPlane.TabIndex = 8; + this.buttonSelectPlane.Text = "Выбрать"; + this.buttonSelectPlane.UseVisualStyleBackColor = true; + this.buttonSelectPlane.Click += new System.EventHandler(this.buttonSelectPlane_Click); + // // FormPlane // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(700, 338); + this.Controls.Add(this.buttonSelectPlane); this.Controls.Add(this.buttonCreateModif); this.Controls.Add(this.buttonDown); this.Controls.Add(this.buttonUp); @@ -197,5 +209,6 @@ private Button buttonUp; private Button buttonDown; private Button buttonCreateModif; + private Button buttonSelectPlane; } } \ No newline at end of file diff --git a/Airbus/Airbus/FormPlane.cs b/Airbus/Airbus/FormPlane.cs index a2aa505..e9a8dd0 100644 --- a/Airbus/Airbus/FormPlane.cs +++ b/Airbus/Airbus/FormPlane.cs @@ -14,6 +14,8 @@ namespace Airbus { private DrawningPlane _plane; + public DrawningPlane SelectedPlane { get; private set; } + public FormPlane() { InitializeComponent(); @@ -93,6 +95,12 @@ namespace Airbus SetData(); Draw(); } + + private void buttonSelectPlane_Click(object sender, EventArgs e) + { + SelectedPlane = _plane; + DialogResult = DialogResult.OK; + } } } diff --git a/Airbus/Airbus/Program.cs b/Airbus/Airbus/Program.cs index 3c7e1fb..5166800 100644 --- a/Airbus/Airbus/Program.cs +++ b/Airbus/Airbus/Program.cs @@ -11,7 +11,7 @@ namespace Airbus // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormMap()); + Application.Run(new FormMapWithSetPlanes()); } } } \ No newline at end of file From 6c938430b017283d523a312eb304b62261d48d2c Mon Sep 17 00:00:00 2001 From: ArtemEmelyanov Date: Sun, 16 Oct 2022 13:34:08 +0400 Subject: [PATCH 3/6] =?UTF-8?q?=D0=94=D0=BE=D0=BF=D0=BE=D0=BB=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D0=BD=D0=B0=D1=8F=20=D1=84=D0=BE=D1=80=D0=BC=D0=B0=20For?= =?UTF-8?q?mPlane?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Airbus/Airbus/FormPlane.cs | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/Airbus/Airbus/FormPlane.cs b/Airbus/Airbus/FormPlane.cs index e9a8dd0..85716c6 100644 --- a/Airbus/Airbus/FormPlane.cs +++ b/Airbus/Airbus/FormPlane.cs @@ -47,7 +47,14 @@ namespace Airbus private void ButtonCreate_Click(object sender, EventArgs e) { Random rnd = new(); - _plane = new DrawningPlane(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; + } + _plane = new DrawningPlane(rnd.Next(100, 300), rnd.Next(1000, 2000),color); SetData(); Draw(); } @@ -91,7 +98,19 @@ namespace Airbus private void buttonCreateModif_Click(object sender, EventArgs e) { Random rnd = new(); - _plane = 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.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2))); + 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 dopColor = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)); + ColorDialog dialogDop = new(); + if (dialogDop.ShowDialog() == DialogResult.OK) + { + dopColor = dialogDop.Color; + } + _plane = new DrawningAirbus(rnd.Next(100, 300), rnd.Next(1000, 2000), color, dopColor, Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2))); SetData(); Draw(); } From 9a7af194feb54bb830d2b44a24d3ac1c5cd74b60 Mon Sep 17 00:00:00 2001 From: ArtemEmelyanov Date: Sun, 16 Oct 2022 19:48:03 +0400 Subject: [PATCH 4/6] =?UTF-8?q?=D0=92=D1=80=D0=BE=D0=B4=D0=B5=20=D0=BA?= =?UTF-8?q?=D0=B0=D0=BA=20=D0=B4=D0=BE=D0=B4=D0=B5=D0=BB=D0=B0=D0=BD=D0=BD?= =?UTF-8?q?=D0=B0=D1=8F=20=D0=BB=D0=B0=D0=B1=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Airbus/FormMapWithSetPlanes.Designer.cs | 241 ++++++++++-------- Airbus/Airbus/FormMapWithSetPlanes.cs | 20 +- Airbus/Airbus/MapWithSetPlanesGeneric.cs | 13 +- Airbus/Airbus/SetPlanesGeneric.cs | 53 +++- 4 files changed, 201 insertions(+), 126 deletions(-) diff --git a/Airbus/Airbus/FormMapWithSetPlanes.Designer.cs b/Airbus/Airbus/FormMapWithSetPlanes.Designer.cs index df42df7..159ed8c 100644 --- a/Airbus/Airbus/FormMapWithSetPlanes.Designer.cs +++ b/Airbus/Airbus/FormMapWithSetPlanes.Designer.cs @@ -29,17 +29,17 @@ private void InitializeComponent() { this.groupBox1 = new System.Windows.Forms.GroupBox(); - this.pictureBox = new System.Windows.Forms.PictureBox(); - this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox(); - this.buttonAddPlane = new System.Windows.Forms.Button(); - this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox(); - this.buttonRemovePlane = new System.Windows.Forms.Button(); - this.buttonShowStorage = new System.Windows.Forms.Button(); - this.buttonShowOnMap = new System.Windows.Forms.Button(); - this.buttonUp = new System.Windows.Forms.Button(); - this.buttonDown = new System.Windows.Forms.Button(); - this.buttonRight = new System.Windows.Forms.Button(); this.buttonLeft = new System.Windows.Forms.Button(); + this.buttonRight = new System.Windows.Forms.Button(); + this.buttonDown = new System.Windows.Forms.Button(); + this.buttonUp = new System.Windows.Forms.Button(); + this.buttonShowOnMap = new System.Windows.Forms.Button(); + this.buttonShowStorage = new System.Windows.Forms.Button(); + this.buttonRemovePlane = new System.Windows.Forms.Button(); + this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox(); + this.buttonAddPlane = new System.Windows.Forms.Button(); + this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox(); + this.pictureBox = new System.Windows.Forms.PictureBox(); this.groupBox1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit(); this.SuspendLayout(); @@ -57,123 +57,150 @@ this.groupBox1.Controls.Add(this.buttonAddPlane); this.groupBox1.Controls.Add(this.comboBoxSelectorMap); this.groupBox1.Dock = System.Windows.Forms.DockStyle.Right; - this.groupBox1.Location = new System.Drawing.Point(600, 0); + this.groupBox1.Location = new System.Drawing.Point(685, 0); + this.groupBox1.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.groupBox1.Name = "groupBox1"; - this.groupBox1.Size = new System.Drawing.Size(200, 450); + this.groupBox1.Padding = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.groupBox1.Size = new System.Drawing.Size(229, 600); this.groupBox1.TabIndex = 0; this.groupBox1.TabStop = false; this.groupBox1.Text = "Инструменты"; // - // pictureBox1 - // - this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill; - this.pictureBox.Location = new System.Drawing.Point(0, 0); - this.pictureBox.Name = "pictureBox1"; - this.pictureBox.Size = new System.Drawing.Size(600, 450); - this.pictureBox.TabIndex = 0; - this.pictureBox.TabStop = false; - // - // comboBoxSelectorMap - // - this.comboBoxSelectorMap.FormattingEnabled = true; - this.comboBoxSelectorMap.Location = new System.Drawing.Point(17, 22); - this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; - this.comboBoxSelectorMap.Size = new System.Drawing.Size(171, 23); - this.comboBoxSelectorMap.TabIndex = 0; - // - // buttonAddPlane - // - this.buttonAddPlane.Location = new System.Drawing.Point(17, 64); - this.buttonAddPlane.Name = "buttonAddPlane"; - this.buttonAddPlane.Size = new System.Drawing.Size(171, 31); - this.buttonAddPlane.TabIndex = 1; - this.buttonAddPlane.Text = "Добавить самолёт"; - this.buttonAddPlane.UseVisualStyleBackColor = true; - // - // maskedTextBoxPosition - // - this.maskedTextBoxPosition.Location = new System.Drawing.Point(17, 126); - this.maskedTextBoxPosition.Mask = "00"; - this.maskedTextBoxPosition.Name = "maskedTextBoxPosition"; - this.maskedTextBoxPosition.Size = new System.Drawing.Size(171, 23); - this.maskedTextBoxPosition.TabIndex = 2; - // - // buttonRemovePlane - // - this.buttonRemovePlane.Location = new System.Drawing.Point(17, 169); - this.buttonRemovePlane.Name = "buttonRemovePlane"; - this.buttonRemovePlane.Size = new System.Drawing.Size(171, 31); - this.buttonRemovePlane.TabIndex = 3; - this.buttonRemovePlane.Text = "Удалить самолёт"; - this.buttonRemovePlane.UseVisualStyleBackColor = true; - // - // buttonShowStorage - // - this.buttonShowStorage.Location = new System.Drawing.Point(17, 259); - this.buttonShowStorage.Name = "buttonShowStorage"; - this.buttonShowStorage.Size = new System.Drawing.Size(171, 34); - this.buttonShowStorage.TabIndex = 4; - this.buttonShowStorage.Text = "Посмотреть хранилище"; - this.buttonShowStorage.UseVisualStyleBackColor = true; - // - // buttonShowOnMap - // - this.buttonShowOnMap.Location = new System.Drawing.Point(17, 308); - this.buttonShowOnMap.Name = "buttonShowOnMap"; - this.buttonShowOnMap.Size = new System.Drawing.Size(171, 31); - this.buttonShowOnMap.TabIndex = 5; - this.buttonShowOnMap.Text = "Посмотреть карту"; - this.buttonShowOnMap.UseVisualStyleBackColor = true; - // - // buttonUp - // - this.buttonUp.BackgroundImage = global::Airbus.Properties.Resources.arrowUp; - this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonUp.Location = new System.Drawing.Point(92, 370); - this.buttonUp.Name = "buttonUp"; - this.buttonUp.Size = new System.Drawing.Size(30, 30); - this.buttonUp.TabIndex = 6; - this.buttonUp.UseVisualStyleBackColor = true; - // - // buttonDown - // - this.buttonDown.BackgroundImage = global::Airbus.Properties.Resources.arrowDown; - this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonDown.Location = new System.Drawing.Point(92, 406); - this.buttonDown.Name = "buttonDown"; - this.buttonDown.Size = new System.Drawing.Size(30, 30); - this.buttonDown.TabIndex = 7; - this.buttonDown.UseVisualStyleBackColor = true; - // - // buttonRight - // - this.buttonRight.BackgroundImage = global::Airbus.Properties.Resources.arrowRight; - this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonRight.Location = new System.Drawing.Point(128, 406); - this.buttonRight.Name = "buttonRight"; - this.buttonRight.Size = new System.Drawing.Size(30, 30); - this.buttonRight.TabIndex = 8; - this.buttonRight.UseVisualStyleBackColor = true; - // // buttonLeft // this.buttonLeft.BackgroundImage = global::Airbus.Properties.Resources.arrowLeft; this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonLeft.Location = new System.Drawing.Point(56, 406); + this.buttonLeft.Location = new System.Drawing.Point(64, 541); + this.buttonLeft.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.buttonLeft.Name = "buttonLeft"; - this.buttonLeft.Size = new System.Drawing.Size(30, 30); + this.buttonLeft.Size = new System.Drawing.Size(34, 40); this.buttonLeft.TabIndex = 9; this.buttonLeft.UseVisualStyleBackColor = true; + this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click); + // + // buttonRight + // + this.buttonRight.BackgroundImage = global::Airbus.Properties.Resources.arrowRight; + this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonRight.Location = new System.Drawing.Point(146, 541); + 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); + this.buttonRight.TabIndex = 8; + this.buttonRight.UseVisualStyleBackColor = true; + this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click); + // + // buttonDown + // + this.buttonDown.BackgroundImage = global::Airbus.Properties.Resources.arrowDown; + this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonDown.Location = new System.Drawing.Point(105, 541); + 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); + this.buttonDown.TabIndex = 7; + this.buttonDown.UseVisualStyleBackColor = true; + this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click); + // + // buttonUp + // + this.buttonUp.BackgroundImage = global::Airbus.Properties.Resources.arrowUp; + this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; + this.buttonUp.Location = new System.Drawing.Point(105, 493); + 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); + this.buttonUp.TabIndex = 6; + this.buttonUp.UseVisualStyleBackColor = true; + this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click); + // + // buttonShowOnMap + // + this.buttonShowOnMap.Location = new System.Drawing.Point(19, 411); + this.buttonShowOnMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.buttonShowOnMap.Name = "buttonShowOnMap"; + this.buttonShowOnMap.Size = new System.Drawing.Size(195, 41); + this.buttonShowOnMap.TabIndex = 5; + this.buttonShowOnMap.Text = "Посмотреть карту"; + this.buttonShowOnMap.UseVisualStyleBackColor = true; + this.buttonShowOnMap.Click += new System.EventHandler(this.buttonShowOnMap_Click_1); + // + // buttonShowStorage + // + this.buttonShowStorage.Location = new System.Drawing.Point(19, 345); + this.buttonShowStorage.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.buttonShowStorage.Name = "buttonShowStorage"; + this.buttonShowStorage.Size = new System.Drawing.Size(195, 45); + this.buttonShowStorage.TabIndex = 4; + this.buttonShowStorage.Text = "Посмотреть хранилище"; + this.buttonShowStorage.UseVisualStyleBackColor = true; + this.buttonShowStorage.Click += new System.EventHandler(this.buttonShowStorage_Click_1); + // + // buttonRemovePlane + // + this.buttonRemovePlane.Location = new System.Drawing.Point(19, 225); + this.buttonRemovePlane.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.buttonRemovePlane.Name = "buttonRemovePlane"; + this.buttonRemovePlane.Size = new System.Drawing.Size(195, 41); + this.buttonRemovePlane.TabIndex = 3; + this.buttonRemovePlane.Text = "Удалить самолёт"; + this.buttonRemovePlane.UseVisualStyleBackColor = true; + this.buttonRemovePlane.Click += new System.EventHandler(this.buttonRemovePlane_Click_1); + // + // maskedTextBoxPosition + // + this.maskedTextBoxPosition.Location = new System.Drawing.Point(19, 168); + this.maskedTextBoxPosition.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.maskedTextBoxPosition.Mask = "00"; + this.maskedTextBoxPosition.Name = "maskedTextBoxPosition"; + this.maskedTextBoxPosition.Size = new System.Drawing.Size(195, 27); + this.maskedTextBoxPosition.TabIndex = 2; + // + // buttonAddPlane + // + this.buttonAddPlane.Location = new System.Drawing.Point(19, 85); + this.buttonAddPlane.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.buttonAddPlane.Name = "buttonAddPlane"; + this.buttonAddPlane.Size = new System.Drawing.Size(195, 41); + this.buttonAddPlane.TabIndex = 1; + this.buttonAddPlane.Text = "Добавить самолёт"; + this.buttonAddPlane.UseVisualStyleBackColor = true; + this.buttonAddPlane.Click += new System.EventHandler(this.buttonAddPlane_Click_1); + // + // comboBoxSelectorMap + // + this.comboBoxSelectorMap.FormattingEnabled = true; + this.comboBoxSelectorMap.Items.AddRange(new object[] { + "Простая карта", + "Вторая карта"}); + this.comboBoxSelectorMap.Location = new System.Drawing.Point(19, 29); + this.comboBoxSelectorMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; + this.comboBoxSelectorMap.Size = new System.Drawing.Size(195, 28); + this.comboBoxSelectorMap.TabIndex = 0; + this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.comboBoxSelectorMap_SelectedIndexChanged_1); + // + // pictureBox + // + this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill; + this.pictureBox.Location = new System.Drawing.Point(0, 0); + this.pictureBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.pictureBox.Name = "pictureBox"; + this.pictureBox.Size = new System.Drawing.Size(685, 600); + this.pictureBox.TabIndex = 0; + this.pictureBox.TabStop = false; // // FormMapWithSetPlanes // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); + this.ClientSize = new System.Drawing.Size(914, 600); this.Controls.Add(this.pictureBox); this.Controls.Add(this.groupBox1); + this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.Name = "FormMapWithSetPlanes"; this.Text = "FormMapWithSetPlanes"; + this.Click += new System.EventHandler(this.ButtonMove_Click); this.groupBox1.ResumeLayout(false); this.groupBox1.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit(); diff --git a/Airbus/Airbus/FormMapWithSetPlanes.cs b/Airbus/Airbus/FormMapWithSetPlanes.cs index 41d291f..818fc0a 100644 --- a/Airbus/Airbus/FormMapWithSetPlanes.cs +++ b/Airbus/Airbus/FormMapWithSetPlanes.cs @@ -29,7 +29,7 @@ namespace Airbus /// /// /// - private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e) + private void comboBoxSelectorMap_SelectedIndexChanged_1(object sender, EventArgs e) { AbstractMap map = null; switch (comboBoxSelectorMap.Text) @@ -37,6 +37,10 @@ namespace Airbus case "Простая карта": map = new SimpleMap(); break; + case "Вторая карта": + map = new MyMap(); + break; + } if (map != null) { @@ -53,7 +57,7 @@ namespace Airbus /// /// /// - private void ButtonAddPlane_Click(object sender, EventArgs e) + private void buttonAddPlane_Click_1(object sender, EventArgs e) { if (_mapPlanesCollectionGeneric == null) { @@ -63,7 +67,7 @@ namespace Airbus if (form.ShowDialog() == DialogResult.OK) { DrawningObjectPlane plane = new(form.SelectedPlane); - if (_mapPlanesCollectionGeneric + plane) + if (_mapPlanesCollectionGeneric + plane != -1) { MessageBox.Show("Объект добавлен"); pictureBox.Image = _mapPlanesCollectionGeneric.ShowSet(); @@ -79,7 +83,7 @@ namespace Airbus /// /// /// - private void ButtonRemovePlane_Click(object sender, EventArgs e) + private void buttonRemovePlane_Click_1(object sender, EventArgs e) { if (string.IsNullOrEmpty(maskedTextBoxPosition.Text)) { @@ -90,7 +94,7 @@ namespace Airbus return; } int pos = Convert.ToInt32(maskedTextBoxPosition.Text); - if (_mapPlanesCollectionGeneric - pos) + if (_mapPlanesCollectionGeneric - pos != -1) { MessageBox.Show("Объект удален"); pictureBox.Image = _mapPlanesCollectionGeneric.ShowSet(); @@ -105,7 +109,7 @@ namespace Airbus /// /// /// - private void ButtonShowStorage_Click(object sender, EventArgs e) + private void buttonShowStorage_Click_1(object sender, EventArgs e) { if (_mapPlanesCollectionGeneric == null) { @@ -118,7 +122,7 @@ namespace Airbus /// /// /// - private void ButtonShowOnMap_Click(object sender, EventArgs e) + private void buttonShowOnMap_Click_1(object sender, EventArgs e) { if (_mapPlanesCollectionGeneric == null) { @@ -157,5 +161,7 @@ namespace Airbus } pictureBox.Image = _mapPlanesCollectionGeneric.MoveObject(dir); } + + } } diff --git a/Airbus/Airbus/MapWithSetPlanesGeneric.cs b/Airbus/Airbus/MapWithSetPlanesGeneric.cs index 2cbbb46..d2005bd 100644 --- a/Airbus/Airbus/MapWithSetPlanesGeneric.cs +++ b/Airbus/Airbus/MapWithSetPlanesGeneric.cs @@ -55,7 +55,7 @@ namespace Airbus /// /// /// - public static bool operator +(MapWithSetPlanesGeneric map, T planes) + public static int operator +(MapWithSetPlanesGeneric map, T planes) { return map._setPlanes.Insert(planes); } @@ -65,7 +65,7 @@ namespace Airbus /// /// /// - public static bool operator -(MapWithSetPlanesGeneric map, int position) + public static int operator -(MapWithSetPlanesGeneric map, int position) { return map._setPlanes.Remove(position); } @@ -162,10 +162,17 @@ namespace Airbus /// private void DrawPlanes(Graphics g) { + int width = _pictureWidth / _placeSizeWidth; + int height = _pictureHeight / _placeSizeHeight; + for (int i = 0; i < _setPlanes.Count; i++) { // TODO установка позиции - _setPlanes.Get(i)?.DrawningObject(g); + if(_setPlanes.Get(i) != null) + { + _setPlanes.Get(i).SetObject(i % width * _placeSizeWidth, (height - 1 - i / width) * _placeSizeHeight, _pictureWidth, _pictureHeight); + _setPlanes.Get(i)?.DrawningObject(g); + } } } } diff --git a/Airbus/Airbus/SetPlanesGeneric.cs b/Airbus/Airbus/SetPlanesGeneric.cs index 8e20371..549f6bc 100644 --- a/Airbus/Airbus/SetPlanesGeneric.cs +++ b/Airbus/Airbus/SetPlanesGeneric.cs @@ -28,39 +28,70 @@ 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 вставка по позиции - _places[position] = plane; - return true; + + if(_places[position] == null) + { + _places[position] = plane; + return position; + } + else + { + bool isFree = false; + for (int i = 0; i < Count; i++) + { + if (_places[i] == null) + { + isFree = true; + } + } + if (isFree) + { + for (var i = _places.Length - 1; i != 0; --i) _places[i] = _places[i - 1]; + _places[position] = plane; + } + else + { + return -1; + } + } + return 0; } /// /// Удаление объекта из набора с конкретной позиции /// /// /// - public bool Remove(int position) + public int Remove(int position) { // TODO проверка позиции // TODO удаление объекта из массива, присовив элементу массива значение null - return true; + if(position < 0 || position >= Count || _places[position] == null) + { + return -1; + } + _places[position] = null; + return 0; } /// /// Получение объекта из набора по позиции @@ -70,6 +101,10 @@ namespace Airbus public T Get(int position) { // TODO проверка позиции + if (position < 0 || position >= Count) + { + return null; + } return _places[position]; } } From 2d38dcf373856e81581479339e8888ce49dc542f Mon Sep 17 00:00:00 2001 From: ArtemEmelyanov Date: Tue, 18 Oct 2022 16:51:12 +0400 Subject: [PATCH 5/6] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=B4=D0=B5=D0=BB?= =?UTF-8?q?=D0=B0=D0=BD=D1=8B=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=D1=8B,=20?= =?UTF-8?q?=D0=B3=D0=BE=D1=82=D0=BE=D0=B2=D0=B0=D1=8F=20=D0=BB=D0=B0=D0=B1?= =?UTF-8?q?=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Airbus/Airbus/FormMapWithSetPlanes.cs | 4 ++-- Airbus/Airbus/MapWithSetPlanesGeneric.cs | 4 ++-- Airbus/Airbus/SetPlanesGeneric.cs | 27 ++++++++++++++---------- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/Airbus/Airbus/FormMapWithSetPlanes.cs b/Airbus/Airbus/FormMapWithSetPlanes.cs index 818fc0a..d3cca69 100644 --- a/Airbus/Airbus/FormMapWithSetPlanes.cs +++ b/Airbus/Airbus/FormMapWithSetPlanes.cs @@ -67,7 +67,7 @@ namespace Airbus if (form.ShowDialog() == DialogResult.OK) { DrawningObjectPlane plane = new(form.SelectedPlane); - if (_mapPlanesCollectionGeneric + plane != -1) + if (_mapPlanesCollectionGeneric + plane) { MessageBox.Show("Объект добавлен"); pictureBox.Image = _mapPlanesCollectionGeneric.ShowSet(); @@ -94,7 +94,7 @@ namespace Airbus return; } int pos = Convert.ToInt32(maskedTextBoxPosition.Text); - if (_mapPlanesCollectionGeneric - pos != -1) + if (_mapPlanesCollectionGeneric - pos) { MessageBox.Show("Объект удален"); pictureBox.Image = _mapPlanesCollectionGeneric.ShowSet(); diff --git a/Airbus/Airbus/MapWithSetPlanesGeneric.cs b/Airbus/Airbus/MapWithSetPlanesGeneric.cs index d2005bd..5a758bf 100644 --- a/Airbus/Airbus/MapWithSetPlanesGeneric.cs +++ b/Airbus/Airbus/MapWithSetPlanesGeneric.cs @@ -55,7 +55,7 @@ namespace Airbus /// /// /// - public static int operator +(MapWithSetPlanesGeneric map, T planes) + public static bool operator +(MapWithSetPlanesGeneric map, T planes) { return map._setPlanes.Insert(planes); } @@ -65,7 +65,7 @@ namespace Airbus /// /// /// - public static int operator -(MapWithSetPlanesGeneric map, int position) + public static bool operator -(MapWithSetPlanesGeneric map, int position) { return map._setPlanes.Remove(position); } diff --git a/Airbus/Airbus/SetPlanesGeneric.cs b/Airbus/Airbus/SetPlanesGeneric.cs index 549f6bc..5e965b9 100644 --- a/Airbus/Airbus/SetPlanesGeneric.cs +++ b/Airbus/Airbus/SetPlanesGeneric.cs @@ -30,7 +30,7 @@ namespace Airbus /// /// Добавляемый самолёт /// - public int Insert(T plane) + public bool Insert(T plane) { // TODO вставка в начало набора return Insert(plane, 0); @@ -42,7 +42,7 @@ namespace Airbus /// Добавляемый самолёт /// Позиция /// - public int Insert(T plane, int position) + public bool Insert(T plane, int position) { // TODO проверка позиции // TODO проверка, что элемент массива по этой позиции пустой, если нет, то @@ -53,45 +53,50 @@ namespace Airbus if(_places[position] == null) { _places[position] = plane; - return position; } else { + int pos = -1; bool isFree = false; for (int i = 0; i < Count; i++) { if (_places[i] == null) { isFree = true; + pos = i; + break; } } if (isFree) { - for (var i = _places.Length - 1; i != 0; --i) _places[i] = _places[i - 1]; + for (var i = pos; i > position; --i) _places[i] = _places[i - 1]; _places[position] = plane; } else { - return -1; + return false; } } - return 0; + return true; } /// /// Удаление объекта из набора с конкретной позиции /// /// /// - public int Remove(int position) + public bool Remove(int position) { // TODO проверка позиции // TODO удаление объекта из массива, присовив элементу массива значение null - if(position < 0 || position >= Count || _places[position] == null) + if (position < 0 || position >= Count || _places[position] == null) { - return -1; + return false; + } + else + { + _places[position] = null; + return true; } - _places[position] = null; - return 0; } /// /// Получение объекта из набора по позиции From 378ba86d6c04c83253b2680f8693bd994dc8d277 Mon Sep 17 00:00:00 2001 From: ArtemEmelyanov Date: Wed, 19 Oct 2022 10:00:42 +0400 Subject: [PATCH 6/6] =?UTF-8?q?=D0=A1=D0=B4=D0=B0=D0=BD=D0=BD=D0=B0=D1=8F?= =?UTF-8?q?=20=D0=BB=D0=B0=D0=B1=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Airbus/Airbus/FormMapWithSetPlanes.cs | 4 ++-- Airbus/Airbus/MapWithSetPlanesGeneric.cs | 25 +++++++++++++++++++++--- Airbus/Airbus/SetPlanesGeneric.cs | 24 ++++++++++------------- 3 files changed, 34 insertions(+), 19 deletions(-) diff --git a/Airbus/Airbus/FormMapWithSetPlanes.cs b/Airbus/Airbus/FormMapWithSetPlanes.cs index d3cca69..d750449 100644 --- a/Airbus/Airbus/FormMapWithSetPlanes.cs +++ b/Airbus/Airbus/FormMapWithSetPlanes.cs @@ -67,7 +67,7 @@ namespace Airbus if (form.ShowDialog() == DialogResult.OK) { DrawningObjectPlane plane = new(form.SelectedPlane); - if (_mapPlanesCollectionGeneric + plane) + if (_mapPlanesCollectionGeneric + plane != -1) { MessageBox.Show("Объект добавлен"); pictureBox.Image = _mapPlanesCollectionGeneric.ShowSet(); @@ -94,7 +94,7 @@ namespace Airbus return; } int pos = Convert.ToInt32(maskedTextBoxPosition.Text); - if (_mapPlanesCollectionGeneric - pos) + if (_mapPlanesCollectionGeneric - pos != null) { MessageBox.Show("Объект удален"); pictureBox.Image = _mapPlanesCollectionGeneric.ShowSet(); diff --git a/Airbus/Airbus/MapWithSetPlanesGeneric.cs b/Airbus/Airbus/MapWithSetPlanesGeneric.cs index 5a758bf..6b7dd53 100644 --- a/Airbus/Airbus/MapWithSetPlanesGeneric.cs +++ b/Airbus/Airbus/MapWithSetPlanesGeneric.cs @@ -55,7 +55,7 @@ namespace Airbus /// /// /// - public static bool operator +(MapWithSetPlanesGeneric map, T planes) + public static int operator +(MapWithSetPlanesGeneric map, T planes) { return map._setPlanes.Insert(planes); } @@ -65,7 +65,7 @@ namespace Airbus /// /// /// - public static bool operator -(MapWithSetPlanesGeneric map, int position) + public static T operator -(MapWithSetPlanesGeneric map, int position) { return map._setPlanes.Remove(position); } @@ -144,6 +144,23 @@ namespace Airbus /// private void DrawBackground(Graphics g) { + Brush road = new SolidBrush(Color.Gray); + g.FillRectangle(road, 0, 0, _pictureWidth, _pictureHeight); + Brush lines = new SolidBrush(Color.White); + for (int y = 0; y < _pictureHeight; y+=80) + { + g.FillRectangle(lines, _pictureWidth / 2 - 10, y, 20, 70); + } + int lastLine = 0; + for (int y = 50; y < _pictureHeight; y += _pictureHeight/3 - 50) + { + g.FillRectangle(lines, _pictureWidth / 3 - 10, y, 20, 70); + g.FillRectangle(lines, _pictureWidth - _pictureWidth / 3 - 10, y, 20, 70); + lastLine = y; + } + g.FillRectangle(lines, _pictureWidth / 3 - 40, lastLine, 20, 70); + g.FillRectangle(lines, _pictureWidth - _pictureWidth / 3 + 20, lastLine, 20, 70); + Pen pen = new(Color.Black, 3); for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++) { @@ -155,6 +172,8 @@ namespace Airbus g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, (_pictureHeight / _placeSizeHeight) * _placeSizeHeight); } + + } /// /// Метод прорисовки объектов @@ -170,7 +189,7 @@ namespace Airbus // TODO установка позиции if(_setPlanes.Get(i) != null) { - _setPlanes.Get(i).SetObject(i % width * _placeSizeWidth, (height - 1 - i / width) * _placeSizeHeight, _pictureWidth, _pictureHeight); + _setPlanes.Get(i).SetObject((width - i % width - 1) * _placeSizeWidth,(height - i / width - 1) * _placeSizeHeight, _pictureWidth, _pictureHeight); _setPlanes.Get(i)?.DrawningObject(g); } } diff --git a/Airbus/Airbus/SetPlanesGeneric.cs b/Airbus/Airbus/SetPlanesGeneric.cs index 5e965b9..a7f7d3d 100644 --- a/Airbus/Airbus/SetPlanesGeneric.cs +++ b/Airbus/Airbus/SetPlanesGeneric.cs @@ -30,7 +30,7 @@ namespace Airbus /// /// Добавляемый самолёт /// - public bool Insert(T plane) + public int Insert(T plane) { // TODO вставка в начало набора return Insert(plane, 0); @@ -42,7 +42,7 @@ namespace Airbus /// Добавляемый самолёт /// Позиция /// - public bool Insert(T plane, int position) + public int Insert(T plane, int position) { // TODO проверка позиции // TODO проверка, что элемент массива по этой позиции пустой, если нет, то @@ -53,6 +53,7 @@ namespace Airbus if(_places[position] == null) { _places[position] = plane; + return position; } else { @@ -71,32 +72,27 @@ namespace Airbus { for (var i = pos; i > position; --i) _places[i] = _places[i - 1]; _places[position] = plane; + return position; } else { - return false; + return -1; } } - return true; } /// /// Удаление объекта из набора с конкретной позиции /// /// /// - public bool Remove(int position) + public T Remove(int position) { // TODO проверка позиции // TODO удаление объекта из массива, присовив элементу массива значение null - if (position < 0 || position >= Count || _places[position] == null) - { - return false; - } - else - { - _places[position] = null; - return true; - } + if (position < 0 || position >= Count || _places[position] == null) return null; + T DeletePlane = _places[position]; + _places[position] = null; + return DeletePlane; } /// /// Получение объекта из набора по позиции