diff --git a/ProjectTrolleybus/ProjectTrolleybus/CollectionGenericObjects/AbstractCompany.cs b/ProjectTrolleybus/ProjectTrolleybus/CollectionGenericObjects/AbstractCompany.cs
new file mode 100644
index 0000000..68673f0
--- /dev/null
+++ b/ProjectTrolleybus/ProjectTrolleybus/CollectionGenericObjects/AbstractCompany.cs
@@ -0,0 +1,103 @@
+using ProjectTrolleybus.Drawnings;
+
+
+namespace ProjectTrolleybus.CollectionGenericObjects;
+
+public abstract class AbstractCompany
+{
+ ///
+ /// Размер места (Ширина)
+ ///
+ protected readonly int _placeSizeWidth = 225;
+
+ ///
+ /// Размер места (Высота)
+ ///
+ protected readonly int _placeSizeHeight = 55;
+
+ ///
+ /// Ширина окна
+ ///
+ protected readonly int _pictureWidth;
+
+ ///
+ /// Высота окна
+ ///
+ protected readonly int _pictureHeight;
+
+ ///
+ /// Коллекция автобусов
+ ///
+ protected ICollectionGenericObjects? _collection = null;
+
+ ///
+ /// Вычисление максимального кол-ва объектов которое можно разместить в окне
+ ///
+ private int GetMaxCount => _pictureWidth * _pictureHeight / (_placeSizeWidth);
+
+ ///
+ /// Конструктор
+ ///
+ /// Ширина окна
+ /// Высота окна
+ /// Коллекция автобусов
+ public AbstractCompany(int picWidth, int picHeight, ICollectionGenericObjects collection)
+ {
+ _pictureWidth = picWidth;
+ _pictureHeight = picHeight;
+ _collection = collection;
+ _collection.SetMaxCount = GetMaxCount;
+ }
+
+ ///
+ /// Перегрузка оператора сложения для класса
+ ///
+ /// Компания
+ /// Номер добавляемого объекта
+ ///
+ public static int operator +(AbstractCompany company, DrawningTrolleyB trolleyB)
+ {
+ return company._collection.Insert(trolleyB);
+ }
+
+ ///
+ /// Перегрузка оператора удаления для класса
+ ///
+ /// Компания
+ /// Номер удаляемого объекта
+ ///
+ public static DrawningTrolleyB operator -(AbstractCompany company, int position)
+ {
+ return company._collection.Remove(position);
+ }
+
+ ///
+ /// Получение случайного объекта из коллекции
+ ///
+ ///
+ public DrawningTrolleyB? GetRandomObject()
+ {
+ Random rnd = new();
+ return _collection?.Get(rnd.Next(GetMaxCount));
+ }
+
+ public Bitmap? Show()
+ {
+ Bitmap bitmap = new(_pictureWidth, _pictureHeight);
+ Graphics graphics = Graphics.FromImage(bitmap);
+ DrawBackground(graphics);
+
+ SetObjectPosition();
+ for (int i = 0; i < (_collection?.Count ?? 0); ++i)
+ {
+ DrawningTrolleyB? obj = _collection?.Get(i);
+ obj?.DrawTransport(graphics);
+ }
+
+ return bitmap;
+ }
+
+ protected abstract void DrawBackground(Graphics g);
+
+ protected abstract void SetObjectPosition();
+}
diff --git a/ProjectTrolleybus/ProjectTrolleybus/CollectionGenericObjects/ICollectionGenericObjects.cs b/ProjectTrolleybus/ProjectTrolleybus/CollectionGenericObjects/ICollectionGenericObjects.cs
index 8223254..515fb9d 100644
--- a/ProjectTrolleybus/ProjectTrolleybus/CollectionGenericObjects/ICollectionGenericObjects.cs
+++ b/ProjectTrolleybus/ProjectTrolleybus/CollectionGenericObjects/ICollectionGenericObjects.cs
@@ -1,10 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace ProjectTrolleybus.CollectionGenericObjects;
+namespace ProjectTrolleybus.CollectionGenericObjects;
///
/// Интерфейс описания действий для набора хранимых объектов
@@ -23,19 +17,26 @@ public interface ICollectionGenericObjects
///
int SetMaxCount { set; }
+ ///
+ /// Добавление объекта в коллецию
+ ///
+ ///
+ ///
+ int Insert(T obj);
+
///
/// Добавление объекта в коллекцию
///
/// Добавляемый объект
/// true - вставка прошла удачно, false - вставка не удалась
- bool Insert(T obj, int position);
+ int Insert(T obj, int position);
///
/// Удаление объекта из коллекции с конкретной позиции
///
/// Позиция
/// true - удаление прошло удачно, false - удаление не удалось
- bool Remove(int position);
+ T? Remove(int position);
///
/// Получение объекта и з позиции
diff --git a/ProjectTrolleybus/ProjectTrolleybus/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectTrolleybus/ProjectTrolleybus/CollectionGenericObjects/MassiveGenericObjects.cs
index 29be751..b070e0d 100644
--- a/ProjectTrolleybus/ProjectTrolleybus/CollectionGenericObjects/MassiveGenericObjects.cs
+++ b/ProjectTrolleybus/ProjectTrolleybus/CollectionGenericObjects/MassiveGenericObjects.cs
@@ -1,10 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace ProjectTrolleybus.CollectionGenericObjects;
+namespace ProjectTrolleybus.CollectionGenericObjects;
///
/// Параметризированный набор объектов
@@ -33,29 +27,80 @@ public class MassiveGenericObjects : ICollectionGenericObjects
public T? Get(int position)
{
// TODO проверка позиции
+ if (position >= _collection.Length || position < 0)
+ {
+ return null;
+ }
return _collection[position];
}
- public bool Insert(T obj)
+ public int Insert(T obj)
{
// TODO вставка в свободное место набора
- return false;
+ int index = 0;
+ while (index < _collection.Length)
+ {
+ if (_collection[index] == null)
+ {
+ _collection[index] = obj;
+ return index;
+ }
+ index++;
+ }
+ return -1;
}
- public bool Insert(T obj, int position)
+ public int Insert(T obj, int position)
{
// TODO проверка позиции
// TODO проверка, что элемент массива по этой позиции пустой, если нет, то
- // ищется свободное место после этой позиции и идёт вставка туда
+ // ищется свободное место после этой позиции и идет вставка туда
// если нет после, ищем до
// TODO вставка
- return false;
+ if (position >= _collection.Length || position < 0)
+ return -1;
+
+ // TODO проверка, что элемент массива по этой позиции пустой, если нет, то
+ if (_collection[position] != null)
+ {
+ // проверка, что после вставляемого элемента в массиве есть пустой элемент
+ int nullIndex = -1;
+ for (int i = position + 1; i < Count; i++)
+ {
+ if (_collection[i] == null)
+ {
+ nullIndex = i;
+ break;
+ }
+ }
+ // Если пустого элемента нет, то выходим
+ if (nullIndex < 0)
+ {
+ return -1;
+ }
+ // сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента
+ int j = nullIndex - 1;
+ while (j >= position)
+ {
+ _collection[j + 1] = _collection[j];
+ j--;
+ }
+ }
+ // TODO вставка по позиции
+ _collection[position] = obj;
+ return position;
}
- public bool Remove(int position)
+ public T? Remove(int position)
{
// TODO проверка позиции
// TODO удаление объекта из массива, присвоив элементу массива значение null
- return true;
+ if (position >= _collection.Length || position < 0)
+ {
+ return null;
+ }
+ T temp = _collection[position];
+ _collection[position] = null;
+ return temp;
}
}
diff --git a/ProjectTrolleybus/ProjectTrolleybus/CollectionGenericObjects/TrolleyBSharingService.cs b/ProjectTrolleybus/ProjectTrolleybus/CollectionGenericObjects/TrolleyBSharingService.cs
new file mode 100644
index 0000000..84b49a1
--- /dev/null
+++ b/ProjectTrolleybus/ProjectTrolleybus/CollectionGenericObjects/TrolleyBSharingService.cs
@@ -0,0 +1,55 @@
+using ProjectTrolleybus.Drawnings;
+
+namespace ProjectTrolleybus.CollectionGenericObjects;
+
+public class TrolleyBCarSharingService : AbstractCompany
+{
+ public TrolleyBCarSharingService(int picWidth, int picHeight, ICollectionGenericObjects collection) : base(picWidth, picHeight, collection)
+ {
+ }
+
+
+ protected override void DrawBackground(Graphics g)
+ {
+ Pen pen = new(Color.Black, 3);
+ for (int i = 0; i <= _pictureWidth / _placeSizeWidth; i++)
+ {
+ for (int j = 0; j <= _pictureHeight / _placeSizeHeight; 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 SetObjectPosition()
+ {
+ int width = _pictureWidth / _placeSizeWidth;
+ int height = _pictureHeight / _placeSizeHeight;
+
+ int posWidth = width;
+ int posHeight = 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 * posWidth + 4, posHeight * _placeSizeHeight + 4, width, height);
+ }
+
+ if (posWidth > 0)
+ posWidth--;
+ else
+ {
+ posWidth = width;
+ posHeight++;
+ }
+ if (posHeight > height)
+ {
+ return;
+ }
+ }
+ }
+}
+
diff --git a/ProjectTrolleybus/ProjectTrolleybus/Drawnings/DrawningTrolleyB.cs b/ProjectTrolleybus/ProjectTrolleybus/Drawnings/DrawningTrolleyB.cs
index 84f98ce..0ff37af 100644
--- a/ProjectTrolleybus/ProjectTrolleybus/Drawnings/DrawningTrolleyB.cs
+++ b/ProjectTrolleybus/ProjectTrolleybus/Drawnings/DrawningTrolleyB.cs
@@ -1,9 +1,4 @@
using ProjectTrolleybus.Entities;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
namespace ProjectTrolleybus.Drawnings;
diff --git a/ProjectTrolleybus/ProjectTrolleybus/Drawnings/DrawningTrolleybus.cs b/ProjectTrolleybus/ProjectTrolleybus/Drawnings/DrawningTrolleybus.cs
index 2c09a7f..d9db6e6 100644
--- a/ProjectTrolleybus/ProjectTrolleybus/Drawnings/DrawningTrolleybus.cs
+++ b/ProjectTrolleybus/ProjectTrolleybus/Drawnings/DrawningTrolleybus.cs
@@ -1,5 +1,4 @@
using ProjectTrolleybus.Entities;
-using System.Drawing;
namespace ProjectTrolleybus.Drawnings;
diff --git a/ProjectTrolleybus/ProjectTrolleybus/FormTrolleyBCollection.Designer.cs b/ProjectTrolleybus/ProjectTrolleybus/FormTrolleyBCollection.Designer.cs
new file mode 100644
index 0000000..06c0de7
--- /dev/null
+++ b/ProjectTrolleybus/ProjectTrolleybus/FormTrolleyBCollection.Designer.cs
@@ -0,0 +1,174 @@
+namespace ProjectTrolleybus
+{
+ partial class FormTrolleyBCollection
+ {
+ ///
+ /// 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();
+ buttonRemoveTrolleyB = new Button();
+ maskedTextBoxPosition = new MaskedTextBox();
+ buttonAddTrolleybus = new Button();
+ buttonAddTrolleyB = 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(buttonRemoveTrolleyB);
+ groupBoxTools.Controls.Add(maskedTextBoxPosition);
+ groupBoxTools.Controls.Add(buttonAddTrolleybus);
+ groupBoxTools.Controls.Add(buttonAddTrolleyB);
+ groupBoxTools.Controls.Add(comboBoxSelectorCompany);
+ groupBoxTools.Dock = DockStyle.Right;
+ groupBoxTools.Location = new Point(861, 0);
+ groupBoxTools.Name = "groupBoxTools";
+ groupBoxTools.Size = new Size(201, 645);
+ groupBoxTools.TabIndex = 0;
+ groupBoxTools.TabStop = false;
+ groupBoxTools.Text = "Инструменты";
+ //
+ // buttonRefresh
+ //
+ buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonRefresh.Location = new Point(6, 544);
+ buttonRefresh.Name = "buttonRefresh";
+ buttonRefresh.Size = new Size(189, 41);
+ 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, 362);
+ buttonGoToCheck.Name = "buttonGoToCheck";
+ buttonGoToCheck.Size = new Size(189, 41);
+ buttonGoToCheck.TabIndex = 5;
+ buttonGoToCheck.Text = "Передать на тесты";
+ buttonGoToCheck.UseVisualStyleBackColor = true;
+ buttonGoToCheck.Click += ButtonGoToCheck_Click;
+ //
+ // buttonRemoveTrolleyB
+ //
+ buttonRemoveTrolleyB.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonRemoveTrolleyB.Location = new Point(6, 257);
+ buttonRemoveTrolleyB.Name = "buttonRemoveTrolleyB";
+ buttonRemoveTrolleyB.Size = new Size(189, 41);
+ buttonRemoveTrolleyB.TabIndex = 4;
+ buttonRemoveTrolleyB.Text = "Удалить троллейбус";
+ buttonRemoveTrolleyB.UseVisualStyleBackColor = true;
+ buttonRemoveTrolleyB.Click += ButtonRemoveTrolleyB_Click;
+ //
+ // maskedTextBoxPosition
+ //
+ maskedTextBoxPosition.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ maskedTextBoxPosition.Location = new Point(6, 228);
+ maskedTextBoxPosition.Mask = "00";
+ maskedTextBoxPosition.Name = "maskedTextBoxPosition";
+ maskedTextBoxPosition.Size = new Size(189, 23);
+ maskedTextBoxPosition.TabIndex = 3;
+ maskedTextBoxPosition.ValidatingType = typeof(int);
+ //
+ // buttonAddTrolleybus
+ //
+ buttonAddTrolleybus.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonAddTrolleybus.Location = new Point(6, 153);
+ buttonAddTrolleybus.Name = "buttonAddTrolleybus";
+ buttonAddTrolleybus.Size = new Size(189, 41);
+ buttonAddTrolleybus.TabIndex = 2;
+ buttonAddTrolleybus.Text = "Добавление улучшенного троллейбуса";
+ buttonAddTrolleybus.UseVisualStyleBackColor = true;
+ buttonAddTrolleybus.Click += ButtonAddTrolleybus_Click;
+ //
+ // buttonAddTrolleyB
+ //
+ buttonAddTrolleyB.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonAddTrolleyB.Location = new Point(6, 106);
+ buttonAddTrolleyB.Name = "buttonAddTrolleyB";
+ buttonAddTrolleyB.Size = new Size(189, 41);
+ buttonAddTrolleyB.TabIndex = 1;
+ buttonAddTrolleyB.Text = "Добавление троллейбуса";
+ buttonAddTrolleyB.UseVisualStyleBackColor = true;
+ buttonAddTrolleyB.Click += ButtonAddTrolleyB_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(189, 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(861, 645);
+ pictureBox.TabIndex = 1;
+ pictureBox.TabStop = false;
+ //
+ // FormTrolleyBCollection
+ //
+ AutoScaleDimensions = new SizeF(7F, 15F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(1062, 645);
+ Controls.Add(pictureBox);
+ Controls.Add(groupBoxTools);
+ Name = "FormTrolleyBCollection";
+ Text = "Коллекция троллейбусов";
+ groupBoxTools.ResumeLayout(false);
+ groupBoxTools.PerformLayout();
+ ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
+ ResumeLayout(false);
+ }
+
+ #endregion
+
+ private GroupBox groupBoxTools;
+ private ComboBox comboBoxSelectorCompany;
+ private Button buttonAddTrolleybus;
+ private Button buttonAddTrolleyB;
+ private PictureBox pictureBox;
+ private Button buttonRemoveTrolleyB;
+ private MaskedTextBox maskedTextBoxPosition;
+ private Button buttonRefresh;
+ private Button buttonGoToCheck;
+ }
+}
\ No newline at end of file
diff --git a/ProjectTrolleybus/ProjectTrolleybus/FormTrolleyBCollection.cs b/ProjectTrolleybus/ProjectTrolleybus/FormTrolleyBCollection.cs
new file mode 100644
index 0000000..2086e70
--- /dev/null
+++ b/ProjectTrolleybus/ProjectTrolleybus/FormTrolleyBCollection.cs
@@ -0,0 +1,193 @@
+using ProjectTrolleybus.CollectionGenericObjects;
+using ProjectTrolleybus.Drawnings;
+
+namespace ProjectTrolleybus;
+
+///
+///
+///
+public partial class FormTrolleyBCollection : Form
+{
+ ///
+ ///
+ ///
+ private AbstractCompany? _company = null;
+
+ ///
+ /// Конструктор
+ ///
+ public FormTrolleyBCollection()
+ {
+ InitializeComponent();
+ }
+
+ ///
+ /// Выбор компании
+ ///
+ ///
+ ///
+ private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ switch (comboBoxSelectorCompany.Text)
+ {
+ case "Хранилище":
+ _company = new TrolleyBCarSharingService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects());
+ break;
+ }
+
+ }
+
+ ///
+ /// Добавление троллейбуса
+ ///
+ ///
+ ///
+ private void ButtonAddTrolleyB_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningTrolleyB));
+
+ ///
+ /// Добавление улучшенного троллейбуса
+ ///
+ ///
+ ///
+ private void ButtonAddTrolleybus_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningTrolleybus));
+
+ ///
+ /// Создание объекта класса-перемещения
+ ///
+ /// Тип создания объекта
+ private void CreateObject(string type)
+ {
+ if (_company == null)
+ {
+ return;
+ }
+
+ Random random = new();
+ DrawningTrolleyB drawningTrolleyB;
+ switch (type)
+ {
+ case nameof(DrawningTrolleyB):
+ drawningTrolleyB = new DrawningTrolleyB(random.Next(100, 300), random.Next(1000, 3000), GetColor(random));
+ break;
+ case nameof(DrawningTrolleybus):
+ drawningTrolleyB = new DrawningTrolleybus(random.Next(100, 300), random.Next(1000, 3000),
+ GetColor(random),
+ GetColor(random),
+ Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
+ break;
+ default:
+ return;
+ }
+
+ if (_company + drawningTrolleyB != -1)
+ {
+ MessageBox.Show("Объект добавлен");
+ pictureBox.Image = _company.Show();
+ }
+
+ else
+ {
+ MessageBox.Show("Не удалось добавить объект");
+ }
+ }
+
+ ///
+ /// Выбор цвета
+ ///
+ ///
+ ///
+ private static Color GetColor(Random random)
+ {
+ Color color = Color.FromArgb(random.Next(0, 255), random.Next(0, 255), random.Next(0, 255));
+ ColorDialog dialog = new();
+ if (dialog.ShowDialog() == DialogResult.OK)
+ {
+ color = dialog.Color;
+ }
+
+ return color;
+ }
+
+ ///
+ /// Удаление троллейбуса с места
+ ///
+ ///
+ ///
+ private void ButtonRemoveTrolleyB_Click(object sender, EventArgs e)
+ {
+
+ if (string.IsNullOrEmpty(maskedTextBoxPosition.Text) || _company == null)
+ {
+ return;
+ }
+
+ if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
+ {
+ return;
+ }
+
+ int pos = Convert.ToInt32(maskedTextBoxPosition.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;
+ }
+
+ DrawningTrolleyB? trolleyB = null;
+ int counter = 100;
+ while (trolleyB == null)
+ {
+ trolleyB = _company.GetRandomObject();
+ counter--;
+ if (counter <= 0)
+ {
+ break;
+ }
+ }
+
+ if (trolleyB == null)
+ {
+ return;
+ }
+
+ FormTrolleybus form = new()
+ {
+ SetTrolleyB = trolleyB,
+ };
+ form.ShowDialog();
+ }
+
+ ///
+ /// Обновление коллекции
+ ///
+ ///
+ ///
+ private void ButtonRefresh_Click(object sender, EventArgs e)
+ {
+ if (_company == null)
+ {
+ return;
+ }
+
+ pictureBox.Image = _company.Show();
+
+ }
+}
diff --git a/ProjectTrolleybus/ProjectTrolleybus/FormTrolleyBCollection.resx b/ProjectTrolleybus/ProjectTrolleybus/FormTrolleyBCollection.resx
new file mode 100644
index 0000000..af32865
--- /dev/null
+++ b/ProjectTrolleybus/ProjectTrolleybus/FormTrolleyBCollection.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/ProjectTrolleybus/ProjectTrolleybus/FormTrolleybus.Designer.cs b/ProjectTrolleybus/ProjectTrolleybus/FormTrolleybus.Designer.cs
index 95e9c34..b38fca8 100644
--- a/ProjectTrolleybus/ProjectTrolleybus/FormTrolleybus.Designer.cs
+++ b/ProjectTrolleybus/ProjectTrolleybus/FormTrolleybus.Designer.cs
@@ -29,12 +29,10 @@
private void InitializeComponent()
{
pictureBoxTrolleybus = new PictureBox();
- buttonCreateTrolleybus = new Button();
buttonLeft = new Button();
buttonDown = new Button();
buttonRight = new Button();
buttonUp = new Button();
- buttonCreateTrolleyB = new Button();
comboBoxStrategy = new ComboBox();
buttonStrategyStep = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxTrolleybus).BeginInit();
@@ -49,17 +47,6 @@
pictureBoxTrolleybus.TabIndex = 0;
pictureBoxTrolleybus.TabStop = false;
//
- // buttonCreateTrolleybus
- //
- buttonCreateTrolleybus.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
- buttonCreateTrolleybus.Location = new Point(22, 406);
- buttonCreateTrolleybus.Name = "buttonCreateTrolleybus";
- buttonCreateTrolleybus.Size = new Size(204, 23);
- buttonCreateTrolleybus.TabIndex = 1;
- buttonCreateTrolleybus.Text = "Создать улучшенный троллейбус";
- buttonCreateTrolleybus.UseVisualStyleBackColor = true;
- buttonCreateTrolleybus.Click += ButtonCreateTrolleybus_Click;
- //
// buttonLeft
//
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
@@ -108,17 +95,6 @@
buttonUp.UseVisualStyleBackColor = true;
buttonUp.Click += ButtonMove_Click;
//
- // buttonCreateTrolleyB
- //
- buttonCreateTrolleyB.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
- buttonCreateTrolleyB.Location = new Point(246, 406);
- buttonCreateTrolleyB.Name = "buttonCreateTrolleyB";
- buttonCreateTrolleyB.Size = new Size(130, 23);
- buttonCreateTrolleyB.TabIndex = 6;
- buttonCreateTrolleyB.Text = "Создать троллейбус";
- buttonCreateTrolleyB.UseVisualStyleBackColor = true;
- buttonCreateTrolleyB.Click += ButtonCreateTrolleyB_Click;
- //
// comboBoxStrategy
//
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
@@ -146,12 +122,10 @@
ClientSize = new Size(800, 450);
Controls.Add(buttonStrategyStep);
Controls.Add(comboBoxStrategy);
- Controls.Add(buttonCreateTrolleyB);
Controls.Add(buttonUp);
Controls.Add(buttonRight);
Controls.Add(buttonDown);
Controls.Add(buttonLeft);
- Controls.Add(buttonCreateTrolleybus);
Controls.Add(pictureBoxTrolleybus);
Name = "FormTrolleybus";
Text = "Троллейбус";
@@ -162,12 +136,10 @@
#endregion
private PictureBox pictureBoxTrolleybus;
- private Button buttonCreateTrolleybus;
private Button buttonLeft;
private Button buttonDown;
private Button buttonRight;
private Button buttonUp;
- private Button buttonCreateTrolleyB;
private ComboBox comboBoxStrategy;
private Button buttonStrategyStep;
}
diff --git a/ProjectTrolleybus/ProjectTrolleybus/FormTrolleybus.cs b/ProjectTrolleybus/ProjectTrolleybus/FormTrolleybus.cs
index ba58b73..02b5e60 100644
--- a/ProjectTrolleybus/ProjectTrolleybus/FormTrolleybus.cs
+++ b/ProjectTrolleybus/ProjectTrolleybus/FormTrolleybus.cs
@@ -19,6 +19,18 @@ public partial class FormTrolleybus : Form
///
private AbstractStrategy? _strategy;
+ public DrawningTrolleyB SetTrolleyB
+ {
+ set
+ {
+ _drawningTrolleyB = value;
+ _drawningTrolleyB.SetPictureSize(pictureBoxTrolleybus.Width, pictureBoxTrolleybus.Height);
+ comboBoxStrategy.Enabled = true;
+ _strategy = null;
+ Draw();
+ }
+ }
+
///
/// Конструктор формы
///
@@ -39,58 +51,6 @@ public partial class FormTrolleybus : Form
pictureBoxTrolleybus.Image = bmp;
}
-
- ///
- /// Создание объекта класса-перемещения
- ///
- /// Тип создания объекта
- private void CreateObject(string type)
- {
- Random random = new();
- switch (type)
- {
- case nameof(DrawningTrolleyB):
- _drawningTrolleyB = new DrawningTrolleyB(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(DrawningTrolleybus):
- _drawningTrolleyB = new DrawningTrolleybus(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;
- }
-
- _drawningTrolleyB.SetPictureSize(pictureBoxTrolleybus.Width, pictureBoxTrolleybus.Height);
- _drawningTrolleyB.SetPosition(random.Next(10, 100), random.Next(10, 100), pictureBoxTrolleybus.Width, pictureBoxTrolleybus.Height);
- _strategy = null;
- comboBoxStrategy.Enabled = true;
-
- Draw();
- }
-
- ///
- /// Обработка нажатия создать улучшеный троллейбус
- ///
- ///
- ///
- private void ButtonCreateTrolleybus_Click(object sender, EventArgs e)
- {
- CreateObject(nameof(DrawningTrolleybus));
- }
-
- ///
- /// Обработка нажатия создать троллейбус
- ///
- ///
- ///
- private void ButtonCreateTrolleyB_Click(object sender, EventArgs e)
- {
- CreateObject(nameof(DrawningTrolleyB));
- }
-
///
/// Перемещение объекта по кнопке (нажатие кнопок навигации)
///
diff --git a/ProjectTrolleybus/ProjectTrolleybus/Program.cs b/ProjectTrolleybus/ProjectTrolleybus/Program.cs
index 8a49dfe..bfe6ed4 100644
--- a/ProjectTrolleybus/ProjectTrolleybus/Program.cs
+++ b/ProjectTrolleybus/ProjectTrolleybus/Program.cs
@@ -11,7 +11,7 @@ namespace ProjectTrolleybus
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
- Application.Run(new FormTrolleybus());
+ Application.Run(new FormTrolleyBCollection());
}
}
}
\ No newline at end of file