From 65c79eb884a05a1d279423d2368c27b474d38d46 Mon Sep 17 00:00:00 2001
From: Esenia12 <148366616+Esenia12@users.noreply.github.com>
Date: Sun, 3 Mar 2024 22:31:29 +0400
Subject: [PATCH] =?UTF-8?q?=D0=9B=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82?=
=?UTF-8?q?=D0=BE=D1=80=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82?=
=?UTF-8?q?=D0=B0=20=E2=84=963?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../AbstractCompany.cs | 4 +-
.../CarSharingService.cs | 66 +++++-
.../MassiveGenericObjects.cs | 142 +++++++------
.../Drawnings/DrawningDumpTrack.cs | 8 +-
.../Drawnings/DrawningTrack.cs | 2 +-
.../Entities/EntityDumpTrack.cs | 9 +-
.../FormTrackCollection.Designer.cs | 174 ++++++++++++++++
.../ProjectDumpTruck/FormTrackCollection.cs | 191 ++++++++++++++++++
.../ProjectDumpTruck/FormTrackCollection.resx | 120 +++++++++++
.../FormTransport.Designer.cs | 28 ---
.../ProjectDumpTruck/FormTransport.cs | 58 ++----
ProjectDumpTruck/ProjectDumpTruck/Program.cs | 3 +-
12 files changed, 661 insertions(+), 144 deletions(-)
create mode 100644 ProjectDumpTruck/ProjectDumpTruck/FormTrackCollection.Designer.cs
create mode 100644 ProjectDumpTruck/ProjectDumpTruck/FormTrackCollection.cs
create mode 100644 ProjectDumpTruck/ProjectDumpTruck/FormTrackCollection.resx
diff --git a/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/AbstractCompany.cs b/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/AbstractCompany.cs
index 6413673..563ac42 100644
--- a/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/AbstractCompany.cs
+++ b/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/AbstractCompany.cs
@@ -6,12 +6,12 @@ public abstract class AbstractCompany
///
/// Размер места (ширина)
///
- protected readonly int _placeSizeWidth = 210;
+ protected readonly int _placeSizeWidth = 220;
///
/// Размер места (высота)
///
- protected readonly int _placeSizeHeight = 80;
+ protected readonly int _placeSizeHeight = 155;
///
/// Ширина окна
diff --git a/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/CarSharingService.cs b/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/CarSharingService.cs
index e2ada74..fbb53c4 100644
--- a/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/CarSharingService.cs
+++ b/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/CarSharingService.cs
@@ -1,6 +1,66 @@
-
+using ProjectDumpTrack.Drawnings;
+
namespace ProjectDumpTruck.CollectionGenericObjects;
-internal class CarSharingService
+///
+/// Реализация абстрактной компании - каршеринг
+///
+public class CarSharingService : AbstractCompany
{
-}
+ ///
+ /// Конструктор
+ ///
+ ///
+ ///
+ ///
+ public CarSharingService(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, 2);
+ for (int i = 0; i < width; i++)
+ {
+ for (int j = 0; j < height + 1; ++j)
+ {
+ g.DrawLine(pen, i * _placeSizeWidth+15, j * _placeSizeHeight, i * _placeSizeWidth+15 + _placeSizeWidth-55, j * _placeSizeHeight);
+ g.DrawLine(pen, i * _placeSizeWidth+15, j * _placeSizeHeight, i * _placeSizeWidth+15, j * _placeSizeHeight -_placeSizeHeight);
+ }
+ }
+ }
+
+ protected override void SetObjectsPosition()
+ {
+ int width = _pictureWidth / _placeSizeWidth;
+ int height = _pictureHeight / _placeSizeHeight;
+
+ int curWidth = 0;
+ int curHeight = 0;
+
+ for (int i = 0; i < (_collection?.Count ?? 0); i++)
+ {
+ if (_collection.Get(i) != null)
+ {
+ _collection.Get(i).SetPictureSize(_pictureWidth, _pictureHeight);
+ _collection.Get(i).SetPosition(_placeSizeWidth * curWidth + 20, curHeight * _placeSizeHeight + 4);
+ }
+
+ if (curWidth < width-1)
+ curWidth++;
+ else
+ {
+ curWidth = 0;
+ curHeight++;
+ }
+ if (curHeight > height)
+ {
+ return;
+ }
+ }
+
+ }
+}
\ No newline at end of file
diff --git a/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/MassiveGenericObjects.cs
index cecc38d..cfb1b26 100644
--- a/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/MassiveGenericObjects.cs
+++ b/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/MassiveGenericObjects.cs
@@ -1,85 +1,109 @@
namespace ProjectDumpTruck.CollectionGenericObjects;
-internal class SetDumpTrackGeneric
- where T : class
+internal class MassiveGenericObjects : ICollectionGenericObjects
+ where T : class
{
- private readonly T[] _collection;
+ ///
+ /// Массив объектов, которые храним
+ ///
+ private T?[] _collection;
+
public int Count => _collection.Length;
- public SetDumpTrackGeneric(int count)
+
+ public int SetMaxCount
{
- _collection = new T[count];
+ set
+ {
+ if (value > 0)
+ {
+ if (_collection.Length > 0)
+ {
+ Array.Resize(ref _collection, value);
+ }
+ else
+ {
+ _collection = new T?[value];
+ }
+ }
+ }
}
- public int Insert(T DumpTrack)
+ ///
+ /// Конструктор
+ ///
+ public MassiveGenericObjects()
{
- // TODO вставка в начало набора
- if (_collection[Count - 1] == null)
- {
- for (int i = Count - 1; i > 0; i--)
- {
- _collection[i] = _collection[i - 1];
- }
- _collection[0] = DumpTrack;
- return 0;
- }
- return -1;
+ _collection = Array.Empty();
}
- public int Insert(T DumpTrack, int position)
+
+ public T? Get(int position)
+ {
+ // TODO проверка позиции
+ if (position >= _collection.Length || position < 0) return null;
+ return _collection[position];
+ }
+
+ public bool Insert(T obj)
+ {
+ // TODO вставка в свободное место набора
+ int index = 0;
+ while (index < _collection.Length)
+ {
+ if (_collection[index] == null)
+ {
+ _collection[index] = obj;
+ return true;
+ }
+ index++;
+ }
+ return false;
+ }
+
+ public bool Insert(T obj, int position)
{
// TODO проверка позиции
// TODO проверка, что элемент массива по этой позиции пустой, если нет, то
- // проверка, что после вставляемого элемента в массиве есть пустой элемент
- // сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента
- // TODO вставка по позиции
- if (position < 0 || position >= Count) return -1;
+ // ищется свободное место после этой позиции и идет вставка туда
+ // если нет после, ищем до
+ // TODO вставка
+ if (position >= _collection.Length || position < 0) return false;
if (_collection[position] == null)
{
- _collection[position] = DumpTrack;
- return position;
+ _collection[position] = obj;
+ return true;
}
- else
+ int index = position + 1;
+ while (index < _collection.Length)
{
- if (_collection[Count - 1] == null)
+ if (_collection[index] == null)
{
- for (int i = Count - 1; i > position; i--)
- {
- _collection[i] = _collection[i - 1];
- }
- _collection[position] = DumpTrack;
- return position;
+ _collection[index] = obj;
+ return true;
}
- return -1;
+ index++;
}
+ index = position - 1;
+ while (index >= 0)
+ {
+ if (_collection[index] == null)
+ {
+ _collection[index] = obj;
+ return true;
+ }
+ index--;
+ }
+ return false;
}
- public T Remove(int position)
+ public bool Remove(int position)
{
// TODO проверка позиции
- // TODO удаление объекта из массива, присовив элементу массива значение null
- if (position < 0 || position >= Count)
- return null;
- if (_collection[position] != null)
- {
- T removed = _collection[position];
- _collection[position] = null;
- if (position < Count - 1)
- {
- for (int k = position; k < Count - 1; k++)
- {
- _collection[k] = _collection[k + 1];
- }
- }
- return removed;
- }
- return null;
- }
- public T Get(int position)
- {
- // TODO проверка позиции
- if (position >= Count || position < 0)
- return null;
-
- return _collection[position];
+ // TODO удаление объекта из массива, присвоив элементу массива значение null
+ if (position >= _collection.Length || position < 0) return false;
+ _collection[position] = null;
+ return true;
}
}
+
+
diff --git a/ProjectDumpTruck/ProjectDumpTruck/Drawnings/DrawningDumpTrack.cs b/ProjectDumpTruck/ProjectDumpTruck/Drawnings/DrawningDumpTrack.cs
index cc9e727..da00f4b 100644
--- a/ProjectDumpTruck/ProjectDumpTruck/Drawnings/DrawningDumpTrack.cs
+++ b/ProjectDumpTruck/ProjectDumpTruck/Drawnings/DrawningDumpTrack.cs
@@ -64,9 +64,9 @@ public class DrawningDumpTrack : DrawningTrack
/// Признак наличия тента
- public DrawningDumpTrack(int speed, double weight, Color bodyColor, Color additionalColor, bool bodywork, bool awning) : base(130, 100)
+ public DrawningDumpTrack(int speed, double weight, Color bodyColor, Color additionalColor, Color additional2Color, bool bodywork, bool awning) : base(130, 100)
{
- EntityTrack = new EntityDumpTrack(speed, weight, bodyColor, additionalColor, bodywork, awning);
+ EntityTrack = new EntityDumpTrack(speed, weight, bodyColor, additionalColor, additional2Color, bodywork, awning);
}
@@ -77,15 +77,15 @@ public class DrawningDumpTrack : DrawningTrack
return;
}
- Pen pen = new(Color.Black);
Brush additionalBrush = new SolidBrush(dumpTrack.AdditionalColor);
+ Brush additional2Brush = new SolidBrush(dumpTrack.Additional2Color);
base.DrawTransport(g);
//Отрисовка кузова
if (dumpTrack.Bodywork)
{
- g.FillRectangle(additionalBrush, _startPosX.Value, _startPosY.Value, 90, 35);
+ g.FillRectangle(additional2Brush, _startPosX.Value, _startPosY.Value, 90, 35);
}
//Отрисовка тента
diff --git a/ProjectDumpTruck/ProjectDumpTruck/Drawnings/DrawningTrack.cs b/ProjectDumpTruck/ProjectDumpTruck/Drawnings/DrawningTrack.cs
index 8cc5536..037ead7 100644
--- a/ProjectDumpTruck/ProjectDumpTruck/Drawnings/DrawningTrack.cs
+++ b/ProjectDumpTruck/ProjectDumpTruck/Drawnings/DrawningTrack.cs
@@ -219,7 +219,7 @@ public class DrawningTrack
}
Pen pen = new(Color.Black);
-
+
//Отрисовка основы (кабины водителя и днища)
Brush body = new SolidBrush(EntityTrack.BodyColor);
diff --git a/ProjectDumpTruck/ProjectDumpTruck/Entities/EntityDumpTrack.cs b/ProjectDumpTruck/ProjectDumpTruck/Entities/EntityDumpTrack.cs
index 9999843..60cc6ff 100644
--- a/ProjectDumpTruck/ProjectDumpTruck/Entities/EntityDumpTrack.cs
+++ b/ProjectDumpTruck/ProjectDumpTruck/Entities/EntityDumpTrack.cs
@@ -10,6 +10,11 @@ public class EntityDumpTrack : EntityTrack
///
public Color AdditionalColor { get; private set; }
+ ///
+ /// Дополнительный цвет (для опциональных элементов)
+ ///
+ public Color Additional2Color { get; private set; }
+
///
/// Признак (опция) наличия кузова
///
@@ -29,12 +34,14 @@ public class EntityDumpTrack : EntityTrack
/// Вес
/// Основной цвет
/// Дополнительный цвет
+ /// /// Дополнительный цвет
/// Признак наличия кузова
/// Признак наличия тента
- public EntityDumpTrack(int speed, double weight, Color bodyColor, Color additionalColor, bool bodywork, bool awning) : base(5, 45, Color.Black)
+ public EntityDumpTrack(int speed, double weight, Color bodyColor, Color additionalColor, Color additional2Color, bool bodywork, bool awning) : base(5, 45, Color.Black)
{
AdditionalColor = additionalColor;
+ Additional2Color = additional2Color;
Bodywork = bodywork;
Awning = awning;
}
diff --git a/ProjectDumpTruck/ProjectDumpTruck/FormTrackCollection.Designer.cs b/ProjectDumpTruck/ProjectDumpTruck/FormTrackCollection.Designer.cs
new file mode 100644
index 0000000..8deaa1a
--- /dev/null
+++ b/ProjectDumpTruck/ProjectDumpTruck/FormTrackCollection.Designer.cs
@@ -0,0 +1,174 @@
+namespace ProjectDumpTruck
+{
+ partial class FormTrackCollection
+ {
+ ///
+ /// 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();
+ buttonDelTrack = new Button();
+ maskedTextBox = new MaskedTextBox();
+ buttonAddDumpTrack = new Button();
+ buttonAddTrack = 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(buttonDelTrack);
+ groupBoxTools.Controls.Add(maskedTextBox);
+ groupBoxTools.Controls.Add(buttonAddDumpTrack);
+ groupBoxTools.Controls.Add(buttonAddTrack);
+ groupBoxTools.Controls.Add(comboBoxSelectorCompany);
+ groupBoxTools.Dock = DockStyle.Right;
+ groupBoxTools.Location = new Point(745, 0);
+ groupBoxTools.Name = "groupBoxTools";
+ groupBoxTools.Size = new Size(216, 493);
+ groupBoxTools.TabIndex = 0;
+ groupBoxTools.TabStop = false;
+ groupBoxTools.Text = "Инструменты";
+ //
+ // buttonRefresh
+ //
+ buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonRefresh.Location = new Point(6, 423);
+ buttonRefresh.Name = "buttonRefresh";
+ buttonRefresh.Size = new Size(192, 39);
+ 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, 306);
+ buttonGoToCheck.Name = "buttonGoToCheck";
+ buttonGoToCheck.Size = new Size(192, 39);
+ buttonGoToCheck.TabIndex = 5;
+ buttonGoToCheck.Text = "Передать на тесты";
+ buttonGoToCheck.UseVisualStyleBackColor = true;
+ buttonGoToCheck.Click += buttonGoToCheck_Click;
+ //
+ // buttonDelTrack
+ //
+ buttonDelTrack.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonDelTrack.Location = new Point(6, 198);
+ buttonDelTrack.Name = "buttonDelTrack";
+ buttonDelTrack.Size = new Size(192, 39);
+ buttonDelTrack.TabIndex = 4;
+ buttonDelTrack.Text = "Удалить грузовик";
+ buttonDelTrack.UseVisualStyleBackColor = true;
+ buttonDelTrack.Click += buttonDelTrack_Click;
+ //
+ // maskedTextBox
+ //
+ maskedTextBox.Location = new Point(6, 169);
+ maskedTextBox.Mask = "00";
+ maskedTextBox.Name = "maskedTextBox";
+ maskedTextBox.Size = new Size(192, 23);
+ maskedTextBox.TabIndex = 3;
+ maskedTextBox.ValidatingType = typeof(int);
+ //
+ // buttonAddDumpTrack
+ //
+ buttonAddDumpTrack.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonAddDumpTrack.Location = new Point(6, 106);
+ buttonAddDumpTrack.Name = "buttonAddDumpTrack";
+ buttonAddDumpTrack.Size = new Size(192, 39);
+ buttonAddDumpTrack.TabIndex = 2;
+ buttonAddDumpTrack.Text = "Добавление самосвала";
+ buttonAddDumpTrack.UseVisualStyleBackColor = true;
+ buttonAddDumpTrack.Click += buttonAddDumpTrack_Click;
+ //
+ // buttonAddTrack
+ //
+ buttonAddTrack.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonAddTrack.Location = new Point(6, 61);
+ buttonAddTrack.Name = "buttonAddTrack";
+ buttonAddTrack.Size = new Size(192, 39);
+ buttonAddTrack.TabIndex = 1;
+ buttonAddTrack.Text = "Добавление грузовика";
+ buttonAddTrack.UseVisualStyleBackColor = true;
+ buttonAddTrack.Click += buttonAddTrack_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(192, 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(745, 493);
+ pictureBox.TabIndex = 1;
+ pictureBox.TabStop = false;
+
+ //
+ // FormTrackCollection
+ //
+ AutoScaleDimensions = new SizeF(7F, 15F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(961, 493);
+ Controls.Add(pictureBox);
+ Controls.Add(groupBoxTools);
+ Name = "FormTrackCollection";
+ Text = "Коллекция самосвалов";
+ groupBoxTools.ResumeLayout(false);
+ groupBoxTools.PerformLayout();
+ ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
+ ResumeLayout(false);
+ }
+
+ #endregion
+
+ private GroupBox groupBoxTools;
+ private ComboBox comboBoxSelectorCompany;
+ private Button buttonAddDumpTrack;
+ private Button buttonAddTrack;
+ private PictureBox pictureBox;
+ private Button buttonRefresh;
+ private Button buttonGoToCheck;
+ private Button buttonDelTrack;
+ private MaskedTextBox maskedTextBox;
+ }
+}
\ No newline at end of file
diff --git a/ProjectDumpTruck/ProjectDumpTruck/FormTrackCollection.cs b/ProjectDumpTruck/ProjectDumpTruck/FormTrackCollection.cs
new file mode 100644
index 0000000..fb8e10e
--- /dev/null
+++ b/ProjectDumpTruck/ProjectDumpTruck/FormTrackCollection.cs
@@ -0,0 +1,191 @@
+
+using ProjectDumpTruck.CollectionGenericObjects;
+using ProjectDumpTrack.Drawnings;
+
+namespace ProjectDumpTruck;
+
+///
+/// Форма работы с компанией и ее коллекцией
+///
+public partial class FormTrackCollection : Form
+{
+ ///
+ /// Компания
+ ///
+ private AbstractCompany? _company = null;
+
+ ///
+ /// Конструктор
+ ///
+ public FormTrackCollection()
+ {
+ InitializeComponent();
+ }
+
+ ///
+ /// Выбор компании
+ ///
+ ///
+ ///
+ private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ switch (comboBoxSelectorCompany.Text)
+ {
+ case "Хранилище":
+ _company = new CarSharingService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects< DrawningTrack > ());
+ break;
+ }
+ }
+
+ ///
+ /// Добавление обычного автомобиля
+ ///
+ ///
+ ///
+ private void buttonAddTrack_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningTrack));
+
+ ///
+ /// Добавление спортивного автомобиля
+ ///
+ ///
+ ///
+ private void buttonAddDumpTrack_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningDumpTrack));
+
+ ///
+ /// Создание объекта класса-перемещения
+ ///
+ /// Тип создаваемого объекта
+ private void CreateObject(string type)
+ {
+ if (_company == null)
+ {
+ return;
+ }
+
+ Random random = new();
+ DrawningTrack drawningTrack;
+ switch (type)
+ {
+ case nameof(DrawningTrack):
+ drawningTrack = new DrawningTrack(random.Next(100, 300), random.Next(1000, 3000), GetColor(random));
+ break;
+ case nameof(DrawningDumpTrack):
+ drawningTrack = new DrawningDumpTrack(random.Next(100, 300), random.Next(1000, 3000), GetColor(random), GetColor(random), GetColor(random),
+ Convert.ToBoolean(random.Next(2, 2)), Convert.ToBoolean(random.Next(1, 2)));
+ break;
+ default:
+ return;
+ }
+
+ if (_company + drawningTrack)
+ {
+ 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 buttonDelTrack_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)
+ {
+ MessageBox.Show("Объект удален");
+ pictureBox.Image = _company.Show();
+ }
+ else
+ {
+ MessageBox.Show("Не удалось удалить объект");
+ }
+ }
+
+ ///
+ /// Передача объекта в другую форму
+ ///
+ ///
+ ///
+ private void buttonGoToCheck_Click(object sender, EventArgs e)
+ {
+ if (_company == null)
+ {
+ return;
+ }
+
+ DrawningTrack? track = null;
+ int counter = 100;
+ while (track == null)
+ {
+ track = _company.GetRandomObject();
+ counter--;
+ if (counter <= 0)
+ {
+ break;
+ }
+ }
+
+ if (track == null)
+ {
+ return;
+ }
+
+ FormTransport form = new()
+ {
+ SetTrack = track
+ };
+ form.ShowDialog();
+ }
+
+ ///
+ /// Перерисовка коллекции
+ ///
+ ///
+ ///
+ private void buttonRefresh_Click(object sender, EventArgs e)
+ {
+ if (_company == null)
+ {
+ return;
+ }
+
+ pictureBox.Image = _company.Show();
+ }
+
+
+}
diff --git a/ProjectDumpTruck/ProjectDumpTruck/FormTrackCollection.resx b/ProjectDumpTruck/ProjectDumpTruck/FormTrackCollection.resx
new file mode 100644
index 0000000..af32865
--- /dev/null
+++ b/ProjectDumpTruck/ProjectDumpTruck/FormTrackCollection.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/ProjectDumpTruck/ProjectDumpTruck/FormTransport.Designer.cs b/ProjectDumpTruck/ProjectDumpTruck/FormTransport.Designer.cs
index 5b55460..14289a1 100644
--- a/ProjectDumpTruck/ProjectDumpTruck/FormTransport.Designer.cs
+++ b/ProjectDumpTruck/ProjectDumpTruck/FormTransport.Designer.cs
@@ -29,12 +29,10 @@
private void InitializeComponent()
{
pictureBoxDumpTrack = new PictureBox();
- buttonCreateDumpTrack = new Button();
buttonLeft = new Button();
buttonRight = new Button();
buttonUp = new Button();
buttonDown = new Button();
- buttonCreateTrack = new Button();
comboBoxStrategy = new ComboBox();
buttonStrategyStep = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxDumpTrack).BeginInit();
@@ -49,17 +47,6 @@
pictureBoxDumpTrack.TabIndex = 0;
pictureBoxDumpTrack.TabStop = false;
//
- // buttonCreateDumpTrack
- //
- buttonCreateDumpTrack.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
- buttonCreateDumpTrack.Location = new Point(12, 409);
- buttonCreateDumpTrack.Name = "buttonCreateDumpTrack";
- buttonCreateDumpTrack.Size = new Size(210, 29);
- buttonCreateDumpTrack.TabIndex = 1;
- buttonCreateDumpTrack.Text = "Создать грузовик с кузовом";
- buttonCreateDumpTrack.UseVisualStyleBackColor = true;
- buttonCreateDumpTrack.Click += buttonCreateDumpTrack_Click;
- //
// buttonLeft
//
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
@@ -108,17 +95,6 @@
buttonDown.UseVisualStyleBackColor = true;
buttonDown.Click += buttonMove_Click;
//
- // buttonCreateTrack
- //
- buttonCreateTrack.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
- buttonCreateTrack.Location = new Point(238, 409);
- buttonCreateTrack.Name = "buttonCreateTrack";
- buttonCreateTrack.Size = new Size(210, 29);
- buttonCreateTrack.TabIndex = 6;
- buttonCreateTrack.Text = "Создать грузовик";
- buttonCreateTrack.UseVisualStyleBackColor = true;
- buttonCreateTrack.Click += buttonCreateTrack_Click;
- //
// comboBoxStrategy
//
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
@@ -146,12 +122,10 @@
ClientSize = new Size(800, 450);
Controls.Add(buttonStrategyStep);
Controls.Add(comboBoxStrategy);
- Controls.Add(buttonCreateTrack);
Controls.Add(buttonDown);
Controls.Add(buttonUp);
Controls.Add(buttonRight);
Controls.Add(buttonLeft);
- Controls.Add(buttonCreateDumpTrack);
Controls.Add(pictureBoxDumpTrack);
Name = "FormTransport";
Text = "FormTransport";
@@ -162,12 +136,10 @@
#endregion
private PictureBox pictureBoxDumpTrack;
- private Button buttonCreateDumpTrack;
internal Button buttonLeft;
internal Button buttonRight;
internal Button buttonUp;
internal Button buttonDown;
- private Button buttonCreateTrack;
private ComboBox comboBoxStrategy;
private Button buttonStrategyStep;
}
diff --git a/ProjectDumpTruck/ProjectDumpTruck/FormTransport.cs b/ProjectDumpTruck/ProjectDumpTruck/FormTransport.cs
index e3c9f5f..13b9100 100644
--- a/ProjectDumpTruck/ProjectDumpTruck/FormTransport.cs
+++ b/ProjectDumpTruck/ProjectDumpTruck/FormTransport.cs
@@ -21,6 +21,19 @@ namespace ProjectDumpTruck
///
/// Конструктор формы
///
+ ///
+
+ public DrawningTrack SetTrack
+ {
+ set
+ {
+ _drawningTrack = value;
+ _drawningTrack.SetPictureSize(pictureBoxDumpTrack.Width, pictureBoxDumpTrack.Height);
+ comboBoxStrategy.Enabled = true;
+ _strategy = null;
+ Draw();
+ }
+ }
public FormTransport()
{
InitializeComponent();
@@ -45,51 +58,6 @@ namespace ProjectDumpTruck
}
- ///
- /// Создание объекта класса-перемещения
- ///
- /// Тип создаваемого объекта
- private void CreateObject(string type)
- {
- Random random = new();
- switch (type)
- {
- case nameof(DrawningTrack):
- _drawningTrack = new DrawningTrack(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(DrawningDumpTrack):
- _drawningTrack = new DrawningDumpTrack(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(1, 2)), Convert.ToBoolean(random.Next(0, 2)));
- break;
- default:
- return;
- }
-
- _drawningTrack.SetPictureSize(pictureBoxDumpTrack.Width, pictureBoxDumpTrack.Height);
- _drawningTrack.SetPosition(random.Next(10, 100), random.Next(10, 100));
- _strategy = null;
- comboBoxStrategy.Enabled = true;
- Draw();
- }
-
-
- ///
- /// Обработка нажатия кнопки "Создать грузовик с кузовом"
- ///
- ///
- ///
- private void buttonCreateDumpTrack_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningDumpTrack));
-
- ///
- /// Обработка нажатия кнопки "Создать грузовик"
- ///
- ///
- ///
- private void buttonCreateTrack_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningTrack));
-
///
/// Перемещение объекта по форме (нажатие кнопок навигации)
diff --git a/ProjectDumpTruck/ProjectDumpTruck/Program.cs b/ProjectDumpTruck/ProjectDumpTruck/Program.cs
index 2711713..99f3436 100644
--- a/ProjectDumpTruck/ProjectDumpTruck/Program.cs
+++ b/ProjectDumpTruck/ProjectDumpTruck/Program.cs
@@ -13,7 +13,8 @@ namespace ProjectDumpTruck
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
- Application.Run(new FormTransport());
+ Application.Run(new FormTrackCollection());
+
//// 3