From 9c244adfba3896433a2bb83c4064c239be724eef Mon Sep 17 00:00:00 2001 From: alhimek17 Date: Sun, 24 Mar 2024 17:42:31 +0400 Subject: [PATCH 1/3] =?UTF-8?q?=D0=9A=D0=BE=D0=BC=D0=BF=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbstractCompany.cs | 100 ++++++++++ .../ICollectionGenericObjects.cs | 49 +++++ .../MassiveGenericObjects.cs | 86 +++++++++ .../PlaneSharigService.cs | 21 +++ .../ProjectAirPlane/FormAirPlane.Designer.cs | 28 --- .../ProjectAirPlane/FormAirPlane.cs | 48 +---- .../FormPlaneCollection.Designer.cs | 177 ++++++++++++++++++ .../ProjectAirPlane/FormPlaneCollection.cs | 175 +++++++++++++++++ .../ProjectAirPlane/FormPlaneCollection.resx | 120 ++++++++++++ ProjectAirPlane/ProjectAirPlane/Program.cs | 2 +- 10 files changed, 731 insertions(+), 75 deletions(-) create mode 100644 ProjectAirPlane/ProjectAirPlane/CollectionGenericObjects/AbstractCompany.cs create mode 100644 ProjectAirPlane/ProjectAirPlane/CollectionGenericObjects/ICollectionGenericObjects.cs create mode 100644 ProjectAirPlane/ProjectAirPlane/CollectionGenericObjects/MassiveGenericObjects.cs create mode 100644 ProjectAirPlane/ProjectAirPlane/CollectionGenericObjects/PlaneSharigService.cs create mode 100644 ProjectAirPlane/ProjectAirPlane/FormPlaneCollection.Designer.cs create mode 100644 ProjectAirPlane/ProjectAirPlane/FormPlaneCollection.cs create mode 100644 ProjectAirPlane/ProjectAirPlane/FormPlaneCollection.resx diff --git a/ProjectAirPlane/ProjectAirPlane/CollectionGenericObjects/AbstractCompany.cs b/ProjectAirPlane/ProjectAirPlane/CollectionGenericObjects/AbstractCompany.cs new file mode 100644 index 0000000..3a34be8 --- /dev/null +++ b/ProjectAirPlane/ProjectAirPlane/CollectionGenericObjects/AbstractCompany.cs @@ -0,0 +1,100 @@ +using ProjectAirPlane.Drawnings; + +namespace ProjectAirPlane.CollectionGenericObjects; + +public abstract class AbstractCompany +{ + /// + /// Размер места (ширина) + /// + protected readonly int _placeSizeWidth = 210; + /// + /// Размер места (высота) + /// + protected readonly int _placeSizeHeight = 80; + /// + /// Ширина окна + /// + protected readonly int _pictureWidth; + /// + /// Высота окна + /// + protected readonly int _pictureHeight; + /// + /// Коллекция судов + /// + protected ICollectionGenericObjects? _collection = null; + /// + /// Вычисление максимального количества элементов, который можно разместить в окне + /// + private int GetMaxCount => _pictureWidth * _pictureHeight / (_placeSizeWidth * _placeSizeHeight); + /// + /// Конструктор + /// + /// Ширина окна + /// Высота окна + /// Коллекция автомобилей + public AbstractCompany(int picWidth, int picHeight, ICollectionGenericObjects collection) + { + _pictureWidth = picWidth; + _pictureHeight = picHeight; + _collection = collection; + _collection.SetMaxCount = GetMaxCount; + } + /// + /// Перегрузка оператора сложения для класса + /// + /// Компания + /// Добавляемый объект + /// + public static int operator +(AbstractCompany company, DrawningPlane plane) + { + return company._collection.Insert(plane); + } + /// + /// Перегрузка оператора удаления для класса + /// + /// Компания + /// Номер удаляемого объекта + /// + public static DrawningPlane operator -(AbstractCompany company, int position) + { + return company._collection?.Remove(position); + } + /// + /// Получение случайного объекта из коллекции + /// + /// + public DrawningPlane? GetRandomObject() + { + Random rnd = new(); + return _collection?.Get(rnd.Next(GetMaxCount)); + } + /// + /// Вывод всей коллекции + /// + /// + public Bitmap? Show() + { + Bitmap bitmap = new(_pictureWidth, _pictureHeight); + Graphics graphics = Graphics.FromImage(bitmap); + DrawBackgound(graphics); + SetObjectsPosition(); + for (int i = 0; i < (_collection?.Count ?? 0); ++i) + { + DrawningPlane? obj = _collection?.Get(i); + obj?.DrawTransport(graphics); + } + return bitmap; + } + /// + /// Вывод заднего фона + /// + /// + protected abstract void DrawBackgound(Graphics g); + /// + /// Расстановка объектов + /// + protected abstract void SetObjectsPosition(); +} + diff --git a/ProjectAirPlane/ProjectAirPlane/CollectionGenericObjects/ICollectionGenericObjects.cs b/ProjectAirPlane/ProjectAirPlane/CollectionGenericObjects/ICollectionGenericObjects.cs new file mode 100644 index 0000000..dc51cd5 --- /dev/null +++ b/ProjectAirPlane/ProjectAirPlane/CollectionGenericObjects/ICollectionGenericObjects.cs @@ -0,0 +1,49 @@ +namespace ProjectAirPlane.CollectionGenericObjects; + +/// +/// Интерфейс описания действий для набора хранимых объектов +/// +/// Параметр: ограничение - ссылочный тип +public interface ICollectionGenericObjects + where T : class +{ + /// + /// Количество объектов в коллекции + /// + int Count { get; } + + /// + /// Установка максимального количества элементов + /// + int SetMaxCount { set; } + + /// + /// Добавление объекта в коллекцию + /// + /// Добавляемый объект + /// true - вставка прошла удачно, false - вставка не удалась + int Insert(T obj); + + /// + /// Добавление объекта в коллекцию на конкретную позицию + /// + /// Добавляемый объект + /// Позиция + /// true - вставка прошла удачно, false - вставка не удалась + int Insert(T obj, int position); + + /// + /// Удаление объекта из коллекции с конкретной позиции + /// + /// Позиция + /// true - удаление прошло удачно, false - удаление не удалось + T Remove(int position); + + /// + /// Получение объекта по позиции + /// + /// Позиция + /// Объект + T? Get(int position); +} + diff --git a/ProjectAirPlane/ProjectAirPlane/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectAirPlane/ProjectAirPlane/CollectionGenericObjects/MassiveGenericObjects.cs new file mode 100644 index 0000000..0820610 --- /dev/null +++ b/ProjectAirPlane/ProjectAirPlane/CollectionGenericObjects/MassiveGenericObjects.cs @@ -0,0 +1,86 @@ +namespace ProjectAirPlane.CollectionGenericObjects; + +public class MassiveGenericObjects : ICollectionGenericObjects + where T : class +{ + /// + /// Массив объектов, которые храним + /// + private T?[] _collection; + public int Count => _collection.Length; + public int SetMaxCount { set { if (value > 0) { _collection = new T?[value]; } } } + /// + /// Конструктор + /// + public MassiveGenericObjects() + { + _collection = Array.Empty(); + } + public T? Get(int position) + { + // TODO проверка позиции + if (position >= _collection.Length || position < 0) return null; + return _collection[position]; + } + public int Insert(T obj) + { + // TODO вставка в свободное место набора + int index = 0; + while (index < _collection.Length) + { + if (_collection[index] == null) + { + _collection[index] = obj; + return index; + } + ++index; + } + return -1; + } + public int Insert(T obj, int position) + { + // TODO проверка позиции + // TODO проверка, что элемент массива по этой позиции пустой, если нет, то + // ищется свободное место после этой позиции и идет вставка туда + // если нет после, ищем до + // TODO вставка + if (position >= _collection.Length || position < 0) + return -1; + if (_collection[position] == null) + { + _collection[position] = obj; + return position; + } + int index = position + 1; + while (index < _collection.Length) + { + if (_collection[index] == null) + { + _collection[index] = obj; + return index; + } + ++index; + } + index = position - 1; + while (index >= 0) + { + if (_collection[index] == null) + { + _collection[index] = obj; + return index; + } + --index; + } + return -1; + } + public T Remove(int position) + { + // TODO проверка позиции + // TODO удаление объекта из массива, присвоив элементу массива значение null + if (position >= _collection.Length || position < 0) + return null; + T obj = _collection[position]; + _collection[position] = null; + return obj; + } +} \ No newline at end of file diff --git a/ProjectAirPlane/ProjectAirPlane/CollectionGenericObjects/PlaneSharigService.cs b/ProjectAirPlane/ProjectAirPlane/CollectionGenericObjects/PlaneSharigService.cs new file mode 100644 index 0000000..b0e0b8b --- /dev/null +++ b/ProjectAirPlane/ProjectAirPlane/CollectionGenericObjects/PlaneSharigService.cs @@ -0,0 +1,21 @@ + +using ProjectAirPlane.Drawnings; + +namespace ProjectAirPlane.CollectionGenericObjects; + +public class PlaneSharigService : AbstractCompany +{ + public PlaneSharigService(int picWidth, int picHeight, ICollectionGenericObjects collection) : base(picWidth, picHeight, collection) + { + } + + protected override void DrawBackgound(Graphics g) + { + throw new NotImplementedException(); + } + + protected override void SetObjectsPosition() + { + throw new NotImplementedException(); + } +} diff --git a/ProjectAirPlane/ProjectAirPlane/FormAirPlane.Designer.cs b/ProjectAirPlane/ProjectAirPlane/FormAirPlane.Designer.cs index aecfeea..42ee3eb 100644 --- a/ProjectAirPlane/ProjectAirPlane/FormAirPlane.Designer.cs +++ b/ProjectAirPlane/ProjectAirPlane/FormAirPlane.Designer.cs @@ -30,12 +30,10 @@ { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormAirPlane)); pictureBoxAirPlane = new PictureBox(); - buttonCreateAirPlane = new Button(); buttonLeft = new Button(); buttonUp = new Button(); buttonDown = new Button(); buttonRight = new Button(); - ButtonCreatePlane = new Button(); comboBoxStrategy = new ComboBox(); buttonStrategyStepS = new Button(); ((System.ComponentModel.ISupportInitialize)pictureBoxAirPlane).BeginInit(); @@ -50,17 +48,6 @@ pictureBoxAirPlane.TabIndex = 0; pictureBoxAirPlane.TabStop = false; // - // buttonCreateAirPlane - // - buttonCreateAirPlane.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonCreateAirPlane.Location = new Point(12, 488); - buttonCreateAirPlane.Name = "buttonCreateAirPlane"; - buttonCreateAirPlane.Size = new Size(180, 23); - buttonCreateAirPlane.TabIndex = 1; - buttonCreateAirPlane.Text = "Создать самолёт с радаром"; - buttonCreateAirPlane.UseVisualStyleBackColor = true; - buttonCreateAirPlane.Click += ButtonCreateAirPlane_Click; - // // buttonLeft // buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; @@ -109,17 +96,6 @@ buttonRight.UseVisualStyleBackColor = true; buttonRight.Click += ButtonMove_Click; // - // ButtonCreatePlane - // - ButtonCreatePlane.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - ButtonCreatePlane.Location = new Point(198, 488); - ButtonCreatePlane.Name = "ButtonCreatePlane"; - ButtonCreatePlane.Size = new Size(180, 23); - ButtonCreatePlane.TabIndex = 6; - ButtonCreatePlane.Text = "Создать самолёт"; - ButtonCreatePlane.UseVisualStyleBackColor = true; - ButtonCreatePlane.Click += ButtonCreatePlane_Click; - // // comboBoxStrategy // comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList; @@ -147,12 +123,10 @@ ClientSize = new Size(749, 523); Controls.Add(buttonStrategyStepS); Controls.Add(comboBoxStrategy); - Controls.Add(ButtonCreatePlane); Controls.Add(buttonRight); Controls.Add(buttonDown); Controls.Add(buttonUp); Controls.Add(buttonLeft); - Controls.Add(buttonCreateAirPlane); Controls.Add(pictureBoxAirPlane); Name = "FormAirPlane"; Text = "Спортивный автомобиль"; @@ -163,12 +137,10 @@ #endregion private PictureBox pictureBoxAirPlane; - private Button buttonCreateAirPlane; private Button buttonLeft; private Button buttonUp; private Button buttonDown; private Button buttonRight; - private Button ButtonCreatePlane; private ComboBox comboBoxStrategy; private Button buttonStrategyStepS; } diff --git a/ProjectAirPlane/ProjectAirPlane/FormAirPlane.cs b/ProjectAirPlane/ProjectAirPlane/FormAirPlane.cs index 355bcff..bad1e30 100644 --- a/ProjectAirPlane/ProjectAirPlane/FormAirPlane.cs +++ b/ProjectAirPlane/ProjectAirPlane/FormAirPlane.cs @@ -19,6 +19,8 @@ public partial class FormAirPlane : Form /// private AbstractStrategy? _strategy; + public DrawningPlane SetPlane { get; internal set; } + /// /// /// @@ -44,52 +46,6 @@ public partial class FormAirPlane : Form pictureBoxAirPlane.Image = bmp; } - /// - /// - - /// - /// - private void CreateObject(string type) - { - Random random = new(); - switch (type) - { - case nameof(DrawningPlane): - _drawningPlane = new DrawningPlane(random.Next(100, 300), random.Next(1000, 3000), - Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256))); - break; - case nameof(DrawningAirPlane): - _drawningPlane = new DrawningAirPlane(random.Next(100, 300), random.Next(1000, 3000), - Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), - Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), - Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2))); - break; - default: - return; - } - - _drawningPlane.SetPictureSize(pictureBoxAirPlane.Width, pictureBoxAirPlane.Height); - _drawningPlane.SetPosition(random.Next(10, 100), random.Next(10, 100)); - _strategy = null; - comboBoxStrategy.Enabled = true; - Draw(); - } - - /// - /// " " - /// - /// - /// - private void ButtonCreateAirPlane_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningAirPlane)); - - /// - /// " " - /// - /// - /// - private void ButtonCreatePlane_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningPlane)); - - - /// /// ( ) /// diff --git a/ProjectAirPlane/ProjectAirPlane/FormPlaneCollection.Designer.cs b/ProjectAirPlane/ProjectAirPlane/FormPlaneCollection.Designer.cs new file mode 100644 index 0000000..947f70f --- /dev/null +++ b/ProjectAirPlane/ProjectAirPlane/FormPlaneCollection.Designer.cs @@ -0,0 +1,177 @@ +namespace ProjectAirPlane +{ + partial class FormPlaneCollection + { + /// + /// 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() + { + groupBoxTools = new GroupBox(); + buttonRefresh = new Button(); + buttonGoToCheck = new Button(); + buttonRemovePlane = new Button(); + maskedTextBox = new MaskedTextBox(); + buttonAddAirPlane = new Button(); + buttonAddPlane = new Button(); + comboBoxSelectionCompany = new ComboBox(); + pictureBox = new PictureBox(); + groupBoxTools.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit(); + SuspendLayout(); + // + // groupBoxTools + // + groupBoxTools.Controls.Add(buttonRefresh); + groupBoxTools.Controls.Add(buttonGoToCheck); + groupBoxTools.Controls.Add(buttonRemovePlane); + groupBoxTools.Controls.Add(maskedTextBox); + groupBoxTools.Controls.Add(buttonAddAirPlane); + groupBoxTools.Controls.Add(buttonAddPlane); + groupBoxTools.Controls.Add(comboBoxSelectionCompany); + groupBoxTools.Dock = DockStyle.Right; + groupBoxTools.Location = new Point(726, 0); + groupBoxTools.Name = "groupBoxTools"; + groupBoxTools.Size = new Size(205, 557); + groupBoxTools.TabIndex = 0; + groupBoxTools.TabStop = false; + groupBoxTools.Text = "Инструменты"; + // + // buttonRefresh + // + buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonRefresh.Location = new Point(6, 484); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(186, 50); + buttonRefresh.TabIndex = 6; + buttonRefresh.Text = "Обновить"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += buttonRefresh_Click; + // + // buttonGoToCheck + // + buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonGoToCheck.Location = new Point(6, 397); + buttonGoToCheck.Name = "buttonGoToCheck"; + buttonGoToCheck.Size = new Size(186, 50); + buttonGoToCheck.TabIndex = 5; + buttonGoToCheck.Text = "Передать на тесты"; + buttonGoToCheck.UseVisualStyleBackColor = true; + buttonGoToCheck.Click += ButtonGoToCheck_Click; + // + // buttonRemovePlane + // + buttonRemovePlane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonRemovePlane.Location = new Point(6, 310); + buttonRemovePlane.Name = "buttonRemovePlane"; + buttonRemovePlane.Size = new Size(186, 50); + buttonRemovePlane.TabIndex = 4; + buttonRemovePlane.Text = "Удалить самолёта"; + buttonRemovePlane.UseVisualStyleBackColor = true; + buttonRemovePlane.Click += ButtonRemovePlane_Click; + // + // maskedTextBox + // + maskedTextBox.Location = new Point(6, 281); + maskedTextBox.Mask = "00"; + maskedTextBox.Name = "maskedTextBox"; + maskedTextBox.Size = new Size(186, 23); + maskedTextBox.TabIndex = 3; + maskedTextBox.ValidatingType = typeof(int); + // + // buttonAddAirPlane + // + buttonAddAirPlane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonAddAirPlane.Location = new Point(6, 143); + buttonAddAirPlane.Name = "buttonAddAirPlane"; + buttonAddAirPlane.Size = new Size(186, 50); + buttonAddAirPlane.TabIndex = 2; + buttonAddAirPlane.Text = "Добавление самолёта с радаром"; + buttonAddAirPlane.UseVisualStyleBackColor = true; + buttonAddAirPlane.Click += ButtonAddAirPlane_Click; + // + // buttonAddPlane + // + buttonAddPlane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonAddPlane.Location = new Point(6, 87); + buttonAddPlane.Name = "buttonAddPlane"; + buttonAddPlane.Size = new Size(186, 50); + buttonAddPlane.TabIndex = 1; + buttonAddPlane.Text = "Добавление самолёта"; + buttonAddPlane.UseVisualStyleBackColor = true; + buttonAddPlane.Click += ButtonAddPlane_Click; + // + // comboBoxSelectionCompany + // + comboBoxSelectionCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + comboBoxSelectionCompany.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxSelectionCompany.FormattingEnabled = true; + comboBoxSelectionCompany.Items.AddRange(new object[] { "Хранилище" }); + comboBoxSelectionCompany.Location = new Point(6, 22); + comboBoxSelectionCompany.Name = "comboBoxSelectionCompany"; + comboBoxSelectionCompany.Size = new Size(186, 23); + comboBoxSelectionCompany.TabIndex = 0; + // + // pictureBox + // + pictureBox.Dock = DockStyle.Fill; + pictureBox.Location = new Point(0, 0); + pictureBox.Name = "pictureBox"; + pictureBox.Size = new Size(726, 557); + pictureBox.TabIndex = 1; + pictureBox.TabStop = false; + // + // FormPlaneCollection + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(931, 557); + Controls.Add(pictureBox); + Controls.Add(groupBoxTools); + Name = "FormPlaneCollection"; + Text = "Коллекция самолётов"; + groupBoxTools.ResumeLayout(false); + groupBoxTools.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); + ResumeLayout(false); + } + + private void ButtonAddPlane_Click1(object sender, EventArgs e) + { + throw new NotImplementedException(); + } + + #endregion + + private GroupBox groupBoxTools; + private ComboBox comboBoxSelectionCompany; + private Button buttonAddPlane; + private Button buttonAddAirPlane; + private PictureBox pictureBox; + private Button buttonRemovePlane; + private MaskedTextBox maskedTextBox; + private Button buttonGoToCheck; + private Button buttonRefresh; + } +} \ No newline at end of file diff --git a/ProjectAirPlane/ProjectAirPlane/FormPlaneCollection.cs b/ProjectAirPlane/ProjectAirPlane/FormPlaneCollection.cs new file mode 100644 index 0000000..f59deee --- /dev/null +++ b/ProjectAirPlane/ProjectAirPlane/FormPlaneCollection.cs @@ -0,0 +1,175 @@ +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 ProjectAirPlane.CollectionGenericObjects; +using ProjectAirPlane.Drawnings; + +namespace ProjectAirPlane; + +/// +/// Форма работы с компанией и ее коллекцией +/// +public partial class FormPlaneCollection : Form +{ + /// + /// Компания + /// + private AbstractCompany? _company = null; + + /// + /// Конструктор + /// + public FormPlaneCollection() + { + InitializeComponent(); + } + + /// + /// Выбор компании + /// + /// + /// + private void ComboBoxSelectionCompany_SelectedIndexChanged(object sender, EventArgs e) + { + switch (comboBoxSelectionCompany.Text) + { + case "Хранилище": + _company = new PlaneSharigService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects()); + break; + } + } + + /// + /// Создание объекта класса-перемещения + /// + /// Тип создаваемого объекта + private void CreateObject(string type) + { + DrawningPlane drawningPlane; + if (_company == null) + { + return; + } + + Random random = new(); + switch (type) + { + case nameof(DrawningPlane): + drawningPlane = new DrawningPlane(random.Next(100, 300), random.Next(1000, 3000), GetColor(random)); + break; + case nameof(DrawningAirPlane): + drawningPlane = new DrawningAirPlane(random.Next(100, 300), random.Next(1000, 3000), + Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), + Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), + Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2))); + break; + default: + return; + } + + if (_company + drawningPlane != -1) + { + MessageBox.Show("Объект добавлен"); + pictureBox.Image = _company.Show(); + } + else + { + MessageBox.Show("Не удалось добавить объект"); + } + } + /// + /// Получение цвета + /// + /// Генератор случайных чисел + /// + private static Color GetColor(Random random) + { + Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)); + ColorDialog dialog = new(); + if (dialog.ShowDialog() == DialogResult.OK) + { + color = dialog.Color; + } + return color; + } + + private void ButtonAddPlane_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningPlane)); + + + private void ButtonAddAirPlane_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningAirPlane)); + + /// + /// Удаление объекта + /// + /// + /// + private void ButtonRemovePlane_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == null) + { + return; + } + if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) + { + return; + } + int pos = Convert.ToInt32(maskedTextBox.Text); + if (_company - pos != null) + { + MessageBox.Show("Объект удален"); + pictureBox.Image = _company.Show(); + } + else + { + MessageBox.Show("Не удалось удалить объект"); + } + } + + /// + /// Передача объекта в другую форму + /// + /// + /// + private void ButtonGoToCheck_Click(object sender, EventArgs e) + { + if (_company == null) + { + return; + } + DrawningPlane? plane = null; + int counter = 100; + while (plane == null) + { + plane = _company.GetRandomObject(); + counter--; + if (counter <= 0) + { + break; + } + } + if (plane == null) + { + return; + } + FormAirPlane form = new() + { + SetPlane = plane + }; + form.ShowDialog(); + } + + private void buttonRefresh_Click(object sender, EventArgs e) + { + if (_company == null) + { + return; + } + pictureBox.Image = _company.Show(); + } +} diff --git a/ProjectAirPlane/ProjectAirPlane/FormPlaneCollection.resx b/ProjectAirPlane/ProjectAirPlane/FormPlaneCollection.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectAirPlane/ProjectAirPlane/FormPlaneCollection.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ProjectAirPlane/ProjectAirPlane/Program.cs b/ProjectAirPlane/ProjectAirPlane/Program.cs index 37a9525..bd0c956 100644 --- a/ProjectAirPlane/ProjectAirPlane/Program.cs +++ b/ProjectAirPlane/ProjectAirPlane/Program.cs @@ -11,7 +11,7 @@ namespace ProjectAirPlane // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormAirPlane()); + Application.Run(new FormPlaneCollection()); } } } \ No newline at end of file -- 2.25.1 From 2bec551f18ae59012cae4d6535600a34a1f7eb57 Mon Sep 17 00:00:00 2001 From: alhimek17 Date: Sun, 24 Mar 2024 19:22:18 +0400 Subject: [PATCH 2/3] =?UTF-8?q?=D0=9F=D1=80=D0=B0=D0=BA=D1=82=D0=B8=D1=87?= =?UTF-8?q?=D0=B5=D1=81=D0=BA=D0=B8=20=D0=B4=D0=BE=D0=B4=D0=B5=D0=BB=D0=B0?= =?UTF-8?q?=D0=BD=D0=BD=D0=B0=D1=8F=20=D0=9B=D0=B0=D0=B1=20=D1=80=D0=B0?= =?UTF-8?q?=D0=B1=D0=BE=D1=82=D0=B0=2003?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbstractCompany.cs | 4 +- .../PlaneSharigService.cs | 41 ++++++++++++++++++- .../FormPlaneCollection.Designer.cs | 2 +- 3 files changed, 42 insertions(+), 5 deletions(-) diff --git a/ProjectAirPlane/ProjectAirPlane/CollectionGenericObjects/AbstractCompany.cs b/ProjectAirPlane/ProjectAirPlane/CollectionGenericObjects/AbstractCompany.cs index 3a34be8..a705d97 100644 --- a/ProjectAirPlane/ProjectAirPlane/CollectionGenericObjects/AbstractCompany.cs +++ b/ProjectAirPlane/ProjectAirPlane/CollectionGenericObjects/AbstractCompany.cs @@ -7,11 +7,11 @@ public abstract class AbstractCompany /// /// Размер места (ширина) /// - protected readonly int _placeSizeWidth = 210; + protected readonly int _placeSizeWidth = 195; /// /// Размер места (высота) /// - protected readonly int _placeSizeHeight = 80; + protected readonly int _placeSizeHeight = 70; /// /// Ширина окна /// diff --git a/ProjectAirPlane/ProjectAirPlane/CollectionGenericObjects/PlaneSharigService.cs b/ProjectAirPlane/ProjectAirPlane/CollectionGenericObjects/PlaneSharigService.cs index b0e0b8b..0fccf19 100644 --- a/ProjectAirPlane/ProjectAirPlane/CollectionGenericObjects/PlaneSharigService.cs +++ b/ProjectAirPlane/ProjectAirPlane/CollectionGenericObjects/PlaneSharigService.cs @@ -11,11 +11,48 @@ public class PlaneSharigService : AbstractCompany protected override void DrawBackgound(Graphics g) { - throw new NotImplementedException(); + + 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); + } } protected override void SetObjectsPosition() { - throw new NotImplementedException(); + int width = _pictureWidth / _placeSizeWidth; + int height = _pictureHeight / _placeSizeHeight; + + int curWidth = width - 1; + int curHeight = 0; + + for (int i = 0; i < (_collection?.Count ?? 0); i++) + { + if (_collection.Get(i) != null) + { + _collection.Get(i).SetPictureSize(_pictureWidth, _pictureHeight); + _collection.Get(i).SetPosition(_placeSizeWidth * curWidth + 20, curHeight * _placeSizeHeight + 4); + } + if (curWidth > 0) + curWidth--; + else + { + curWidth = width - 1; + curHeight++; + } + if (curHeight > height) + { + return; + } + } } } diff --git a/ProjectAirPlane/ProjectAirPlane/FormPlaneCollection.Designer.cs b/ProjectAirPlane/ProjectAirPlane/FormPlaneCollection.Designer.cs index 947f70f..ae38492 100644 --- a/ProjectAirPlane/ProjectAirPlane/FormPlaneCollection.Designer.cs +++ b/ProjectAirPlane/ProjectAirPlane/FormPlaneCollection.Designer.cs @@ -118,7 +118,7 @@ buttonAddPlane.Name = "buttonAddPlane"; buttonAddPlane.Size = new Size(186, 50); buttonAddPlane.TabIndex = 1; - buttonAddPlane.Text = "Добавление самолёта"; + buttonAddPlane.Text = "Добавление судна"; buttonAddPlane.UseVisualStyleBackColor = true; buttonAddPlane.Click += ButtonAddPlane_Click; // -- 2.25.1 From 8f24090bdf845dee672b330cb7a27d8ec787ae63 Mon Sep 17 00:00:00 2001 From: alhimek17 Date: Tue, 26 Mar 2024 13:14:52 +0400 Subject: [PATCH 3/3] =?UTF-8?q?=D0=9B=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=20=E2=84=963?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbstractCompany.cs | 38 +++++++--- .../ICollectionGenericObjects.cs | 15 ++-- .../MassiveGenericObjects.cs | 54 ++++++++++++--- ...harigService.cs => PlaneSharingService.cs} | 27 ++++---- .../ProjectAirPlane/FormAirPlane.cs | 35 ++++++---- .../FormPlaneCollection.Designer.cs | 69 +++++++++---------- .../ProjectAirPlane/FormPlaneCollection.cs | 59 ++++++++-------- ProjectAirPlane/ProjectAirPlane/Program.cs | 1 + 8 files changed, 180 insertions(+), 118 deletions(-) rename ProjectAirPlane/ProjectAirPlane/CollectionGenericObjects/{PlaneSharigService.cs => PlaneSharingService.cs} (58%) diff --git a/ProjectAirPlane/ProjectAirPlane/CollectionGenericObjects/AbstractCompany.cs b/ProjectAirPlane/ProjectAirPlane/CollectionGenericObjects/AbstractCompany.cs index a705d97..5788d0b 100644 --- a/ProjectAirPlane/ProjectAirPlane/CollectionGenericObjects/AbstractCompany.cs +++ b/ProjectAirPlane/ProjectAirPlane/CollectionGenericObjects/AbstractCompany.cs @@ -1,33 +1,44 @@ -using ProjectAirPlane.Drawnings; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ProjectAirPlane.Drawnings; namespace ProjectAirPlane.CollectionGenericObjects; public abstract class AbstractCompany { /// - /// Размер места (ширина) - /// - protected readonly int _placeSizeWidth = 195; + /// Размер места (ширина) + /// + protected readonly int _placeSizeWidth = 210; + /// /// Размер места (высота) /// - protected readonly int _placeSizeHeight = 70; + protected readonly int _placeSizeHeight = 80; + /// /// Ширина окна /// protected readonly int _pictureWidth; + /// /// Высота окна /// protected readonly int _pictureHeight; + /// - /// Коллекция судов + /// Коллекция автомобилей /// protected ICollectionGenericObjects? _collection = null; + /// /// Вычисление максимального количества элементов, который можно разместить в окне /// private int GetMaxCount => _pictureWidth * _pictureHeight / (_placeSizeWidth * _placeSizeHeight); + /// /// Конструктор /// @@ -41,16 +52,18 @@ public abstract class AbstractCompany _collection = collection; _collection.SetMaxCount = GetMaxCount; } + /// /// Перегрузка оператора сложения для класса /// /// Компания - /// Добавляемый объект + /// Добавляемый объект /// public static int operator +(AbstractCompany company, DrawningPlane plane) { - return company._collection.Insert(plane); + return company._collection?.Insert(plane) ?? -1; } + /// /// Перегрузка оператора удаления для класса /// @@ -59,8 +72,9 @@ public abstract class AbstractCompany /// public static DrawningPlane operator -(AbstractCompany company, int position) { - return company._collection?.Remove(position); + return company._collection?.Remove(position) ?? null; } + /// /// Получение случайного объекта из коллекции /// @@ -70,6 +84,7 @@ public abstract class AbstractCompany Random rnd = new(); return _collection?.Get(rnd.Next(GetMaxCount)); } + /// /// Вывод всей коллекции /// @@ -79,22 +94,25 @@ public abstract class AbstractCompany Bitmap bitmap = new(_pictureWidth, _pictureHeight); Graphics graphics = Graphics.FromImage(bitmap); DrawBackgound(graphics); + SetObjectsPosition(); for (int i = 0; i < (_collection?.Count ?? 0); ++i) { DrawningPlane? obj = _collection?.Get(i); obj?.DrawTransport(graphics); } + return bitmap; } + /// /// Вывод заднего фона /// /// protected abstract void DrawBackgound(Graphics g); + /// /// Расстановка объектов /// protected abstract void SetObjectsPosition(); } - diff --git a/ProjectAirPlane/ProjectAirPlane/CollectionGenericObjects/ICollectionGenericObjects.cs b/ProjectAirPlane/ProjectAirPlane/CollectionGenericObjects/ICollectionGenericObjects.cs index dc51cd5..d609f17 100644 --- a/ProjectAirPlane/ProjectAirPlane/CollectionGenericObjects/ICollectionGenericObjects.cs +++ b/ProjectAirPlane/ProjectAirPlane/CollectionGenericObjects/ICollectionGenericObjects.cs @@ -1,9 +1,11 @@ -namespace ProjectAirPlane.CollectionGenericObjects; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectAirPlane.CollectionGenericObjects; -/// -/// Интерфейс описания действий для набора хранимых объектов -/// -/// Параметр: ограничение - ссылочный тип public interface ICollectionGenericObjects where T : class { @@ -37,7 +39,7 @@ public interface ICollectionGenericObjects /// /// Позиция /// true - удаление прошло удачно, false - удаление не удалось - T Remove(int position); + T? Remove(int position); /// /// Получение объекта по позиции @@ -46,4 +48,3 @@ public interface ICollectionGenericObjects /// Объект T? Get(int position); } - diff --git a/ProjectAirPlane/ProjectAirPlane/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectAirPlane/ProjectAirPlane/CollectionGenericObjects/MassiveGenericObjects.cs index 0820610..32c4e8f 100644 --- a/ProjectAirPlane/ProjectAirPlane/CollectionGenericObjects/MassiveGenericObjects.cs +++ b/ProjectAirPlane/ProjectAirPlane/CollectionGenericObjects/MassiveGenericObjects.cs @@ -1,27 +1,54 @@ -namespace ProjectAirPlane.CollectionGenericObjects; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectAirPlane.CollectionGenericObjects; public class MassiveGenericObjects : ICollectionGenericObjects where T : class { /// - /// Массив объектов, которые храним - /// - private T?[] _collection; + /// Массив объектов, которые храним + /// + private T?[] _collection; + public int Count => _collection.Length; - public int SetMaxCount { set { if (value > 0) { _collection = new T?[value]; } } } + + public int SetMaxCount + { + set + { + if (value > 0) + { + if (_collection.Length > 0) + { + Array.Resize(ref _collection, value); + } + else + { + _collection = new T?[value]; + } + } + } + } + /// - /// Конструктор - /// - public MassiveGenericObjects() + /// Конструктор + /// + public MassiveGenericObjects() { _collection = Array.Empty(); } + public T? Get(int position) { // TODO проверка позиции if (position >= _collection.Length || position < 0) return null; return _collection[position]; } + public int Insert(T obj) { // TODO вставка в свободное место набора @@ -37,12 +64,13 @@ public class MassiveGenericObjects : ICollectionGenericObjects } return -1; } + public int Insert(T obj, int position) { // TODO проверка позиции // TODO проверка, что элемент массива по этой позиции пустой, если нет, то - // ищется свободное место после этой позиции и идет вставка туда - // если нет после, ищем до + // ищется свободное место после этой позиции и идет вставка туда + // если нет после, ищем до // TODO вставка if (position >= _collection.Length || position < 0) return -1; @@ -73,14 +101,18 @@ public class MassiveGenericObjects : ICollectionGenericObjects } return -1; } + public T Remove(int position) { // TODO проверка позиции // TODO удаление объекта из массива, присвоив элементу массива значение null if (position >= _collection.Length || position < 0) + { return null; + } + T obj = _collection[position]; _collection[position] = null; return obj; } -} \ No newline at end of file +} diff --git a/ProjectAirPlane/ProjectAirPlane/CollectionGenericObjects/PlaneSharigService.cs b/ProjectAirPlane/ProjectAirPlane/CollectionGenericObjects/PlaneSharingService.cs similarity index 58% rename from ProjectAirPlane/ProjectAirPlane/CollectionGenericObjects/PlaneSharigService.cs rename to ProjectAirPlane/ProjectAirPlane/CollectionGenericObjects/PlaneSharingService.cs index 0fccf19..2b20d90 100644 --- a/ProjectAirPlane/ProjectAirPlane/CollectionGenericObjects/PlaneSharigService.cs +++ b/ProjectAirPlane/ProjectAirPlane/CollectionGenericObjects/PlaneSharingService.cs @@ -1,29 +1,30 @@ - +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; using ProjectAirPlane.Drawnings; namespace ProjectAirPlane.CollectionGenericObjects; -public class PlaneSharigService : AbstractCompany +public class PlaneSharingService : AbstractCompany { - public PlaneSharigService(int picWidth, int picHeight, ICollectionGenericObjects collection) : base(picWidth, picHeight, collection) + public PlaneSharingService(int picWidth, int picHeight, ICollectionGenericObjects collection) : base(picWidth, picHeight, collection) { } protected override void DrawBackgound(Graphics g) { - + + int width = _pictureWidth / _placeSizeWidth; + int height = _pictureHeight / _placeSizeHeight; Pen pen = new(Color.Black, 3); - for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++) + for (int i = 0; i < width; i++) { - for (int j = 0; j < _pictureHeight / _placeSizeHeight + - 1; ++j) + for (int j = 0; j < height + 1; ++j) { - g.DrawLine(pen, i * _placeSizeWidth, j * - _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * - _placeSizeHeight); + g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth - 5, j * _placeSizeHeight); } - g.DrawLine(pen, i * _placeSizeWidth, 0, i * - _placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight); } } @@ -40,7 +41,7 @@ public class PlaneSharigService : AbstractCompany if (_collection.Get(i) != null) { _collection.Get(i).SetPictureSize(_pictureWidth, _pictureHeight); - _collection.Get(i).SetPosition(_placeSizeWidth * curWidth + 20, curHeight * _placeSizeHeight + 4); + _collection.Get(i).SetPosition(_placeSizeWidth * curWidth + 15, curHeight * _placeSizeHeight + 3); } if (curWidth > 0) curWidth--; diff --git a/ProjectAirPlane/ProjectAirPlane/FormAirPlane.cs b/ProjectAirPlane/ProjectAirPlane/FormAirPlane.cs index bad1e30..91510ac 100644 --- a/ProjectAirPlane/ProjectAirPlane/FormAirPlane.cs +++ b/ProjectAirPlane/ProjectAirPlane/FormAirPlane.cs @@ -3,9 +3,8 @@ using ProjectAirPlane.MovementStrategy; namespace ProjectAirPlane; - /// -/// " " +/// "" /// public partial class FormAirPlane : Form { @@ -15,11 +14,21 @@ public partial class FormAirPlane : Form private DrawningPlane? _drawningPlane; /// - /// - /// - private AbstractStrategy? _strategy; + /// + /// + private AbstractStrategy? _strategy; - public DrawningPlane SetPlane { get; internal set; } + public DrawningPlane SetPlane + { + set + { + _drawningPlane = value; + _drawningPlane.SetPictureSize(pictureBoxAirPlane.Width, pictureBoxAirPlane.Height); + comboBoxStrategy.Enabled = true; + _strategy = null; + Draw(); + } + } /// /// @@ -31,7 +40,7 @@ public partial class FormAirPlane : Form } /// - /// + /// /// private void Draw() { @@ -83,11 +92,11 @@ public partial class FormAirPlane : Form } /// - /// "" - /// - /// - /// - private void ButtonStrategyStep_Click(object sender, EventArgs e) + /// + /// + /// + /// + private void ButtonStrategyStep_Click(object sender, EventArgs e) { if (_drawningPlane == null) return; @@ -121,6 +130,4 @@ public partial class FormAirPlane : Form _strategy = null; } } - - } \ No newline at end of file diff --git a/ProjectAirPlane/ProjectAirPlane/FormPlaneCollection.Designer.cs b/ProjectAirPlane/ProjectAirPlane/FormPlaneCollection.Designer.cs index ae38492..ec8bb03 100644 --- a/ProjectAirPlane/ProjectAirPlane/FormPlaneCollection.Designer.cs +++ b/ProjectAirPlane/ProjectAirPlane/FormPlaneCollection.Designer.cs @@ -35,7 +35,7 @@ maskedTextBox = new MaskedTextBox(); buttonAddAirPlane = new Button(); buttonAddPlane = new Button(); - comboBoxSelectionCompany = new ComboBox(); + comboBoxSelectorCompany = new ComboBox(); pictureBox = new PictureBox(); groupBoxTools.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit(); @@ -49,11 +49,11 @@ groupBoxTools.Controls.Add(maskedTextBox); groupBoxTools.Controls.Add(buttonAddAirPlane); groupBoxTools.Controls.Add(buttonAddPlane); - groupBoxTools.Controls.Add(comboBoxSelectionCompany); + groupBoxTools.Controls.Add(comboBoxSelectorCompany); groupBoxTools.Dock = DockStyle.Right; - groupBoxTools.Location = new Point(726, 0); + groupBoxTools.Location = new Point(686, 0); groupBoxTools.Name = "groupBoxTools"; - groupBoxTools.Size = new Size(205, 557); + groupBoxTools.Size = new Size(195, 513); groupBoxTools.TabIndex = 0; groupBoxTools.TabStop = false; groupBoxTools.Text = "Инструменты"; @@ -61,20 +61,20 @@ // buttonRefresh // buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonRefresh.Location = new Point(6, 484); + buttonRefresh.Location = new Point(6, 417); buttonRefresh.Name = "buttonRefresh"; - buttonRefresh.Size = new Size(186, 50); + buttonRefresh.Size = new Size(177, 35); buttonRefresh.TabIndex = 6; buttonRefresh.Text = "Обновить"; buttonRefresh.UseVisualStyleBackColor = true; - buttonRefresh.Click += buttonRefresh_Click; + buttonRefresh.Click += ButtonRefresh_Click; // // buttonGoToCheck // buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonGoToCheck.Location = new Point(6, 397); + buttonGoToCheck.Location = new Point(6, 320); buttonGoToCheck.Name = "buttonGoToCheck"; - buttonGoToCheck.Size = new Size(186, 50); + buttonGoToCheck.Size = new Size(177, 35); buttonGoToCheck.TabIndex = 5; buttonGoToCheck.Text = "Передать на тесты"; buttonGoToCheck.UseVisualStyleBackColor = true; @@ -83,29 +83,30 @@ // buttonRemovePlane // buttonRemovePlane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonRemovePlane.Location = new Point(6, 310); + buttonRemovePlane.Location = new Point(7, 255); buttonRemovePlane.Name = "buttonRemovePlane"; - buttonRemovePlane.Size = new Size(186, 50); + buttonRemovePlane.Size = new Size(177, 35); buttonRemovePlane.TabIndex = 4; - buttonRemovePlane.Text = "Удалить самолёта"; + buttonRemovePlane.Text = "Удалить самолёт"; buttonRemovePlane.UseVisualStyleBackColor = true; buttonRemovePlane.Click += ButtonRemovePlane_Click; // // maskedTextBox // - maskedTextBox.Location = new Point(6, 281); + maskedTextBox.Location = new Point(7, 207); maskedTextBox.Mask = "00"; maskedTextBox.Name = "maskedTextBox"; - maskedTextBox.Size = new Size(186, 23); + maskedTextBox.Size = new Size(180, 23); maskedTextBox.TabIndex = 3; maskedTextBox.ValidatingType = typeof(int); + maskedTextBox.MaskInputRejected += MaskedTextBox_MaskInputRejected; // // buttonAddAirPlane // buttonAddAirPlane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonAddAirPlane.Location = new Point(6, 143); + buttonAddAirPlane.Location = new Point(7, 135); buttonAddAirPlane.Name = "buttonAddAirPlane"; - buttonAddAirPlane.Size = new Size(186, 50); + buttonAddAirPlane.Size = new Size(177, 47); buttonAddAirPlane.TabIndex = 2; buttonAddAirPlane.Text = "Добавление самолёта с радаром"; buttonAddAirPlane.UseVisualStyleBackColor = true; @@ -114,31 +115,32 @@ // buttonAddPlane // buttonAddPlane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonAddPlane.Location = new Point(6, 87); + buttonAddPlane.Location = new Point(6, 80); buttonAddPlane.Name = "buttonAddPlane"; - buttonAddPlane.Size = new Size(186, 50); + buttonAddPlane.Size = new Size(177, 37); buttonAddPlane.TabIndex = 1; - buttonAddPlane.Text = "Добавление судна"; + buttonAddPlane.Text = "Добавление самолёта"; buttonAddPlane.UseVisualStyleBackColor = true; buttonAddPlane.Click += ButtonAddPlane_Click; // - // comboBoxSelectionCompany + // comboBoxSelectorCompany // - comboBoxSelectionCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - comboBoxSelectionCompany.DropDownStyle = ComboBoxStyle.DropDownList; - comboBoxSelectionCompany.FormattingEnabled = true; - comboBoxSelectionCompany.Items.AddRange(new object[] { "Хранилище" }); - comboBoxSelectionCompany.Location = new Point(6, 22); - comboBoxSelectionCompany.Name = "comboBoxSelectionCompany"; - comboBoxSelectionCompany.Size = new Size(186, 23); - comboBoxSelectionCompany.TabIndex = 0; + comboBoxSelectorCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxSelectorCompany.FormattingEnabled = true; + comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" }); + comboBoxSelectorCompany.Location = new Point(6, 22); + comboBoxSelectorCompany.Name = "comboBoxSelectorCompany"; + comboBoxSelectorCompany.Size = new Size(178, 23); + comboBoxSelectorCompany.TabIndex = 0; + comboBoxSelectorCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged; // // pictureBox // pictureBox.Dock = DockStyle.Fill; pictureBox.Location = new Point(0, 0); pictureBox.Name = "pictureBox"; - pictureBox.Size = new Size(726, 557); + pictureBox.Size = new Size(686, 513); pictureBox.TabIndex = 1; pictureBox.TabStop = false; // @@ -146,7 +148,7 @@ // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(931, 557); + ClientSize = new Size(881, 513); Controls.Add(pictureBox); Controls.Add(groupBoxTools); Name = "FormPlaneCollection"; @@ -157,15 +159,10 @@ ResumeLayout(false); } - private void ButtonAddPlane_Click1(object sender, EventArgs e) - { - throw new NotImplementedException(); - } - #endregion private GroupBox groupBoxTools; - private ComboBox comboBoxSelectionCompany; + private ComboBox comboBoxSelectorCompany; private Button buttonAddPlane; private Button buttonAddAirPlane; private PictureBox pictureBox; diff --git a/ProjectAirPlane/ProjectAirPlane/FormPlaneCollection.cs b/ProjectAirPlane/ProjectAirPlane/FormPlaneCollection.cs index f59deee..c6e665a 100644 --- a/ProjectAirPlane/ProjectAirPlane/FormPlaneCollection.cs +++ b/ProjectAirPlane/ProjectAirPlane/FormPlaneCollection.cs @@ -23,24 +23,24 @@ public partial class FormPlaneCollection : Form private AbstractCompany? _company = null; /// - /// Конструктор - /// + /// Конструктор + /// public FormPlaneCollection() { InitializeComponent(); } /// - /// Выбор компании - /// - /// - /// - private void ComboBoxSelectionCompany_SelectedIndexChanged(object sender, EventArgs e) + /// Выбор компании + /// + /// + /// + private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e) { - switch (comboBoxSelectionCompany.Text) + switch (comboBoxSelectorCompany.Text) { case "Хранилище": - _company = new PlaneSharigService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects()); + _company = new PlaneSharingService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects()); break; } } @@ -51,22 +51,22 @@ public partial class FormPlaneCollection : Form /// Тип создаваемого объекта private void CreateObject(string type) { - DrawningPlane drawningPlane; if (_company == null) { return; } Random random = new(); + DrawningPlane drawningPlane; switch (type) { case nameof(DrawningPlane): drawningPlane = new DrawningPlane(random.Next(100, 300), random.Next(1000, 3000), GetColor(random)); break; case nameof(DrawningAirPlane): + // TODO вызов диалогового окна для выбора цвета drawningPlane = new DrawningAirPlane(random.Next(100, 300), random.Next(1000, 3000), - Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), - Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), + GetColor(random), GetColor(random), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2))); break; default: @@ -83,12 +83,13 @@ public partial class FormPlaneCollection : Form MessageBox.Show("Не удалось добавить объект"); } } + /// /// Получение цвета /// /// Генератор случайных чисел /// - private static Color GetColor(Random random) + private static Color GetColor(Random random) { Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)); ColorDialog dialog = new(); @@ -96,29 +97,34 @@ public partial class FormPlaneCollection : Form { color = dialog.Color; } + return color; } - private void ButtonAddPlane_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningPlane)); + + private void ButtonAddAirPlane_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningAirPlane)); + + + private void MaskedTextBox_MaskInputRejected(object sender, MaskInputRejectedEventArgs e) + { + + } - /// - /// Удаление объекта - /// - /// - /// private void ButtonRemovePlane_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == null) { return; } - if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) + + if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) { return; } + int pos = Convert.ToInt32(maskedTextBox.Text); if (_company - pos != null) { @@ -131,17 +137,13 @@ public partial class FormPlaneCollection : Form } } - /// - /// Передача объекта в другую форму - /// - /// - /// private void ButtonGoToCheck_Click(object sender, EventArgs e) { if (_company == null) { return; } + DrawningPlane? plane = null; int counter = 100; while (plane == null) @@ -153,10 +155,12 @@ public partial class FormPlaneCollection : Form break; } } + if (plane == null) { return; } + FormAirPlane form = new() { SetPlane = plane @@ -164,12 +168,13 @@ public partial class FormPlaneCollection : Form form.ShowDialog(); } - private void buttonRefresh_Click(object sender, EventArgs e) + private void ButtonRefresh_Click(object sender, EventArgs e) { if (_company == null) { return; } + pictureBox.Image = _company.Show(); - } + } } diff --git a/ProjectAirPlane/ProjectAirPlane/Program.cs b/ProjectAirPlane/ProjectAirPlane/Program.cs index bd0c956..831f9a4 100644 --- a/ProjectAirPlane/ProjectAirPlane/Program.cs +++ b/ProjectAirPlane/ProjectAirPlane/Program.cs @@ -12,6 +12,7 @@ namespace ProjectAirPlane // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); Application.Run(new FormPlaneCollection()); + } } } \ No newline at end of file -- 2.25.1