From 535a8b9a9cf8ee3c1b15e74bc0376aaff8741a4f Mon Sep 17 00:00:00 2001 From: Aleksandr4350 Date: Thu, 11 Apr 2024 18:56:46 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9B=D0=B0=D0=B1=203?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbstractCompany.cs | 109 +++++++++++ .../ICollectionGenericObjects.cs | 48 +++++ .../MassiveGenericObjects.cs | 117 ++++++++++++ .../PlaneSharingService.cs | 63 +++++++ .../Drawnings/Drawningplane.cs | 8 +- .../ProjectSportCar/FormAiroplane.Designer.cs | 29 +-- .../ProjectSportCar/FormAiroplane.cs | 73 +++----- .../FormPlaneCollection.Designer.cs | 167 +++++++++++++++++ .../ProjectSportCar/FormPlaneCollection.cs | 174 ++++++++++++++++++ .../ProjectSportCar/FormPlaneCollection.resx | 120 ++++++++++++ ProjectSportCar/ProjectSportCar/Program.cs | 2 +- 11 files changed, 823 insertions(+), 87 deletions(-) create mode 100644 ProjectSportCar/ProjectSportCar/CollectionGenericObjects/AbstractCompany.cs create mode 100644 ProjectSportCar/ProjectSportCar/CollectionGenericObjects/ICollectionGenericObjects.cs create mode 100644 ProjectSportCar/ProjectSportCar/CollectionGenericObjects/MassiveGenericObjects.cs create mode 100644 ProjectSportCar/ProjectSportCar/CollectionGenericObjects/PlaneSharingService.cs create mode 100644 ProjectSportCar/ProjectSportCar/FormPlaneCollection.Designer.cs create mode 100644 ProjectSportCar/ProjectSportCar/FormPlaneCollection.cs create mode 100644 ProjectSportCar/ProjectSportCar/FormPlaneCollection.resx diff --git a/ProjectSportCar/ProjectSportCar/CollectionGenericObjects/AbstractCompany.cs b/ProjectSportCar/ProjectSportCar/CollectionGenericObjects/AbstractCompany.cs new file mode 100644 index 0000000..c511aa2 --- /dev/null +++ b/ProjectSportCar/ProjectSportCar/CollectionGenericObjects/AbstractCompany.cs @@ -0,0 +1,109 @@ +using ProjectAiroplane.Drawnings; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectAiroplane.CollectionGenericObjects; + +/// +/// Абстракция компании, хранящий коллекцию самолётов +/// +public abstract class AbstractCompany +{ + /// + /// Размер места (ширина) + /// + protected readonly int _placeSizeWidth = 210; + /// + /// Размер места (высота) + /// + protected readonly int _placeSizeHeight = 90; + /// + /// Ширина окна + /// + 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/ProjectSportCar/ProjectSportCar/CollectionGenericObjects/ICollectionGenericObjects.cs b/ProjectSportCar/ProjectSportCar/CollectionGenericObjects/ICollectionGenericObjects.cs new file mode 100644 index 0000000..a493d42 --- /dev/null +++ b/ProjectSportCar/ProjectSportCar/CollectionGenericObjects/ICollectionGenericObjects.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectAiroplane.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/ProjectSportCar/ProjectSportCar/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectSportCar/ProjectSportCar/CollectionGenericObjects/MassiveGenericObjects.cs new file mode 100644 index 0000000..e223033 --- /dev/null +++ b/ProjectSportCar/ProjectSportCar/CollectionGenericObjects/MassiveGenericObjects.cs @@ -0,0 +1,117 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectAiroplane.CollectionGenericObjects; + +/// +/// Параметризованный набор объектов +/// +/// Параметр: ограничение - ссылочный тип +public class MassiveGenericObjects : ICollectionGenericObjects +where T : class +{ + /// + /// Массив объектов, которые храним + /// + private T?[] _collection; + public int Count => _collection.Length; + public int SetMaxCount + { + set + { + if (value > 0) + { + if (_collection.Length > 0) + { + Array.Resize(ref _collection, value); + } + else + { + _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; + + for (index = position + 1; index < _collection.Length; ++index) + { + if (_collection[index] == null) + { + _collection[position] = obj; + return position; + } + } + + for (index = position - 1; index >= 0; --index) + { + if (_collection[index] == null) + { + _collection[position] = obj; + return position; + } + } + 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/ProjectSportCar/ProjectSportCar/CollectionGenericObjects/PlaneSharingService.cs b/ProjectSportCar/ProjectSportCar/CollectionGenericObjects/PlaneSharingService.cs new file mode 100644 index 0000000..a81d98c --- /dev/null +++ b/ProjectSportCar/ProjectSportCar/CollectionGenericObjects/PlaneSharingService.cs @@ -0,0 +1,63 @@ +using ProjectAiroplane.Drawnings; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectAiroplane.CollectionGenericObjects; + +public class PlaneSharingService : AbstractCompany +{ + 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 < width; i++) + { + for (int j = 0; j < height + 1; ++j) + { + g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth - 15, j * _placeSizeHeight); + } + } + } + protected override void SetObjectsPosition() + { + 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 + 2); + } + if (curWidth > 0) + curWidth--; + else + { + curWidth = width - 1; + curHeight++; + } + if (curHeight > height) + { + return; + } + } + + } +} diff --git a/ProjectSportCar/ProjectSportCar/Drawnings/Drawningplane.cs b/ProjectSportCar/ProjectSportCar/Drawnings/Drawningplane.cs index 8bc2fd2..4528874 100644 --- a/ProjectSportCar/ProjectSportCar/Drawnings/Drawningplane.cs +++ b/ProjectSportCar/ProjectSportCar/Drawnings/Drawningplane.cs @@ -1,9 +1,5 @@ using ProjectAiroplane.Entities; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; + namespace ProjectAiroplane.Drawnings; @@ -227,7 +223,7 @@ public class Drawningplane Pen pen = new(Color.Black); - int f = 10; + int f = 5; //крыло верхнее самолета g.DrawLine(pen, _startPosX.Value + 15 - f, _startPosY.Value + 5 - f, _startPosX.Value + 15 - f, _startPosY.Value + 5 - f); g.DrawLine(pen, _startPosX.Value + 15 - f, _startPosY.Value + 5 - f, _startPosX.Value + 55 - f, _startPosY.Value + 35 - f); diff --git a/ProjectSportCar/ProjectSportCar/FormAiroplane.Designer.cs b/ProjectSportCar/ProjectSportCar/FormAiroplane.Designer.cs index 384b319..5d99b7b 100644 --- a/ProjectSportCar/ProjectSportCar/FormAiroplane.Designer.cs +++ b/ProjectSportCar/ProjectSportCar/FormAiroplane.Designer.cs @@ -29,12 +29,10 @@ private void InitializeComponent() { pictureBoxAiroplane = new PictureBox(); - buttonCreate = new Button(); buttonLeft = new Button(); buttonUp = new Button(); buttonRight = new Button(); buttonDown = new Button(); - buttonCreatePlane = new Button(); comboBoxStrategy = new ComboBox(); Shag = new Button(); ((System.ComponentModel.ISupportInitialize)pictureBoxAiroplane).BeginInit(); @@ -49,17 +47,6 @@ pictureBoxAiroplane.TabIndex = 0; pictureBoxAiroplane.TabStop = false; // - // buttonCreate - // - buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonCreate.Location = new Point(12, 413); - buttonCreate.Name = "buttonCreate"; - buttonCreate.Size = new Size(240, 29); - buttonCreate.TabIndex = 1; - buttonCreate.Text = "Создать самолёт с радаром"; - buttonCreate.UseVisualStyleBackColor = true; - buttonCreate.Click += ButtonCreate_Click; - // // buttonLeft // buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; @@ -108,17 +95,6 @@ buttonDown.UseVisualStyleBackColor = true; buttonDown.Click += ButtonMove_Click; // - // buttonCreatePlane - // - buttonCreatePlane.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonCreatePlane.Location = new Point(263, 413); - buttonCreatePlane.Name = "buttonCreatePlane"; - buttonCreatePlane.Size = new Size(208, 29); - buttonCreatePlane.TabIndex = 6; - buttonCreatePlane.Text = "Создать самолёт"; - buttonCreatePlane.UseVisualStyleBackColor = true; - buttonCreatePlane.Click += ButtonCreateplane_Click; - // // comboBoxStrategy // comboBoxStrategy.Anchor = AnchorStyles.Top | AnchorStyles.Right; @@ -148,15 +124,14 @@ ClientSize = new Size(807, 457); Controls.Add(Shag); Controls.Add(comboBoxStrategy); - Controls.Add(buttonCreatePlane); Controls.Add(buttonDown); Controls.Add(buttonRight); Controls.Add(buttonUp); Controls.Add(buttonLeft); - Controls.Add(buttonCreate); Controls.Add(pictureBoxAiroplane); Name = "FormAiroplane"; Text = "Самолет с радаром"; + Load += FormAiroplane_Load; ((System.ComponentModel.ISupportInitialize)pictureBoxAiroplane).EndInit(); ResumeLayout(false); } @@ -164,12 +139,10 @@ #endregion private PictureBox pictureBoxAiroplane; - private Button buttonCreate; private Button buttonLeft; private Button buttonUp; private Button buttonRight; private Button buttonDown; - private Button buttonCreatePlane; private ComboBox comboBoxStrategy; private Button Shag; } diff --git a/ProjectSportCar/ProjectSportCar/FormAiroplane.cs b/ProjectSportCar/ProjectSportCar/FormAiroplane.cs index 92225f5..b52c459 100644 --- a/ProjectSportCar/ProjectSportCar/FormAiroplane.cs +++ b/ProjectSportCar/ProjectSportCar/FormAiroplane.cs @@ -3,11 +3,26 @@ using ProjectAiroplane.MovementStrategy; namespace ProjectAiroplane { - public partial class FormAiroplane : Form { private Drawningplane? _drawningplane; private AbstractStrategy? _strategy; + + /// + /// стратегия перемещения + /// + public Drawningplane Setplane + { + set + { + _drawningplane = value; + _drawningplane.SetPictureSize(pictureBoxAiroplane.Width, pictureBoxAiroplane.Height); + comboBoxStrategy.Enabled = true; + _strategy = null; + Draw(); + } + } + public FormAiroplane() { InitializeComponent(); @@ -25,62 +40,11 @@ namespace ProjectAiroplane _drawningplane.DrawTransport(gr); pictureBoxAiroplane.Image = bmp; } - - private void CreateObject(string type) - { - Random random = new Random(); - 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(DrawningAiroplane): - _drawningplane = new DrawningAiroplane(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))); - break; - default: - return; - } - _drawningplane.SetPictureSize(pictureBoxAiroplane.Width, pictureBoxAiroplane.Height); - _drawningplane.SetPosition(random.Next(10, 100), random.Next(10, 100)); - _strategy = null; - comboBoxStrategy.Enabled = true; - Draw(); - } - /// - /// Кнопка создания самолета - /// - /// - /// - private void ButtonCreate_Click(object sender, EventArgs e) - { - CreateObject(nameof(DrawningAiroplane)); - } - - ///// - ///// Кнопка создания самолета с радаром "Создать самолет с радаром" - ///// - ///// - ///// - //private void ButtonCreateAiroplane_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningAiroplane)); - - /// - /// Кнопка создания самолета "Создать" - /// - /// - /// - - private void ButtonCreateplane_Click(object sender, EventArgs e) => CreateObject(nameof(Drawningplane)); - /// /// Перемещение объекта по форме (нажатие кнопок навигации) /// /// /// - private void ButtonMove_Click(object sender, EventArgs e) { if (_drawningplane == null) @@ -144,6 +108,11 @@ namespace ProjectAiroplane _strategy = null; } } + + private void FormAiroplane_Load(object sender, EventArgs e) + { + + } } } diff --git a/ProjectSportCar/ProjectSportCar/FormPlaneCollection.Designer.cs b/ProjectSportCar/ProjectSportCar/FormPlaneCollection.Designer.cs new file mode 100644 index 0000000..3d790f1 --- /dev/null +++ b/ProjectSportCar/ProjectSportCar/FormPlaneCollection.Designer.cs @@ -0,0 +1,167 @@ +namespace ProjectAiroplane +{ + 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(); + buttonDelPlane = new Button(); + maskedTextBox1 = new MaskedTextBox(); + buttonAddAiroplane = new Button(); + buttonAddPlane = new Button(); + comboBoxSelectorCompany = 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(buttonDelPlane); + groupBoxTools.Controls.Add(maskedTextBox1); + groupBoxTools.Controls.Add(buttonAddAiroplane); + groupBoxTools.Controls.Add(buttonAddPlane); + groupBoxTools.Controls.Add(comboBoxSelectorCompany); + groupBoxTools.Dock = DockStyle.Right; + groupBoxTools.Location = new Point(859, 0); + groupBoxTools.Name = "groupBoxTools"; + groupBoxTools.Size = new Size(277, 680); + groupBoxTools.TabIndex = 0; + groupBoxTools.TabStop = false; + groupBoxTools.Text = "Инструменты"; + // + // buttonReFresh + // + buttonReFresh.Location = new Point(13, 536); + buttonReFresh.Name = "buttonReFresh"; + buttonReFresh.Size = new Size(252, 57); + buttonReFresh.TabIndex = 6; + buttonReFresh.Text = "Обновить"; + buttonReFresh.UseVisualStyleBackColor = true; + // + // buttonGoToCheck + // + buttonGoToCheck.Location = new Point(11, 400); + buttonGoToCheck.Name = "buttonGoToCheck"; + buttonGoToCheck.Size = new Size(254, 57); + buttonGoToCheck.TabIndex = 5; + buttonGoToCheck.Text = "Передать на тест"; + buttonGoToCheck.UseVisualStyleBackColor = true; + buttonGoToCheck.Click += ButtonGoToCheck_Click; + // + // buttonDelPlane + // + buttonDelPlane.Location = new Point(13, 285); + buttonDelPlane.Name = "buttonDelPlane"; + buttonDelPlane.Size = new Size(252, 57); + buttonDelPlane.TabIndex = 4; + buttonDelPlane.Text = "Удалить самолёт"; + buttonDelPlane.UseVisualStyleBackColor = true; + buttonDelPlane.Click += ButtonDelPlane_Click; + // + // maskedTextBox1 + // + maskedTextBox1.Location = new Point(13, 252); + maskedTextBox1.Mask = "00"; + maskedTextBox1.Name = "maskedTextBox1"; + maskedTextBox1.Size = new Size(252, 27); + maskedTextBox1.TabIndex = 3; + maskedTextBox1.ValidatingType = typeof(int); + // + // buttonAddAiroplane + // + buttonAddAiroplane.Location = new Point(13, 153); + buttonAddAiroplane.Name = "buttonAddAiroplane"; + buttonAddAiroplane.Size = new Size(252, 57); + buttonAddAiroplane.TabIndex = 2; + buttonAddAiroplane.Text = "Добавление самолёта с радаром"; + buttonAddAiroplane.UseVisualStyleBackColor = true; + buttonAddAiroplane.Click += ButtonAddAiroplane_Click; + // + // buttonAddPlane + // + buttonAddPlane.Location = new Point(13, 81); + buttonAddPlane.Name = "buttonAddPlane"; + buttonAddPlane.Size = new Size(252, 55); + buttonAddPlane.TabIndex = 1; + buttonAddPlane.Text = "Добавление самолёта"; + buttonAddPlane.UseVisualStyleBackColor = true; + buttonAddPlane.Click += ButtonAddPlane_Click; + // + // comboBoxSelectorCompany + // + comboBoxSelectorCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxSelectorCompany.FormattingEnabled = true; + comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" }); + comboBoxSelectorCompany.Location = new Point(13, 31); + comboBoxSelectorCompany.Name = "comboBoxSelectorCompany"; + comboBoxSelectorCompany.Size = new Size(252, 28); + 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(859, 680); + pictureBox.TabIndex = 1; + pictureBox.TabStop = false; + // + // FormPlaneCollection + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1136, 680); + Controls.Add(pictureBox); + Controls.Add(groupBoxTools); + Name = "FormPlaneCollection"; + Text = "Коллекция самолётов"; + groupBoxTools.ResumeLayout(false); + groupBoxTools.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); + ResumeLayout(false); + } + + #endregion + + private GroupBox groupBoxTools; + private ComboBox comboBoxSelectorCompany; + private Button buttonAddAiroplane; + private Button buttonAddPlane; + private PictureBox pictureBox; + private Button buttonDelPlane; + private MaskedTextBox maskedTextBox1; + private Button buttonReFresh; + private Button buttonGoToCheck; + } +} \ No newline at end of file diff --git a/ProjectSportCar/ProjectSportCar/FormPlaneCollection.cs b/ProjectSportCar/ProjectSportCar/FormPlaneCollection.cs new file mode 100644 index 0000000..c69a8da --- /dev/null +++ b/ProjectSportCar/ProjectSportCar/FormPlaneCollection.cs @@ -0,0 +1,174 @@ +using ProjectAiroplane.CollectionGenericObjects; +using ProjectAiroplane.Drawnings; +using System.Windows.Forms; + +namespace ProjectAiroplane; + +public partial class FormPlaneCollection : Form +{ + /// + /// Компания + /// + private AbstractCompany? _company = null; + /// + /// Конструктор + /// + public FormPlaneCollection() + { + InitializeComponent(); + } + /// + /// Выбор компании + /// + /// + /// + private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e) + { + switch (comboBoxSelectorCompany.Text) + { + case "Хранилище": + _company = new PlaneSharingService(pictureBox.Width, + pictureBox.Height, new MassiveGenericObjects()); + break; + } + } + /// + /// Добавление обычного самолёта + /// + /// + /// + private void ButtonAddPlane_Click(object sender, EventArgs e) => CreateObject(nameof(Drawningplane)); + /// + /// Добавление самолёта с радаром + /// + /// + /// + private void ButtonAddAiroplane_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningAiroplane)); + /// + /// Создание объекта класса-перемещения + /// + /// Тип создаваемого объекта + private void CreateObject(string type) + { + 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(DrawningAiroplane): + // TODO вызов диалогового окна для выбора цвета + drawningPlane = new DrawningAiroplane(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))); + 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 ButtonDelPlane_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(maskedTextBox1.Text) || _company == null) + { + return; + } + if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) + { + return; + } + int pos = Convert.ToInt32(maskedTextBox1.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; + } + FormAiroplane 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/ProjectSportCar/ProjectSportCar/FormPlaneCollection.resx b/ProjectSportCar/ProjectSportCar/FormPlaneCollection.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectSportCar/ProjectSportCar/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/ProjectSportCar/ProjectSportCar/Program.cs b/ProjectSportCar/ProjectSportCar/Program.cs index 5ebfb6a..c1bf899 100644 --- a/ProjectSportCar/ProjectSportCar/Program.cs +++ b/ProjectSportCar/ProjectSportCar/Program.cs @@ -11,7 +11,7 @@ namespace ProjectAiroplane // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormAiroplane()); + Application.Run(new FormPlaneCollection()); } } } \ No newline at end of file