diff --git a/ProjectByldozer/ProjectByldozer/CollectionGenericObjects/AbstractCompany.cs b/ProjectByldozer/ProjectByldozer/CollectionGenericObjects/AbstractCompany.cs
new file mode 100644
index 0000000..54cce19
--- /dev/null
+++ b/ProjectByldozer/ProjectByldozer/CollectionGenericObjects/AbstractCompany.cs
@@ -0,0 +1,117 @@
+///using ProjectByldozer.CollectionGenericObjects;
+using ProjectByldozer.Drawnings;
+
+namespace ProjectByldozer.CollectionGenericObjects;
+
+///
+/// Абстракция компании, хранящий коллекцию автомобилей
+///
+public abstract class AbstractCompany
+{
+ ///
+ /// Размер места (ширина)
+ ///
+ protected readonly int _placeSizeWidth = 210;
+
+ ///
+ /// Размер места (высота)
+ ///
+ protected readonly int _placeSizeHeight = 83;
+
+ ///
+ /// Ширина окна
+ ///
+ 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, DrawningTrackedCar TrackedCar)
+ {
+ return company._collection.Insert(TrackedCar);
+ }
+
+ ///
+ /// Перегрузка оператора удаления для класса
+ ///
+ /// Компания
+ /// Номер удаляемого объекта
+ ///
+ public static DrawningTrackedCar operator -(AbstractCompany company, int position)
+ {
+ return company._collection?.Remove(position);
+ }
+
+ ///
+ /// Получение случайного объекта из коллекции
+ ///
+ ///
+ public DrawningTrackedCar? 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)
+ {
+ DrawningTrackedCar? obj = _collection?.Get(i);
+ obj?.DrawTransport(graphics);
+ }
+
+ return bitmap;
+ }
+
+ ///
+ /// Вывод заднего фона
+ ///
+ ///
+ protected abstract void DrawBackgound(Graphics g);
+
+ ///
+ /// Расстановка объектов
+ ///
+ protected abstract void SetObjectsPosition();
+}
\ No newline at end of file
diff --git a/ProjectByldozer/ProjectByldozer/CollectionGenericObjects/ICollectionGenericObjects.cs b/ProjectByldozer/ProjectByldozer/CollectionGenericObjects/ICollectionGenericObjects.cs
new file mode 100644
index 0000000..884e418
--- /dev/null
+++ b/ProjectByldozer/ProjectByldozer/CollectionGenericObjects/ICollectionGenericObjects.cs
@@ -0,0 +1,47 @@
+namespace ProjectByldozer.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/ProjectByldozer/ProjectByldozer/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectByldozer/ProjectByldozer/CollectionGenericObjects/MassiveGenericObjects.cs
new file mode 100644
index 0000000..8a8fd2e
--- /dev/null
+++ b/ProjectByldozer/ProjectByldozer/CollectionGenericObjects/MassiveGenericObjects.cs
@@ -0,0 +1,114 @@
+namespace ProjectByldozer.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/ProjectByldozer/ProjectByldozer/CollectionGenericObjects/TrackedCarGarage.cs b/ProjectByldozer/ProjectByldozer/CollectionGenericObjects/TrackedCarGarage.cs
new file mode 100644
index 0000000..1de7b3f
--- /dev/null
+++ b/ProjectByldozer/ProjectByldozer/CollectionGenericObjects/TrackedCarGarage.cs
@@ -0,0 +1,66 @@
+
+using ProjectByldozer.Drawnings;
+namespace ProjectByldozer.CollectionGenericObjects;
+public class TrackedCarGarage : AbstractCompany
+{
+ ///
+ /// Конструктор
+ ///
+ ///
+ ///
+ ///
+ public TrackedCarGarage(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 = height - 1;
+
+ 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 < 0)
+ {
+ return;
+ }
+ }
+ }
+
+
+}
+
+
diff --git a/ProjectByldozer/ProjectByldozer/FormByldozer.Designer.cs b/ProjectByldozer/ProjectByldozer/FormByldozer.Designer.cs
index b410c1f..d676f48 100644
--- a/ProjectByldozer/ProjectByldozer/FormByldozer.Designer.cs
+++ b/ProjectByldozer/ProjectByldozer/FormByldozer.Designer.cs
@@ -29,12 +29,10 @@
private void InitializeComponent()
{
pictureBoxByldozer = new PictureBox();
- buttonCreateByldozer = new Button();
buttonLeft = new Button();
buttonUp = new Button();
buttonDown = new Button();
buttonRight = new Button();
- buttonCreatecar = new Button();
comboBoxStrategy = new ComboBox();
buttonStrategyStep = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxByldozer).BeginInit();
@@ -45,29 +43,16 @@
pictureBoxByldozer.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
pictureBoxByldozer.Location = new Point(-2, -1);
pictureBoxByldozer.Name = "pictureBoxByldozer";
- pictureBoxByldozer.Size = new Size(751, 406);
+ pictureBoxByldozer.Size = new Size(774, 421);
pictureBoxByldozer.TabIndex = 0;
pictureBoxByldozer.TabStop = false;
- pictureBoxByldozer.Click += pictureBoxByldozer_Click;
- //
- // buttonCreateByldozer
- //
- buttonCreateByldozer.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
- buttonCreateByldozer.Location = new Point(26, 367);
- buttonCreateByldozer.Name = "buttonCreateByldozer";
- buttonCreateByldozer.Size = new Size(120, 26);
- buttonCreateByldozer.TabIndex = 1;
- buttonCreateByldozer.Text = "Создать бульдозер";
- buttonCreateByldozer.TextAlign = ContentAlignment.TopRight;
- buttonCreateByldozer.UseVisualStyleBackColor = true;
- buttonCreateByldozer.Click += ButtonCreateByldozer_Click;
//
// buttonLeft
//
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonLeft.BackgroundImage = Properties.Resources.arrowLeft;
buttonLeft.BackgroundImageLayout = ImageLayout.Stretch;
- buttonLeft.Location = new Point(620, 370);
+ buttonLeft.Location = new Point(643, 385);
buttonLeft.Name = "buttonLeft";
buttonLeft.Size = new Size(35, 35);
buttonLeft.TabIndex = 2;
@@ -79,7 +64,7 @@
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonUp.BackgroundImage = Properties.Resources.arrowUp;
buttonUp.BackgroundImageLayout = ImageLayout.Stretch;
- buttonUp.Location = new Point(661, 329);
+ buttonUp.Location = new Point(684, 344);
buttonUp.Name = "buttonUp";
buttonUp.Size = new Size(35, 35);
buttonUp.TabIndex = 3;
@@ -91,7 +76,7 @@
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonDown.BackgroundImage = Properties.Resources.arrowDown;
buttonDown.BackgroundImageLayout = ImageLayout.Stretch;
- buttonDown.Location = new Point(661, 370);
+ buttonDown.Location = new Point(684, 385);
buttonDown.Name = "buttonDown";
buttonDown.Size = new Size(35, 35);
buttonDown.TabIndex = 4;
@@ -103,25 +88,13 @@
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonRight.BackgroundImage = Properties.Resources.arrowRight;
buttonRight.BackgroundImageLayout = ImageLayout.Stretch;
- buttonRight.Location = new Point(702, 370);
+ buttonRight.Location = new Point(725, 385);
buttonRight.Name = "buttonRight";
buttonRight.Size = new Size(35, 35);
buttonRight.TabIndex = 5;
buttonRight.UseVisualStyleBackColor = true;
buttonRight.Click += ButtonMove_Click;
//
- // buttonCreatecar
- //
- buttonCreatecar.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
- buttonCreatecar.Location = new Point(164, 367);
- buttonCreatecar.Name = "buttonCreatecar";
- buttonCreatecar.Size = new Size(179, 26);
- buttonCreatecar.TabIndex = 6;
- buttonCreatecar.Text = "Создать гусеничную машину";
- buttonCreatecar.TextAlign = ContentAlignment.TopRight;
- buttonCreatecar.UseVisualStyleBackColor = true;
- buttonCreatecar.Click += ButtonCreatecar_Click;
- //
// comboBoxStrategy
//
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
@@ -146,15 +119,13 @@
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
- ClientSize = new Size(749, 405);
+ ClientSize = new Size(772, 420);
Controls.Add(buttonStrategyStep);
Controls.Add(comboBoxStrategy);
- Controls.Add(buttonCreatecar);
Controls.Add(buttonRight);
Controls.Add(buttonDown);
Controls.Add(buttonUp);
Controls.Add(buttonLeft);
- Controls.Add(buttonCreateByldozer);
Controls.Add(pictureBoxByldozer);
Name = "FormByldozer";
Text = "Бульдозер";
@@ -165,12 +136,10 @@
#endregion
private PictureBox pictureBoxByldozer;
- private Button buttonCreateByldozer;
private Button buttonLeft;
private Button buttonUp;
private Button buttonDown;
private Button buttonRight;
- private Button buttonCreatecar;
private ComboBox comboBoxStrategy;
private Button buttonStrategyStep;
}
diff --git a/ProjectByldozer/ProjectByldozer/FormByldozer.cs b/ProjectByldozer/ProjectByldozer/FormByldozer.cs
index f12300e..7d9b268 100644
--- a/ProjectByldozer/ProjectByldozer/FormByldozer.cs
+++ b/ProjectByldozer/ProjectByldozer/FormByldozer.cs
@@ -17,6 +17,17 @@ public partial class FormByldozer : Form
/// стратегия перемещения
///
private AbstractStrategy? _strategy;
+ public DrawningTrackedCar SetTrackedCar
+ {
+ set
+ {
+ _drawningTrackedCar = value;
+ _drawningTrackedCar.SetPictureSize(pictureBoxByldozer.Width, pictureBoxByldozer.Height);
+ comboBoxStrategy.Enabled = true;
+ _strategy = null;
+ Draw();
+ }
+ }
///
/// инциализация формы
///
@@ -42,49 +53,6 @@ public partial class FormByldozer : Form
}
- ///
- /// Создание объекта класса-перемещения
- ///
- /// Тип создаваемого объекта
- private void CreateObject(string type)
- {
- Random random = new();
- switch (type)
- {
- case nameof(DrawningTrackedCar):
- _drawningTrackedCar = new DrawningTrackedCar(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(DrawningByldozer):
- _drawningTrackedCar = new DrawningByldozer(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;
- }
-
- _drawningTrackedCar.SetPictureSize(pictureBoxByldozer.Width, pictureBoxByldozer.Height);
- _drawningTrackedCar.SetPosition(random.Next(10, 100), random.Next(10, 100));
- _strategy = null;
- comboBoxStrategy.Enabled = true;
- Draw();
- }
- ///
- /// обработка нажатия кнопки "создать бульдозер"
- ///
- ///
- ///
- private void ButtonCreateByldozer_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningByldozer));
-
- ///
- /// обработка нажатия кнопки "создать машину"
- ///
- ///
- ///
- private void ButtonCreatecar_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningTrackedCar));
-
///
/// премещение объекта по форме
///
@@ -158,9 +126,6 @@ public partial class FormByldozer : Form
}
}
- private void pictureBoxByldozer_Click(object sender, EventArgs e)
- {
- }
}
diff --git a/ProjectByldozer/ProjectByldozer/FormCarCollection.Designer.cs b/ProjectByldozer/ProjectByldozer/FormCarCollection.Designer.cs
new file mode 100644
index 0000000..5a0735f
--- /dev/null
+++ b/ProjectByldozer/ProjectByldozer/FormCarCollection.Designer.cs
@@ -0,0 +1,173 @@
+namespace ProjectByldozer
+{
+ partial class FormCarCollection
+ {
+ ///
+ /// 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();
+ buttonDelCar = new Button();
+ maskedTextBox = new MaskedTextBox();
+ buttonAddByldozer = new Button();
+ buttonAddTrackedCar = 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(buttonDelCar);
+ groupBoxTools.Controls.Add(maskedTextBox);
+ groupBoxTools.Controls.Add(buttonAddByldozer);
+ groupBoxTools.Controls.Add(buttonAddTrackedCar);
+ groupBoxTools.Controls.Add(comboBoxSelectionCompany);
+ groupBoxTools.Dock = DockStyle.Right;
+ groupBoxTools.Location = new Point(750, 0);
+ groupBoxTools.Name = "groupBoxTools";
+ groupBoxTools.Size = new Size(209, 499);
+ groupBoxTools.TabIndex = 0;
+ groupBoxTools.TabStop = false;
+ groupBoxTools.Text = "Инструменты";
+ //
+ // buttonRefresh
+ //
+ buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonRefresh.Location = new Point(6, 403);
+ buttonRefresh.Name = "buttonRefresh";
+ buttonRefresh.Size = new Size(191, 36);
+ 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, 324);
+ buttonGoToCheck.Name = "buttonGoToCheck";
+ buttonGoToCheck.Size = new Size(191, 34);
+ buttonGoToCheck.TabIndex = 5;
+ buttonGoToCheck.Text = "Передать на тесты";
+ buttonGoToCheck.UseVisualStyleBackColor = true;
+ buttonGoToCheck.Click += ButtonGoToCheck_Click;
+ //
+ // buttonDelCar
+ //
+ buttonDelCar.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonDelCar.Location = new Point(6, 248);
+ buttonDelCar.Name = "buttonDelCar";
+ buttonDelCar.Size = new Size(191, 34);
+ buttonDelCar.TabIndex = 4;
+ buttonDelCar.Text = "Удаление машины";
+ buttonDelCar.UseVisualStyleBackColor = true;
+ buttonDelCar.Click += ButtonDelCar_Click;
+ //
+ // maskedTextBox
+ //
+ maskedTextBox.Location = new Point(6, 219);
+ maskedTextBox.Mask = "00";
+ maskedTextBox.Name = "maskedTextBox";
+ maskedTextBox.Size = new Size(191, 23);
+ maskedTextBox.TabIndex = 3;
+ maskedTextBox.ValidatingType = typeof(int);
+ //
+ // buttonAddByldozer
+ //
+ buttonAddByldozer.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonAddByldozer.Location = new Point(6, 128);
+ buttonAddByldozer.Name = "buttonAddByldozer";
+ buttonAddByldozer.Size = new Size(191, 41);
+ buttonAddByldozer.TabIndex = 2;
+ buttonAddByldozer.Text = "Добавления бульдозера";
+ buttonAddByldozer.UseVisualStyleBackColor = true;
+ buttonAddByldozer.Click += ButtonAddByldozer_Click;
+ //
+ // buttonAddTrackedCar
+ //
+ buttonAddTrackedCar.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonAddTrackedCar.Location = new Point(6, 77);
+ buttonAddTrackedCar.Name = "buttonAddTrackedCar";
+ buttonAddTrackedCar.Size = new Size(191, 45);
+ buttonAddTrackedCar.TabIndex = 1;
+ buttonAddTrackedCar.Text = "Добавления гусеничной машины";
+ buttonAddTrackedCar.UseVisualStyleBackColor = true;
+ buttonAddTrackedCar.Click += ButtonAddTrackedCar_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(191, 23);
+ comboBoxSelectionCompany.TabIndex = 0;
+ comboBoxSelectionCompany.SelectedIndexChanged += ComboBoxSelectionCompany_SelectedIndexChanged;
+ //
+ // pictureBox
+ //
+ pictureBox.Dock = DockStyle.Fill;
+ pictureBox.Location = new Point(0, 0);
+ pictureBox.Name = "pictureBox";
+ pictureBox.Size = new Size(750, 499);
+ pictureBox.TabIndex = 1;
+ pictureBox.TabStop = false;
+ //
+ // FormCarCollection
+ //
+ AutoScaleDimensions = new SizeF(7F, 15F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(959, 499);
+ Controls.Add(pictureBox);
+ Controls.Add(groupBoxTools);
+ Name = "FormCarCollection";
+ Text = "коллекция бульдозеров";
+ groupBoxTools.ResumeLayout(false);
+ groupBoxTools.PerformLayout();
+ ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
+ ResumeLayout(false);
+ }
+
+ #endregion
+
+ private GroupBox groupBoxTools;
+ private ComboBox comboBoxSelectionCompany;
+ private Button buttonAddByldozer;
+ private Button buttonAddTrackedCar;
+ private MaskedTextBox maskedTextBox;
+ private PictureBox pictureBox;
+ private Button buttonDelCar;
+ private Button buttonRefresh;
+ private Button buttonGoToCheck;
+ }
+}
\ No newline at end of file
diff --git a/ProjectByldozer/ProjectByldozer/FormCarCollection.cs b/ProjectByldozer/ProjectByldozer/FormCarCollection.cs
new file mode 100644
index 0000000..16ae251
--- /dev/null
+++ b/ProjectByldozer/ProjectByldozer/FormCarCollection.cs
@@ -0,0 +1,161 @@
+using ProjectByldozer.CollectionGenericObjects;
+using ProjectByldozer.Drawnings;
+
+
+namespace ProjectByldozer;
+///
+/// Форма работы с компанией и ее коллекцией
+///
+
+public partial class FormCarCollection : Form
+{
+ ///
+ /// Компания
+ ///
+ private AbstractCompany? _company = null;
+
+ ///
+ /// Конструктор
+ ///
+ public FormCarCollection()
+ {
+ InitializeComponent();
+ }
+
+ private void ComboBoxSelectionCompany_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ switch (comboBoxSelectionCompany.Text)
+ {
+ case "Хранилище":
+ _company = new TrackedCarGarage(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects());
+ break;
+ }
+ }
+ ///
+ /// Добавление обычной машины
+ ///
+ ///
+ ///
+ private void ButtonAddByldozer_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningByldozer));
+
+
+ /// /// Добавление полного экскаватора
+ ///
+ ///
+ ///
+ private void ButtonAddTrackedCar_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningTrackedCar));
+
+ private void CreateObject(string type)
+ {
+ if (_company == null)
+ {
+ return;
+ }
+
+ Random random = new();
+ DrawningTrackedCar drawningTrackedCar;
+ switch (type)
+ {
+ case nameof(DrawningTrackedCar):
+ drawningTrackedCar = new DrawningTrackedCar(random.Next(100, 300), random.Next(1000, 3000), GetColor(random));
+ break;
+ case nameof(DrawningByldozer):
+ // TODO вызов диалогового окна для выбора цвета
+ drawningTrackedCar = new DrawningByldozer(random.Next(100, 300), random.Next(1000, 3000),
+ GetColor(random), GetColor(random),
+ Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
+ break;
+ default:
+ return;
+ }
+
+ if (_company + drawningTrackedCar != -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 ButtonDelCar_Click(object sender, EventArgs e)
+ {
+ if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == null)
+ {
+ return;
+ }
+
+ if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
+ {
+ 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;
+ }
+
+ DrawningTrackedCar? trackedcar = null;
+ int counter = 100;
+ while (trackedcar == null)
+ {
+ trackedcar = _company.GetRandomObject();
+ counter--;
+ if (counter <= 0)
+ {
+ break;
+ }
+ }
+
+ if (trackedcar == null)
+ {
+ return;
+ }
+ FormByldozer form = new()
+ {
+ SetTrackedCar = trackedcar
+ };
+ form.ShowDialog();
+
+ }
+
+ private void ButtonRefresh_Click(object sender, EventArgs e)
+ {
+ if (_company == null)
+ {
+ return;
+ }
+
+ pictureBox.Image = _company.Show();
+ }
+
+}
diff --git a/ProjectByldozer/ProjectByldozer/FormCarCollection.resx b/ProjectByldozer/ProjectByldozer/FormCarCollection.resx
new file mode 100644
index 0000000..a395bff
--- /dev/null
+++ b/ProjectByldozer/ProjectByldozer/FormCarCollection.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/ProjectByldozer/ProjectByldozer/Program.cs b/ProjectByldozer/ProjectByldozer/Program.cs
index 85b3071..28f7cd8 100644
--- a/ProjectByldozer/ProjectByldozer/Program.cs
+++ b/ProjectByldozer/ProjectByldozer/Program.cs
@@ -11,7 +11,8 @@ namespace ProjectByldozer
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
- Application.Run(new FormByldozer());
+
+ Application.Run(new FormCarCollection());
}
}
}
\ No newline at end of file