From df6db4d6b7caf9a9f85ee4b3352d7be5079cc3a1 Mon Sep 17 00:00:00 2001 From: Samecoins <146867889+Samecoins@users.noreply.github.com> Date: Sat, 11 May 2024 00:44:38 +0400 Subject: [PATCH] done lab 3 --- .../AbstractCompany.cs | 121 ++++++++++++ .../ICollectionGenericObjects.cs | 50 +++++ .../MassiveGenericObjects.cs | 106 ++++++++++ .../TruckParkingService.cs | 70 +++++++ .../Drawnings/DrawningDumpTruck.cs | 16 +- .../Entities/EntityDumpTruck.cs | 9 +- .../FormTransport.Designer.cs | 28 --- .../ProjectDumpTruck/FormTransport.cs | 61 ++---- .../FormTruckCollection.Designer.cs | 174 +++++++++++++++++ .../ProjectDumpTruck/FormTruckCollection.cs | 183 ++++++++++++++++++ .../ProjectDumpTruck/FormTruckCollection.resx | 120 ++++++++++++ ProjectDumpTruck/ProjectDumpTruck/Program.cs | 2 +- 12 files changed, 858 insertions(+), 82 deletions(-) create mode 100644 ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/AbstractCompany.cs create mode 100644 ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/ICollectionGenericObjects.cs create mode 100644 ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/MassiveGenericObjects.cs create mode 100644 ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/TruckParkingService.cs create mode 100644 ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.Designer.cs create mode 100644 ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.cs create mode 100644 ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.resx diff --git a/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/AbstractCompany.cs b/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/AbstractCompany.cs new file mode 100644 index 0000000..6273a7a --- /dev/null +++ b/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/AbstractCompany.cs @@ -0,0 +1,121 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ProjectDumpTruck.Drawnings; + +namespace ProjectDumpTruck.CollectionGenericObjects; + +/// +/// Абстракция компании, хранящий коллекцию кораблей +/// +public abstract class AbstractCompany +{ + /// + /// Размер места (ширина) + /// + protected readonly int _placeSizeWidth = 220; + + /// + /// Размер места (высота) + /// + protected readonly int _placeSizeHeight = 155; + + /// + /// Ширина окна + /// + 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, DrawningTruck truck) + { + return company._collection?.Insert(truck) ?? -1; + } + + /// + /// Перегрузка оператора удаления для класса + /// + /// Компания + /// Номер удаляемого объекта + /// + public static DrawningTruck operator -(AbstractCompany company, int position) + { + return company._collection?.Remove(position) ?? null; + } + + /// + /// Получение случайного объекта из коллекции + /// + /// + public DrawningTruck? 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); + + SetObjectsPosition(); + for (int i = 0; i < (_collection?.Count ?? 0); ++i) + { + DrawningTruck? obj = _collection?.Get(i); + obj?.DrawTransport(graphics); + } + + return bitmap; + } + + /// + /// Вывод заднего фона + /// + /// + protected abstract void DrawBackground(Graphics g); + + /// + /// Расстановка объектов + /// + protected abstract void SetObjectsPosition(); +} \ No newline at end of file diff --git a/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/ICollectionGenericObjects.cs b/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/ICollectionGenericObjects.cs new file mode 100644 index 0000000..1dd4f1c --- /dev/null +++ b/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/ICollectionGenericObjects.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectDumpTruck.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); +} \ No newline at end of file diff --git a/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/MassiveGenericObjects.cs new file mode 100644 index 0000000..6d22f27 --- /dev/null +++ b/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/MassiveGenericObjects.cs @@ -0,0 +1,106 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectDumpTruck.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 (position >= 0 && position < Count) + { + return _collection[position]; + } + + return null; + } + + public int Insert(T obj) + { + return Insert(obj, 0); + } + + public int Insert(T obj, int position) + { + if (position < 0 || position >= Count) + { + return -1; + } + if (_collection[position] == null) + { + _collection[position] = obj; + return position; + } + + for (int i = position + 1; i < Count; i++) + { + if (_collection[i] == null) + { + _collection[i] = obj; + return i; + } + } + for (int i = position - 1; i >= 0; i--) + { + if (_collection[i] == null) + { + _collection[i] = obj; + return i; + } + } + + return -1; + } + + public T Remove(int position) + { + if (position < 0 || position >= Count) + { + return null; + } + T obj = _collection[position]; + _collection[position] = null; + return obj; + } +} \ No newline at end of file diff --git a/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/TruckParkingService.cs b/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/TruckParkingService.cs new file mode 100644 index 0000000..3e18f02 --- /dev/null +++ b/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/TruckParkingService.cs @@ -0,0 +1,70 @@ +using ProjectDumpTruck.Drawnings; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectDumpTruck.CollectionGenericObjects; + +public class TruckParkingService : AbstractCompany +{ + + /// + /// Конструктор + /// + /// + /// + /// + public TruckParkingService(int picWidth, int picHeight, ICollectionGenericObjects collection) : base(picWidth, picHeight, collection) + { + } + + protected override void DrawBackground(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 + 5, j * _placeSizeHeight, i * _placeSizeWidth + 5 + _placeSizeWidth - 45, j * _placeSizeHeight); + g.DrawLine(pen, i * _placeSizeWidth + 5, j * _placeSizeHeight, i * _placeSizeWidth + 5, 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 + 20); + } + + if (curWidth < width - 1) + curWidth++; + else + { + curWidth = 0; + curHeight++; + } + if (curHeight > height) + { + return; + } + } + + } +} diff --git a/ProjectDumpTruck/ProjectDumpTruck/Drawnings/DrawningDumpTruck.cs b/ProjectDumpTruck/ProjectDumpTruck/Drawnings/DrawningDumpTruck.cs index 602ba45..85996e5 100644 --- a/ProjectDumpTruck/ProjectDumpTruck/Drawnings/DrawningDumpTruck.cs +++ b/ProjectDumpTruck/ProjectDumpTruck/Drawnings/DrawningDumpTruck.cs @@ -22,9 +22,9 @@ public class DrawningDumpTruck : DrawningTruck /// Признак наличия кузова /// Признак наличия тента - public DrawningDumpTruck(int speed, double weight, Color bodyColor, Color additionalColor, bool bodywork, bool awning) : base(130, 90) + public DrawningDumpTruck(int speed, double weight, Color bodyColor, Color additionalColor, Color additional2Color, bool bodywork, bool awning) : base(130, 90) { - EntityTruck = new EntityDumpTruck(speed, weight, bodyColor, additionalColor, bodywork, awning); + EntityTruck = new EntityDumpTruck(speed, weight, bodyColor, additionalColor, additional2Color, bodywork, awning); } public override void DrawTransport(Graphics g) @@ -36,12 +36,14 @@ public class DrawningDumpTruck : DrawningTruck Pen pen = new(Color.Black); Brush additionalBrush = new SolidBrush(dumpTruck.AdditionalColor); + Brush additional2Brush = new SolidBrush(dumpTruck.Additional2Color); + Brush border = new SolidBrush(Color.Black); //Отрисовка кузова if (dumpTruck.Bodywork) { - g.FillRectangle(additionalBrush, _startPosX.Value, _startPosY.Value, 90, 35); + g.FillRectangle(additional2Brush, _startPosX.Value, _startPosY.Value, 90, 35); } _startPosX += 0; @@ -54,10 +56,10 @@ public class DrawningDumpTruck : DrawningTruck //Отрисовка тента if (dumpTruck.Bodywork & dumpTruck.Awning) { - g.FillRectangle(border, _startPosX.Value, _startPosY.Value, 95, 10); - g.FillRectangle(border, _startPosX.Value, _startPosY.Value, 95, 3); - g.FillRectangle(border, _startPosX.Value + 30, _startPosY.Value, 3, 40); - g.FillRectangle(border, _startPosX.Value + 70, _startPosY.Value, 3, 40); + g.FillRectangle(additionalBrush, _startPosX.Value, _startPosY.Value, 95, 10); + g.FillRectangle(additionalBrush, _startPosX.Value, _startPosY.Value, 95, 3); + g.FillRectangle(additionalBrush, _startPosX.Value + 30, _startPosY.Value, 3, 40); + g.FillRectangle(additionalBrush, _startPosX.Value + 70, _startPosY.Value, 3, 40); } } } \ No newline at end of file diff --git a/ProjectDumpTruck/ProjectDumpTruck/Entities/EntityDumpTruck.cs b/ProjectDumpTruck/ProjectDumpTruck/Entities/EntityDumpTruck.cs index 02bca18..70a8013 100644 --- a/ProjectDumpTruck/ProjectDumpTruck/Entities/EntityDumpTruck.cs +++ b/ProjectDumpTruck/ProjectDumpTruck/Entities/EntityDumpTruck.cs @@ -10,6 +10,11 @@ public class EntityDumpTruck : EntityTruck /// public Color AdditionalColor { get; private set; } + /// + /// Дополнительный цвет (для опциональных элементов) + /// + public Color Additional2Color { get; private set; } + /// /// Признак (опция) наличия кузова /// @@ -27,12 +32,14 @@ public class EntityDumpTruck : EntityTruck /// Вес /// Основной цвет /// Дополнительный цвет + /// Дополнительный цвет /// Признак наличия кузова /// Признак наличия тента - public EntityDumpTruck(int speed, double weight, Color bodyColor, Color additionalColor, bool bodywork, bool awning) : base(speed, weight, bodyColor) + public EntityDumpTruck(int speed, double weight, Color bodyColor, Color additionalColor, Color additional2Color, bool bodywork, bool awning) : base(speed, weight, bodyColor) { AdditionalColor = additionalColor; + Additional2Color = additional2Color; Bodywork = bodywork; Awning = awning; } diff --git a/ProjectDumpTruck/ProjectDumpTruck/FormTransport.Designer.cs b/ProjectDumpTruck/ProjectDumpTruck/FormTransport.Designer.cs index 8c0e52b..d77ac3b 100644 --- a/ProjectDumpTruck/ProjectDumpTruck/FormTransport.Designer.cs +++ b/ProjectDumpTruck/ProjectDumpTruck/FormTransport.Designer.cs @@ -33,8 +33,6 @@ buttonUp = new Button(); buttonDown = new Button(); buttonRight = new Button(); - buttonCreateDumpTruck = new Button(); - buttonCreateTruck = new Button(); comboBoxStrategy = new ComboBox(); buttonStrategyStep = new Button(); ((System.ComponentModel.ISupportInitialize)pictureBoxDumpTruck).BeginInit(); @@ -97,28 +95,6 @@ buttonRight.UseVisualStyleBackColor = true; buttonRight.Click += ButtonMove_Click; // - // buttonCreateDumpTruck - // - buttonCreateDumpTruck.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonCreateDumpTruck.Location = new Point(12, 498); - buttonCreateDumpTruck.Name = "buttonCreateDumpTruck"; - buttonCreateDumpTruck.Size = new Size(117, 23); - buttonCreateDumpTruck.TabIndex = 5; - buttonCreateDumpTruck.Text = "Создать самосвал"; - buttonCreateDumpTruck.UseVisualStyleBackColor = true; - buttonCreateDumpTruck.Click += ButtonCreateDumpTruck_Click; - // - // buttonCreateTruck - // - buttonCreateTruck.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonCreateTruck.Location = new Point(135, 498); - buttonCreateTruck.Name = "buttonCreateTruck"; - buttonCreateTruck.Size = new Size(117, 23); - buttonCreateTruck.TabIndex = 6; - buttonCreateTruck.Text = "Создать тележка"; - buttonCreateTruck.UseVisualStyleBackColor = true; - buttonCreateTruck.Click += ButtonCreateTruck_Click; - // // comboBoxStrategy // comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList; @@ -146,8 +122,6 @@ ClientSize = new Size(1017, 533); Controls.Add(buttonStrategyStep); Controls.Add(comboBoxStrategy); - Controls.Add(buttonCreateTruck); - Controls.Add(buttonCreateDumpTruck); Controls.Add(buttonRight); Controls.Add(buttonDown); Controls.Add(buttonUp); @@ -166,8 +140,6 @@ private Button buttonUp; private Button buttonDown; private Button buttonRight; - private Button buttonCreateDumpTruck; - private Button buttonCreateTruck; private ComboBox comboBoxStrategy; private Button buttonStrategyStep; } diff --git a/ProjectDumpTruck/ProjectDumpTruck/FormTransport.cs b/ProjectDumpTruck/ProjectDumpTruck/FormTransport.cs index b01aede..b9c5396 100644 --- a/ProjectDumpTruck/ProjectDumpTruck/FormTransport.cs +++ b/ProjectDumpTruck/ProjectDumpTruck/FormTransport.cs @@ -23,10 +23,25 @@ namespace ProjectDumpTruck private DrawningTruck? _drawningTruck; /// - /// + /// Стратегия перемещения /// private AbstractStrategy? _strategy; + /// + /// Получение объекта + /// + public DrawningTruck SetTruck + { + set + { + _drawningTruck = value; + _drawningTruck.SetPictureSize(pictureBoxDumpTruck.Width, pictureBoxDumpTruck.Height); + comboBoxStrategy.Enabled = true; + _strategy = null; + Draw(); + } + } + /// /// Конструктор формы /// @@ -52,50 +67,6 @@ namespace ProjectDumpTruck pictureBoxDumpTruck.Image = bmp; } - /// - /// Создание объекта класса-перемещения - /// - /// Тип создаваемого объекта - private void CreateObject(string type) - { - Random random = new(); - switch (type) - { - case nameof(DrawningTruck): - _drawningTruck = new DrawningTruck(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(DrawningDumpTruck): - _drawningTruck = new DrawningDumpTruck(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; - } - - _drawningTruck.SetPictureSize(pictureBoxDumpTruck.Width, pictureBoxDumpTruck.Height); - _drawningTruck.SetPosition(random.Next(10, 100), random.Next(10, 100)); - _strategy = null; - comboBoxStrategy.Enabled = true; - Draw(); - } - - /// - /// Обработка нажатия кнопки "Создать самосвал" - /// - /// - /// - private void ButtonCreateDumpTruck_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningDumpTruck)); - - /// - /// Обработка нажатия кнопки "Создать тележка" - /// - /// - /// - private void ButtonCreateTruck_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningTruck)); - /// /// Перемещение объекта по форме (нажатие кнопок навигации) /// diff --git a/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.Designer.cs b/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.Designer.cs new file mode 100644 index 0000000..c6f0e1a --- /dev/null +++ b/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.Designer.cs @@ -0,0 +1,174 @@ +namespace ProjectDumpTruck +{ + partial class FormTruckCollection + { + /// + /// 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(); + buttonRemoveTruck = new Button(); + maskedTextBoxPosition = new MaskedTextBox(); + buttonAddDumpTruck = new Button(); + buttonAddTruck = 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(buttonRemoveTruck); + groupBoxTools.Controls.Add(maskedTextBoxPosition); + groupBoxTools.Controls.Add(buttonAddDumpTruck); + groupBoxTools.Controls.Add(buttonAddTruck); + groupBoxTools.Controls.Add(comboBoxSelectorCompany); + groupBoxTools.Dock = DockStyle.Right; + groupBoxTools.Location = new Point(947, 0); + groupBoxTools.Name = "groupBoxTools"; + groupBoxTools.Size = new Size(179, 660); + groupBoxTools.TabIndex = 0; + groupBoxTools.TabStop = false; + groupBoxTools.Text = "Интсрументы"; + // + // buttonRefresh + // + buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonRefresh.Location = new Point(6, 477); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(167, 42); + 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, 360); + buttonGoToCheck.Name = "buttonGoToCheck"; + buttonGoToCheck.Size = new Size(167, 42); + buttonGoToCheck.TabIndex = 5; + buttonGoToCheck.Text = "Отправить на проверку"; + buttonGoToCheck.UseVisualStyleBackColor = true; + buttonGoToCheck.Click += ButtonGoToCheck_Click; + // + // buttonRemoveTruck + // + buttonRemoveTruck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonRemoveTruck.Location = new Point(6, 255); + buttonRemoveTruck.Name = "buttonRemoveTruck"; + buttonRemoveTruck.Size = new Size(167, 42); + buttonRemoveTruck.TabIndex = 4; + buttonRemoveTruck.Text = "Удалить грузовик"; + buttonRemoveTruck.UseVisualStyleBackColor = true; + buttonRemoveTruck.Click += ButtonRemoveTruck_Click; + // + // maskedTextBoxPosition + // + maskedTextBoxPosition.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + maskedTextBoxPosition.Location = new Point(6, 226); + maskedTextBoxPosition.Mask = "00"; + maskedTextBoxPosition.Name = "maskedTextBoxPosition"; + maskedTextBoxPosition.Size = new Size(167, 23); + maskedTextBoxPosition.TabIndex = 3; + maskedTextBoxPosition.ValidatingType = typeof(int); + // + // buttonAddDumpTruck + // + buttonAddDumpTruck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonAddDumpTruck.Location = new Point(6, 141); + buttonAddDumpTruck.Name = "buttonAddDumpTruck"; + buttonAddDumpTruck.Size = new Size(167, 42); + buttonAddDumpTruck.TabIndex = 2; + buttonAddDumpTruck.Text = "Добавить самосвал"; + buttonAddDumpTruck.UseVisualStyleBackColor = true; + buttonAddDumpTruck.Click += ButtonAddDumpTruck_Click; + // + // buttonAddTruck + // + buttonAddTruck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonAddTruck.Location = new Point(6, 93); + buttonAddTruck.Name = "buttonAddTruck"; + buttonAddTruck.Size = new Size(167, 42); + buttonAddTruck.TabIndex = 1; + buttonAddTruck.Text = "Добавить грузовик"; + buttonAddTruck.UseVisualStyleBackColor = true; + buttonAddTruck.Click += ButtonAddTruck_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(167, 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(947, 660); + pictureBox.TabIndex = 1; + pictureBox.TabStop = false; + // + // FormTruckCollection + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1126, 660); + Controls.Add(pictureBox); + Controls.Add(groupBoxTools); + Name = "FormTruckCollection"; + Text = "FormTruckCollection"; + groupBoxTools.ResumeLayout(false); + groupBoxTools.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); + ResumeLayout(false); + } + + #endregion + + private GroupBox groupBoxTools; + private Button buttonAddTruck; + private ComboBox comboBoxSelectorCompany; + private MaskedTextBox maskedTextBoxPosition; + private Button buttonAddDumpTruck; + private PictureBox pictureBox; + private Button buttonRefresh; + private Button buttonGoToCheck; + private Button buttonRemoveTruck; + } +} \ No newline at end of file diff --git a/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.cs b/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.cs new file mode 100644 index 0000000..9069f62 --- /dev/null +++ b/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.cs @@ -0,0 +1,183 @@ +using ProjectDumpTruck.CollectionGenericObjects; +using ProjectDumpTruck.Drawnings; + +namespace ProjectDumpTruck; + +/// +/// Форма работы с компанией и ее коллекцией +/// +public partial class FormTruckCollection : Form +{ + /// + /// Компания + /// + private AbstractCompany? _company = null; + + /// + /// Конструктор + /// + public FormTruckCollection() + { + InitializeComponent(); + } + + /// + /// Выбор компании + /// + /// + /// + private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e) + { + switch (comboBoxSelectorCompany.Text) + { + case "Хранилище": + _company = new TruckParkingService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects()); + break; + } + } + + /// + /// Создание объекта класса-перемещения + /// + /// Тип создаваемого объекта + private void CreateObject(string type) + { + if (_company == null) + { + return; + } + + Random random = new(); + DrawningTruck drawningTruck; + switch (type) + { + case nameof(DrawningTruck): + drawningTruck = new DrawningTruck(random.Next(100, 300), random.Next(1000, 3000), GetColor(random)); + break; + case nameof(DrawningDumpTruck): + drawningTruck = new DrawningDumpTruck(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 + drawningTruck != -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 ButtonAddTruck_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningTruck)); + + /// + /// Добавление самосвала + /// + /// + /// + private void ButtonAddDumpTruck_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningDumpTruck)); + + /// + /// Удаление объекта + /// + /// + /// + private void ButtonRemoveTruck_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 != null) + { + MessageBox.Show("Объект удален"); + pictureBox.Image = _company.Show(); + } + else + { + MessageBox.Show("Не удалось удалить объект"); + } + } + + /// + /// Передача объекта в другую форму + /// + /// + /// + private void ButtonGoToCheck_Click(object sender, EventArgs e) + { + if (_company == null) + { + return; + } + + DrawningTruck? truck = null; + int counter = 100; + while (truck == null) + { + truck = _company.GetRandomObject(); + counter--; + if (counter <= 0) + { + break; + } + } + + if (truck == null) + { + return; + } + + FormTransport form = new FormTransport(); + form.SetTruck = truck; + form.ShowDialog(); + } + + /// + /// Перерисовка коллекции + /// + /// + /// + private void ButtonRefresh_Click(object sender, EventArgs e) + { + if (_company == null) + { + return; + } + + pictureBox.Image = _company.Show(); + } +} \ No newline at end of file diff --git a/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.resx b/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.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/Program.cs b/ProjectDumpTruck/ProjectDumpTruck/Program.cs index b5d5161..589f4a5 100644 --- a/ProjectDumpTruck/ProjectDumpTruck/Program.cs +++ b/ProjectDumpTruck/ProjectDumpTruck/Program.cs @@ -11,7 +11,7 @@ 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 FormTruckCollection()); } } } \ No newline at end of file -- 2.25.1