From df565e4295a91943700710ef1adfc3d78ef9de56 Mon Sep 17 00:00:00 2001 From: repka228 <54245562+repka228@users.noreply.github.com> Date: Fri, 15 Mar 2024 03:16:25 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20todo,=20?= =?UTF-8?q?=D0=BD=D0=BE=20=D0=BB=D0=BE=D0=B2=D0=B8=D1=82=20=D0=BE=D1=88?= =?UTF-8?q?=D0=B8=D0=B1=D0=BA=D1=83=20=D0=B2=20Instert=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbstractCompany.cs | 110 +++++++++++ .../BusSharingService.cs | 31 +++ .../ICollectionGenericObjects.cs | 42 ++++ .../MassiveGenericObjects.cs | 96 +++++++++ .../Drawnings/DrawningAccordionBus.cs | 10 + .../Entities/EntityAccordionBus.cs | 10 + .../AccordionBus/FormAccordionBus.Designer.cs | 2 - AccordionBus/AccordionBus/FormAccordionBus.cs | 63 ++---- .../FormBusCollection.Designer.cs | 175 +++++++++++++++++ .../AccordionBus/FormBusCollection.cs | 183 ++++++++++++++++++ .../AccordionBus/FormBusCollection.resx | 123 ++++++++++++ ...AbstractStategy.cs => AbstractStrategy.cs} | 2 +- .../MovementStrategy/MoveToBorder.cs | 2 +- .../MovementStrategy/MoveToCenter.cs | 2 +- AccordionBus/AccordionBus/Program.cs | 28 +-- 15 files changed, 814 insertions(+), 65 deletions(-) create mode 100644 AccordionBus/AccordionBus/CollectionGenericObjects/AbstractCompany.cs create mode 100644 AccordionBus/AccordionBus/CollectionGenericObjects/BusSharingService.cs create mode 100644 AccordionBus/AccordionBus/CollectionGenericObjects/ICollectionGenericObjects.cs create mode 100644 AccordionBus/AccordionBus/CollectionGenericObjects/MassiveGenericObjects.cs create mode 100644 AccordionBus/AccordionBus/FormBusCollection.Designer.cs create mode 100644 AccordionBus/AccordionBus/FormBusCollection.cs create mode 100644 AccordionBus/AccordionBus/FormBusCollection.resx rename AccordionBus/AccordionBus/MovementStrategy/{AbstractStategy.cs => AbstractStrategy.cs} (99%) diff --git a/AccordionBus/AccordionBus/CollectionGenericObjects/AbstractCompany.cs b/AccordionBus/AccordionBus/CollectionGenericObjects/AbstractCompany.cs new file mode 100644 index 0000000..950846e --- /dev/null +++ b/AccordionBus/AccordionBus/CollectionGenericObjects/AbstractCompany.cs @@ -0,0 +1,110 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using AccordionBus.Drawnings; +namespace AccordionBus.CollectionGenericObjects; + +using ProjectAccordionBus.CollectionGenericObjects; + +/// +/// Абстракция компании, хранящий коллекцию автомобилей +/// +public abstract class AbstractCompany +{ + /// + /// Размер места (ширина) + /// + protected readonly int _placeSizeWidth = 180; + /// + /// Размер места (высота) + /// + protected readonly int _placeSizeHeight = 40; + /// + /// Ширина окна + /// + 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 bool operator +(AbstractCompany company, DrawningBus car) + { + return company._collection?.Insert(car) ?? false; + } + /// + /// Перегрузка оператора удаления для класса + /// + /// Компания + /// Номер удаляемого объекта + /// + public static bool operator -(AbstractCompany company, int position) + { + return company._collection?.Remove(position) ?? false; + } + /// + /// Получение случайного объекта из коллекции + /// + /// + public DrawningBus? 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) + { + DrawningBus? obj = _collection?.Get(i); + obj?.DrawTransport(graphics); + } + return bitmap; + } + /// + /// Вывод заднего фона + /// + /// + protected abstract void DrawBackgound(Graphics g); + /// + /// Расстановка объектов + /// + protected abstract void SetObjectsPosition(); +} diff --git a/AccordionBus/AccordionBus/CollectionGenericObjects/BusSharingService.cs b/AccordionBus/AccordionBus/CollectionGenericObjects/BusSharingService.cs new file mode 100644 index 0000000..c4c5d74 --- /dev/null +++ b/AccordionBus/AccordionBus/CollectionGenericObjects/BusSharingService.cs @@ -0,0 +1,31 @@ +using ProjectAccordionBus.CollectionGenericObjects; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using AccordionBus.Drawnings; + +namespace AccordionBus.CollectionGenericObjects; + +public class BusSharingService : AbstractCompany +{ + /// + /// Конструктор + /// + /// + /// + /// + public BusSharingService(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/AccordionBus/AccordionBus/CollectionGenericObjects/ICollectionGenericObjects.cs b/AccordionBus/AccordionBus/CollectionGenericObjects/ICollectionGenericObjects.cs new file mode 100644 index 0000000..a076523 --- /dev/null +++ b/AccordionBus/AccordionBus/CollectionGenericObjects/ICollectionGenericObjects.cs @@ -0,0 +1,42 @@ +namespace ProjectAccordionBus.CollectionGenericObjects; +/// +/// Интерфейс описания действий для набора хранимых объектов +/// +/// Параметр: ограничение - ссылочный тип +public interface ICollectionGenericObjects +where T : class +{ + /// + /// Количество объектов в коллекции + /// + int Count { get; } + /// + /// Установка максимального количества элементов + /// + int SetMaxCount { set; } + /// + /// Добавление объекта в коллекцию + /// + /// Добавляемый объект + /// true - вставка прошла удачно, false - вставка не удалась + bool Insert(T obj); + /// + /// Добавление объекта в коллекцию на конкретную позицию + /// + /// Добавляемый объект + /// Позиция + /// true - вставка прошла удачно, false - вставка не удалась + bool Insert(T obj, int position); + /// + /// Удаление объекта из коллекции с конкретной позиции + /// + /// Позиция + /// true - удаление прошло удачно, false - удаление не удалось + bool Remove(int position); + /// + /// Получение объекта по позиции + /// + /// Позиция + /// Объект + T? Get(int position); +} diff --git a/AccordionBus/AccordionBus/CollectionGenericObjects/MassiveGenericObjects.cs b/AccordionBus/AccordionBus/CollectionGenericObjects/MassiveGenericObjects.cs new file mode 100644 index 0000000..63ce427 --- /dev/null +++ b/AccordionBus/AccordionBus/CollectionGenericObjects/MassiveGenericObjects.cs @@ -0,0 +1,96 @@ +using ProjectAccordionBus.CollectionGenericObjects; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AccordionBus.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) + { + if (_collection[position]!=null) + return _collection[position]; + return null; + } + public bool Insert(T obj) + { + for(int i=0; i < _collection.Length; ++i) + { + if (_collection[i]==null) + { + _collection[i] = obj; + return true; + } + } + return false; + } + public bool Insert(T obj, int position) + { + if (_collection[position] == null) + { + _collection[position] = obj; + return true; + } + else + { + for(int i=position; i< _collection.Length; ++i) + { + if(_collection[i]==null) + { + _collection[i] = obj; + return true; + } + } + for (int i = 0; i < position; ++i) + { + if (_collection[i] == null) + { + _collection[i] = obj; + return true; + } + } + } + return false; + } + public bool Remove(int position) + { + if (_collection[position] != null) + { + _collection[position] = null; + return true; + } + return false; + } +} \ No newline at end of file diff --git a/AccordionBus/AccordionBus/Drawnings/DrawningAccordionBus.cs b/AccordionBus/AccordionBus/Drawnings/DrawningAccordionBus.cs index 6ff8990..c4dafec 100644 --- a/AccordionBus/AccordionBus/Drawnings/DrawningAccordionBus.cs +++ b/AccordionBus/AccordionBus/Drawnings/DrawningAccordionBus.cs @@ -26,6 +26,16 @@ public class DrawningAccordionBus:DrawningBus EntityBus = new EntityAccordionBus(speed, weight, bodyColor, additionalColor, bodyGlass, garmoshka); } + /// + /// перегрузка для создания автобуса в коллекцию базового типа + /// + /// скорость + /// вес + /// основной цвет + public DrawningAccordionBus(int speed, double weight, Color bodyColor) : base(180, 40) + { + EntityBus = new EntityAccordionBus(speed, weight, bodyColor); + } public override void DrawTransport(Graphics g) { diff --git a/AccordionBus/AccordionBus/Entities/EntityAccordionBus.cs b/AccordionBus/AccordionBus/Entities/EntityAccordionBus.cs index 852008a..5d137ac 100644 --- a/AccordionBus/AccordionBus/Entities/EntityAccordionBus.cs +++ b/AccordionBus/AccordionBus/Entities/EntityAccordionBus.cs @@ -33,4 +33,14 @@ public class EntityAccordionBus: EntityBus BodyGlass = glass; BodyGarmoshka = garmoshka; } + /// + /// Перегрузка конструктора для создания базового автобуса в коллекцию + /// + /// скрость + /// вес + /// основной цвет + public EntityAccordionBus(int speed, double weigth, Color bodyColor) : base(speed, weigth, bodyColor) + { + + } } diff --git a/AccordionBus/AccordionBus/FormAccordionBus.Designer.cs b/AccordionBus/AccordionBus/FormAccordionBus.Designer.cs index cdb6f1b..aa059fa 100644 --- a/AccordionBus/AccordionBus/FormAccordionBus.Designer.cs +++ b/AccordionBus/AccordionBus/FormAccordionBus.Designer.cs @@ -57,7 +57,6 @@ buttonCreate.TabIndex = 6; buttonCreate.Text = "Создать автобус с гармошкой"; buttonCreate.UseVisualStyleBackColor = true; - buttonCreate.Click += ButtonCreateAccordionBus_Click; // // buttonUp // @@ -120,7 +119,6 @@ buttonCreateBus.TabIndex = 11; buttonCreateBus.Text = "Создать автобус"; buttonCreateBus.UseVisualStyleBackColor = true; - buttonCreateBus.Click += buttonCreateBus_Click; // // comboBoxStrategy // diff --git a/AccordionBus/AccordionBus/FormAccordionBus.cs b/AccordionBus/AccordionBus/FormAccordionBus.cs index 42eb66a..d3c11bb 100644 --- a/AccordionBus/AccordionBus/FormAccordionBus.cs +++ b/AccordionBus/AccordionBus/FormAccordionBus.cs @@ -20,7 +20,22 @@ public partial class FormAccordionBus : Form /// /// Стратегия перемещения /// - private AbstractStategy? _strategy; + private AbstractStrategy? _strategy; + + /// + /// Получение объекта + /// + public DrawningBus SetBus + { + set + { + _drawningBus = value; + _drawningBus.SetPictureSize(pictureBoxAccordionBus.Width, pictureBoxAccordionBus.Height); + comboBoxStrategy.Enabled = false; + _strategy = null; + Draw(); + } + } /// /// Конструктор формы /// @@ -44,52 +59,6 @@ public partial class FormAccordionBus : Form _drawningBus.DrawTransport(gr); pictureBoxAccordionBus.Image = bmp; } - - /// - ///Создание объекта класса-перемещения - /// - /// Тип создаваемого объётека - - private void CreateObject(string type) - { - Random rnd = new Random(); - switch (type) - { - case nameof(DrawningBus): - _drawningBus = new DrawningBus(rnd.Next(100, 300), rnd.Next(1000, 3000), - Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); - break; - case nameof(DrawningAccordionBus): - _drawningBus = new DrawningAccordionBus(rnd.Next(650, 700), rnd.Next(15760, 16130), - 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))); - break; - default: - return; - } - _drawningBus.SetPictureSize(pictureBoxAccordionBus.Width, pictureBoxAccordionBus.Height); - _drawningBus.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100)); - _strategy = null; - - Draw(); - } - - /// - /// Обработка нажатия кнопки "Создать автобус с гармошкой" - /// - /// - /// - private void ButtonCreateAccordionBus_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningAccordionBus)); - - /// - /// Обработка нажатия кнопки "Создать автобус" - /// - /// - /// - public void buttonCreateBus_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningBus)); - /// /// Перемещение объекта по форме (нажатие кнопок навигации) /// diff --git a/AccordionBus/AccordionBus/FormBusCollection.Designer.cs b/AccordionBus/AccordionBus/FormBusCollection.Designer.cs new file mode 100644 index 0000000..04d0570 --- /dev/null +++ b/AccordionBus/AccordionBus/FormBusCollection.Designer.cs @@ -0,0 +1,175 @@ +namespace AccordionBus +{ + partial class FormBusCollection + { + /// + /// 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(); + buttonDelBus = new Button(); + maskedTextBoxPosition = new MaskedTextBox(); + buttonAddAccordionBus = new Button(); + buttonAddBus = new Button(); + comboBoxSelectorCompany = new ComboBox(); + pictureBox = new PictureBox(); + colorDialog1 = new ColorDialog(); + groupBoxTools.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit(); + SuspendLayout(); + // + // groupBoxTools + // + groupBoxTools.Controls.Add(buttonRefresh); + groupBoxTools.Controls.Add(buttonGoToCheck); + groupBoxTools.Controls.Add(buttonDelBus); + groupBoxTools.Controls.Add(maskedTextBoxPosition); + groupBoxTools.Controls.Add(buttonAddAccordionBus); + groupBoxTools.Controls.Add(buttonAddBus); + groupBoxTools.Controls.Add(comboBoxSelectorCompany); + groupBoxTools.Dock = DockStyle.Right; + groupBoxTools.Location = new Point(612, 0); + groupBoxTools.Name = "groupBoxTools"; + groupBoxTools.Size = new Size(188, 450); + groupBoxTools.TabIndex = 0; + groupBoxTools.TabStop = false; + groupBoxTools.Text = "Инструменты"; + // + // buttonRefresh + // + buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonRefresh.Location = new Point(6, 402); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(170, 42); + buttonRefresh.TabIndex = 7; + buttonRefresh.Text = "Обновить"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += ButtonRefresh_Click; + // + // buttonGoToCheck + // + buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonGoToCheck.Location = new Point(6, 311); + buttonGoToCheck.Name = "buttonGoToCheck"; + buttonGoToCheck.Size = new Size(170, 42); + buttonGoToCheck.TabIndex = 6; + buttonGoToCheck.Text = "Передать на тесты"; + buttonGoToCheck.UseVisualStyleBackColor = true; + buttonGoToCheck.Click += ButtonGoToCheck_Click; + // + // buttonDelBus + // + buttonDelBus.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonDelBus.Location = new Point(6, 236); + buttonDelBus.Name = "buttonDelBus"; + buttonDelBus.Size = new Size(170, 37); + buttonDelBus.TabIndex = 5; + buttonDelBus.Text = "Удалить автомобиль"; + buttonDelBus.UseVisualStyleBackColor = true; + buttonDelBus.Click += ButtonRemoveBus_Click; + // + // maskedTextBoxPosition + // + maskedTextBoxPosition.Location = new Point(6, 207); + maskedTextBoxPosition.Mask = "00"; + maskedTextBoxPosition.Name = "maskedTextBoxPosition"; + maskedTextBoxPosition.Size = new Size(170, 23); + maskedTextBoxPosition.TabIndex = 4; + maskedTextBoxPosition.ValidatingType = typeof(int); + // + // buttonAddAccordionBus + // + buttonAddAccordionBus.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonAddAccordionBus.Location = new Point(6, 160); + buttonAddAccordionBus.Name = "buttonAddAccordionBus"; + buttonAddAccordionBus.Size = new Size(170, 41); + buttonAddAccordionBus.TabIndex = 2; + buttonAddAccordionBus.Text = "Добавление автобуса с гармошкой"; + buttonAddAccordionBus.UseVisualStyleBackColor = true; + buttonAddAccordionBus.Click += ButtonAddAccordionBus_Click; + // + // buttonAddBus + // + buttonAddBus.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonAddBus.Location = new Point(6, 112); + buttonAddBus.Name = "buttonAddBus"; + buttonAddBus.Size = new Size(170, 42); + buttonAddBus.TabIndex = 1; + buttonAddBus.Text = "Добавление атобуса"; + buttonAddBus.UseVisualStyleBackColor = true; + buttonAddBus.Click += ButtonAddBus_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(6, 22); + comboBoxSelectorCompany.Name = "comboBoxSelectorCompany"; + comboBoxSelectorCompany.Size = new Size(170, 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(612, 450); + pictureBox.TabIndex = 3; + pictureBox.TabStop = false; + // + // FormBusCollection + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(pictureBox); + Controls.Add(groupBoxTools); + Name = "FormBusCollection"; + Text = "Коллекция автобусов"; + groupBoxTools.ResumeLayout(false); + groupBoxTools.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); + ResumeLayout(false); + } + + #endregion + + private GroupBox groupBoxTools; + private ComboBox comboBoxSelectorCompany; + private Button buttonDelBus; + private MaskedTextBox maskedTextBoxPosition; + private Button buttonAddAccordionBus; + private Button buttonAddBus; + private PictureBox pictureBox; + private Button buttonRefresh; + private Button buttonGoToCheck; + private ColorDialog colorDialog1; + } +} \ No newline at end of file diff --git a/AccordionBus/AccordionBus/FormBusCollection.cs b/AccordionBus/AccordionBus/FormBusCollection.cs new file mode 100644 index 0000000..5bb439c --- /dev/null +++ b/AccordionBus/AccordionBus/FormBusCollection.cs @@ -0,0 +1,183 @@ +using AccordionBus.CollectionGenericObjects; +using AccordionBus.Drawnings; +using AccordionBus.MovementStrategy; +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 AccordionBus; + +public partial class FormBusCollection : Form +{ + /// + /// Компания + /// + private AbstractCompany? _company = null; + /// + /// Конструктор + /// + public FormBusCollection() + { + InitializeComponent(); + } + /// + /// Выбор компании + /// + /// + /// + private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e) + { + switch (comboBoxSelectorCompany.Text) + { + case "Хранилище": + _company = new BusSharingService(pictureBox.Width, + pictureBox.Height, new MassiveGenericObjects()); + break; + } + } + /// + /// Добавление обычного автомобиля + /// + /// + /// + private void ButtonAddBus_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningBus)); + /// + /// Добавление спортивного автомобиля + /// + /// + /// + private void ButtonAddAccordionBus_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningAccordionBus)); + /// + /// Создание объекта класса-перемещения + /// + /// Тип создаваемого объекта + private void CreateObject(string type) + { + if (_company == null) + { + return; + } + Random random = new(); + DrawningBus drawningBus; + Color bodyColor, additionalColor; + switch (type) + { + case nameof(DrawningBus): + bodyColor = GetColor(random); + drawningBus = new DrawningAccordionBus(random.Next(100, 300), random.Next(1000, 3000), bodyColor); + break; + case nameof(DrawningAccordionBus): + drawningBus = new DrawningBus(random.Next(100, 300),random.Next(1000, 3000), GetColor(random)); + bodyColor = GetColor(random); + additionalColor = GetColor(random); + drawningBus = new DrawningAccordionBus(random.Next(100, + 300), random.Next(1000, 3000), bodyColor, additionalColor, Convert.ToBoolean(random.Next(0,2)), Convert.ToBoolean(random.Next(0, 2))); + break; + default: + return; + } + if (_company + drawningBus) + { + 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 ButtonRemoveBus_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(maskedTextBoxPosition.Text) || _company == null) + { + return; + } + if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) + { + return; + } + int pos = Convert.ToInt32(maskedTextBoxPosition.Text); + if (_company - pos) + { + MessageBox.Show("Объект удален"); + pictureBox.Image = _company.Show(); + } + else + { + MessageBox.Show("Не удалось удалить объект"); + } + } + /// + /// Передача объекта в другую форму + /// + /// + /// + private void ButtonGoToCheck_Click(object sender, EventArgs e) + { + if (_company == null) + { + return; + } + DrawningBus? bus = null; + int counter = 100; + while (bus == null) + { + bus = _company.GetRandomObject(); + counter--; + if (counter <= 0) + { + break; + } + } + if (bus == null) + { + return; + } + FormAccordionBus form = new() + { + SetBus = bus + }; + form.ShowDialog(); + } + /// + /// Перерисовка коллекции + /// + /// + /// + private void ButtonRefresh_Click(object sender, EventArgs e) + { + if (_company == null) + { + return; + } + pictureBox.Image = _company.Show(); + } + +} diff --git a/AccordionBus/AccordionBus/FormBusCollection.resx b/AccordionBus/AccordionBus/FormBusCollection.resx new file mode 100644 index 0000000..818dfae --- /dev/null +++ b/AccordionBus/AccordionBus/FormBusCollection.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + 17, 17 + + \ No newline at end of file diff --git a/AccordionBus/AccordionBus/MovementStrategy/AbstractStategy.cs b/AccordionBus/AccordionBus/MovementStrategy/AbstractStrategy.cs similarity index 99% rename from AccordionBus/AccordionBus/MovementStrategy/AbstractStategy.cs rename to AccordionBus/AccordionBus/MovementStrategy/AbstractStrategy.cs index 532bffa..641f45c 100644 --- a/AccordionBus/AccordionBus/MovementStrategy/AbstractStategy.cs +++ b/AccordionBus/AccordionBus/MovementStrategy/AbstractStrategy.cs @@ -5,7 +5,7 @@ using System.Text; using System.Threading.Tasks; namespace AccordionBus.MovementStrategy; -public abstract class AbstractStategy +public abstract class AbstractStrategy { /// /// Перемещаемый объект diff --git a/AccordionBus/AccordionBus/MovementStrategy/MoveToBorder.cs b/AccordionBus/AccordionBus/MovementStrategy/MoveToBorder.cs index 3f23fb4..0d09994 100644 --- a/AccordionBus/AccordionBus/MovementStrategy/MoveToBorder.cs +++ b/AccordionBus/AccordionBus/MovementStrategy/MoveToBorder.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace AccordionBus.MovementStrategy; -public class MoveToBorder : AbstractStategy +public class MoveToBorder : AbstractStrategy { protected override bool IsTargetDestinaion() { diff --git a/AccordionBus/AccordionBus/MovementStrategy/MoveToCenter.cs b/AccordionBus/AccordionBus/MovementStrategy/MoveToCenter.cs index a637c46..581d006 100644 --- a/AccordionBus/AccordionBus/MovementStrategy/MoveToCenter.cs +++ b/AccordionBus/AccordionBus/MovementStrategy/MoveToCenter.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace AccordionBus.MovementStrategy; -public class MoveToCenter : AbstractStategy +public class MoveToCenter : AbstractStrategy { protected override bool IsTargetDestinaion() { diff --git a/AccordionBus/AccordionBus/Program.cs b/AccordionBus/AccordionBus/Program.cs index ae15180..0f1784d 100644 --- a/AccordionBus/AccordionBus/Program.cs +++ b/AccordionBus/AccordionBus/Program.cs @@ -1,17 +1,19 @@ -namespace AccordionBus +using AccordionBus; +using System.Drawing; + +namespace ProjectAccordionBus; + +internal static class Program { - internal static class Program + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() { - /// - /// The main entry point for the application. - /// - [STAThread] - static void Main() - { - // To customize application configuration such as set high DPI settings or default font, - // see https://aka.ms/applicationconfiguration. - ApplicationConfiguration.Initialize(); - Application.Run(new FormAccordionBus()); - } + // To customize application configuration such as set high DPI settings or default font, + // see https://aka.ms/applicationconfiguration. + ApplicationConfiguration.Initialize(); + Application.Run(new FormBusCollection()); } } \ No newline at end of file