diff --git a/Lab1_OAP/Lab1_OAP.sln b/Lab1_OAP/Lab1_OAP.sln deleted file mode 100644 index 92627e6..0000000 --- a/Lab1_OAP/Lab1_OAP.sln +++ /dev/null @@ -1,31 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.8.34525.116 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Lab1_OAP", "Lab1_OAP\Lab1_OAP.vcxproj", "{39E703FF-4168-4ACA-84CA-CDD94BFE3FD3}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|x64 = Debug|x64 - Debug|x86 = Debug|x86 - Release|x64 = Release|x64 - Release|x86 = Release|x86 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {39E703FF-4168-4ACA-84CA-CDD94BFE3FD3}.Debug|x64.ActiveCfg = Debug|x64 - {39E703FF-4168-4ACA-84CA-CDD94BFE3FD3}.Debug|x64.Build.0 = Debug|x64 - {39E703FF-4168-4ACA-84CA-CDD94BFE3FD3}.Debug|x86.ActiveCfg = Debug|Win32 - {39E703FF-4168-4ACA-84CA-CDD94BFE3FD3}.Debug|x86.Build.0 = Debug|Win32 - {39E703FF-4168-4ACA-84CA-CDD94BFE3FD3}.Release|x64.ActiveCfg = Release|x64 - {39E703FF-4168-4ACA-84CA-CDD94BFE3FD3}.Release|x64.Build.0 = Release|x64 - {39E703FF-4168-4ACA-84CA-CDD94BFE3FD3}.Release|x86.ActiveCfg = Release|Win32 - {39E703FF-4168-4ACA-84CA-CDD94BFE3FD3}.Release|x86.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {AD8890FA-E7D7-4EB8-996C-597872ABE83B} - EndGlobalSection -EndGlobal diff --git a/Lab1_OAP/Lab1_OAP/Lab1_OAP.cpp b/Lab1_OAP/Lab1_OAP/Lab1_OAP.cpp deleted file mode 100644 index 5f28270..0000000 --- a/Lab1_OAP/Lab1_OAP/Lab1_OAP.cpp +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/Lab1_OAP/Lab1_OAP/Lab1_OAP.vcxproj b/Lab1_OAP/Lab1_OAP/Lab1_OAP.vcxproj deleted file mode 100644 index 7b4bd6f..0000000 --- a/Lab1_OAP/Lab1_OAP/Lab1_OAP.vcxproj +++ /dev/null @@ -1,135 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - 17.0 - Win32Proj - {39e703ff-4168-4aca-84ca-cdd94bfe3fd3} - Lab1OAP - 10.0 - - - - Application - true - v143 - Unicode - - - Application - false - v143 - true - Unicode - - - Application - true - v143 - Unicode - - - Application - false - v143 - true - Unicode - - - - - - - - - - - - - - - - - - - - - - Level3 - true - WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - - - - - Level3 - true - true - true - WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - true - true - - - - - Level3 - true - _DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - - - - - Level3 - true - true - true - NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - true - true - - - - - - - - - \ No newline at end of file diff --git a/Lab1_OAP/Lab1_OAP/Lab1_OAP.vcxproj.filters b/Lab1_OAP/Lab1_OAP/Lab1_OAP.vcxproj.filters deleted file mode 100644 index 0805cb7..0000000 --- a/Lab1_OAP/Lab1_OAP/Lab1_OAP.vcxproj.filters +++ /dev/null @@ -1,22 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - - - Исходные файлы - - - \ No newline at end of file diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/AbstractCompany.cs b/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/AbstractCompany.cs new file mode 100644 index 0000000..0549301 --- /dev/null +++ b/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/AbstractCompany.cs @@ -0,0 +1,119 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ProjectGasolineTanker.Drawings; + + +namespace ProjectGasolineTanker.CollectionGenericObjects; + +public abstract class AbstractCompany +{ + /// + /// Размер места (ширина) + /// + protected readonly int _placeSizeWidth = 210; + + /// + /// Размер места (высота) + /// + protected readonly int _placeSizeHeight = 110; + + /// + /// Ширина окна + /// + 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, DrawingTanker tanker) + { + return company._collection.Insert(tanker); + } + + /// + /// Перегрузка оператора удаления для класса + /// + /// Компания + /// Номер удаляемого объекта + /// + public static DrawingTanker operator -(AbstractCompany company, int position) + { + return company._collection.Remove(position); + } + + /// + /// Получение случайного объекта из коллекции + /// + /// + public DrawingTanker? 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) + { + DrawingTanker? obj = _collection?.Get(i); + obj?.DrawTransport(graphics); + } + + return bitmap; + } + + /// + /// Вывод заднего фона + /// + /// + protected abstract void DrawBackgound(Graphics g); + + /// + /// Расстановка объектов + /// + protected abstract void SetObjectsPosition(); +} diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/ICollectionGenericObjects.cs b/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/ICollectionGenericObjects.cs new file mode 100644 index 0000000..1c71a8c --- /dev/null +++ b/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/ICollectionGenericObjects.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectGasolineTanker.CollectionGenericObjects; + +/// +/// Интерфейс описания действий для набора хранимых объектов +/// +/// Параметр: ограничение - ссылочный тип +public interface ICollectionGenericObjects + where T : class +{ + /// + /// Количество объектов в коллекции + /// + int Count { get; } + + /// + /// Установка максимального количества элементов + /// + int SetMaxCount { set; } + + /// + /// Добавление объекта в коллекцию + /// + /// Добавляемый объект + /// true - вставка прошла удачно, false - вставка не удалась + int Insert(T obj); + + /// + /// Добавление объекта в коллекцию на конкретную позицию + /// + /// Добавляемый объект + /// Позиция + /// 1 - вставка прошла удачно, -1 - вставка не удалась + int Insert(T obj, int position); + + /// + /// Удаление объекта из коллекции с конкретной позиции + /// + /// Позиция + /// + T? Remove(int position); + + /// + /// Получение объекта по позиции + /// + /// Позиция + /// Объект + T? Get(int position); +} diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/MassiveGenericObjects.cs new file mode 100644 index 0000000..bf37cd7 --- /dev/null +++ b/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/MassiveGenericObjects.cs @@ -0,0 +1,115 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectGasolineTanker.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 null; + return _collection[position]; + } + + public int Insert(T obj) + { + for (int i = 0; i < Count; i++) + { + if (_collection[i] == null) + { + _collection[i] = obj; + return i; + } + } + return -1; + } + + public int Insert(T obj, int position) + { + if (position < 0 || position >= Count) + return -1; + + if (_collection[position] == null) + { + _collection[position] = obj; + return position; + } + + int temp = position + 1; + while (temp < Count) + { + if (_collection[temp] == null) + { + _collection[temp] = obj; + return temp; + } + temp++; + } + + temp = position - 1; + while (temp > 0) + { + if (_collection[temp] == null) + { + _collection[temp] = obj; + return temp; + } + temp--; + } + + return -1; + } + + public T? Remove(int position) + { + if (position < 0 || position >= Count) + return null; + + if (_collection[position] == null) + { + return null; + } + + T? temp = _collection[position]; + _collection[position] = null; + return temp; + } +} diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/TankerSharingService.cs b/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/TankerSharingService.cs new file mode 100644 index 0000000..c387201 --- /dev/null +++ b/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/TankerSharingService.cs @@ -0,0 +1,60 @@ +using ProjectGasolineTanker.Drawings; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectGasolineTanker.CollectionGenericObjects; + +public class TankerSharingService : AbstractCompany +{ + public TankerSharingService(int picWidth, int picHeight, ICollectionGenericObjects collection) : base(picWidth, picHeight, collection) + { + } + + protected override void DrawBackgound(Graphics g) + { + Pen pen = new(Color.Black, 4); + for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++) + { + for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j) + { + g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, + i * _placeSizeWidth + _placeSizeWidth - 40, j * _placeSizeHeight); + } + g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight); + } + } + + protected override void SetObjectsPosition() + { + int width = _pictureWidth / _placeSizeWidth; + int height = _pictureHeight / _placeSizeHeight; + + int curWidth = 0; + 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 + 10, curHeight * _placeSizeHeight + 5); + } + + if (curWidth < width - 1) + curWidth++; + else + { + curWidth = 0; + curHeight--; + } + if (curHeight < 0) + { + return; + } + } + } +} + diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/FormGasolineTanker.Designer.cs b/ProjectGasolineTanker/ProjectGasolineTanker/FormGasolineTanker.Designer.cs index 2e74d11..fedcea3 100644 --- a/ProjectGasolineTanker/ProjectGasolineTanker/FormGasolineTanker.Designer.cs +++ b/ProjectGasolineTanker/ProjectGasolineTanker/FormGasolineTanker.Designer.cs @@ -29,12 +29,10 @@ private void InitializeComponent() { pictureBoxGasolineTanker = new PictureBox(); - buttonCreateGasolineTanker = new Button(); buttonLeft = new Button(); buttonDown = new Button(); buttonRight = new Button(); buttonUp = new Button(); - buttonCreateTanker = new Button(); comboBoxStrategy = new ComboBox(); buttonStrategyStep = new Button(); ((System.ComponentModel.ISupportInitialize)pictureBoxGasolineTanker).BeginInit(); @@ -49,17 +47,6 @@ pictureBoxGasolineTanker.TabIndex = 0; pictureBoxGasolineTanker.TabStop = false; // - // buttonCreateGasolineTanker - // - buttonCreateGasolineTanker.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonCreateGasolineTanker.Location = new Point(12, 682); - buttonCreateGasolineTanker.Name = "buttonCreateGasolineTanker"; - buttonCreateGasolineTanker.Size = new Size(230, 34); - buttonCreateGasolineTanker.TabIndex = 1; - buttonCreateGasolineTanker.Text = "Создать Бензовоз"; - buttonCreateGasolineTanker.UseVisualStyleBackColor = true; - buttonCreateGasolineTanker.Click += buttonCreateGasolineTanker_Click; - // // buttonLeft // buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; @@ -108,17 +95,6 @@ buttonUp.UseVisualStyleBackColor = true; buttonUp.Click += ButtonMove_Click; // - // buttonCreateTanker - // - buttonCreateTanker.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonCreateTanker.Location = new Point(248, 682); - buttonCreateTanker.Name = "buttonCreateTanker"; - buttonCreateTanker.Size = new Size(230, 34); - buttonCreateTanker.TabIndex = 6; - buttonCreateTanker.Text = "Создать Грузовик"; - buttonCreateTanker.UseVisualStyleBackColor = true; - buttonCreateTanker.Click += buttonCreateTanker_Click; - // // comboBoxStrategy // comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList; @@ -146,12 +122,10 @@ ClientSize = new Size(1312, 749); Controls.Add(buttonStrategyStep); Controls.Add(comboBoxStrategy); - Controls.Add(buttonCreateTanker); Controls.Add(buttonUp); Controls.Add(buttonRight); Controls.Add(buttonDown); Controls.Add(buttonLeft); - Controls.Add(buttonCreateGasolineTanker); Controls.Add(pictureBoxGasolineTanker); Name = "FormGasolineTanker"; Text = "Бензовоз"; @@ -162,12 +136,10 @@ #endregion private PictureBox pictureBoxGasolineTanker; - private Button buttonCreateGasolineTanker; private Button buttonLeft; private Button buttonDown; private Button buttonRight; private Button buttonUp; - private Button buttonCreateTanker; private ComboBox comboBoxStrategy; private Button buttonStrategyStep; } diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/FormGasolineTanker.cs b/ProjectGasolineTanker/ProjectGasolineTanker/FormGasolineTanker.cs index ba4eed7..c48ea75 100644 --- a/ProjectGasolineTanker/ProjectGasolineTanker/FormGasolineTanker.cs +++ b/ProjectGasolineTanker/ProjectGasolineTanker/FormGasolineTanker.cs @@ -24,6 +24,18 @@ namespace ProjectGasolineTanker /// private AbstractStrategy? _strategy; + public DrawingTanker SetTanker + { + set + { + _drawingTanker = value; + _drawingTanker.SetPictureSize(pictureBoxGasolineTanker.Width, pictureBoxGasolineTanker.Height); + comboBoxStrategy.Enabled = true; + _strategy = null; + Draw(); + } + } + /// /// Конструктор формы /// @@ -46,49 +58,6 @@ namespace ProjectGasolineTanker pictureBoxGasolineTanker.Image = bmp; } - private void CreateObject(string type) - { - Random random = new(); - switch (type) - { - case nameof(DrawingTanker): - _drawingTanker = new DrawingTanker(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(DrawingGasolineTanker): - _drawingTanker = new DrawingGasolineTanker(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; - } - _drawingTanker.SetPictureSize(pictureBoxGasolineTanker.Width, pictureBoxGasolineTanker.Height); - _drawingTanker.SetPosition(random.Next(10, 100), random.Next(10, 100)); - _strategy = null; - comboBoxStrategy.Enabled = true; - Draw(); - } - - - - - /// - /// Обработка нажатия кнопки создать - /// - /// - /// - private void buttonCreateGasolineTanker_Click(object sender, EventArgs e) - { - CreateObject(nameof(DrawingGasolineTanker)); - } - - private void buttonCreateTanker_Click(object sender, EventArgs e) - { - CreateObject(nameof(DrawingTanker)); - } - /// /// Перемещение объекта по форме (нажатие кнопок навигации) /// diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/FormTankerCollection.Designer.cs b/ProjectGasolineTanker/ProjectGasolineTanker/FormTankerCollection.Designer.cs new file mode 100644 index 0000000..f67f5a7 --- /dev/null +++ b/ProjectGasolineTanker/ProjectGasolineTanker/FormTankerCollection.Designer.cs @@ -0,0 +1,173 @@ +namespace ProjectGasolineTanker +{ + partial class FormTankerCollection + { + /// + /// 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(); + buttonDelTanker = new Button(); + maskedTextBox1 = new MaskedTextBox(); + buttonAddGasolineTanker = new Button(); + buttonAddTanker = 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(buttonDelTanker); + groupBoxTools.Controls.Add(maskedTextBox1); + groupBoxTools.Controls.Add(buttonAddGasolineTanker); + groupBoxTools.Controls.Add(buttonAddTanker); + groupBoxTools.Controls.Add(comboBoxSelectorCompany); + groupBoxTools.Dock = DockStyle.Right; + groupBoxTools.Location = new Point(1095, 0); + groupBoxTools.Name = "groupBoxTools"; + groupBoxTools.Size = new Size(254, 681); + groupBoxTools.TabIndex = 0; + groupBoxTools.TabStop = false; + groupBoxTools.Text = "Инструменты"; + // + // buttonRefresh + // + buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonRefresh.Location = new Point(16, 522); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(226, 55); + 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(16, 426); + buttonGoToCheck.Name = "buttonGoToCheck"; + buttonGoToCheck.Size = new Size(226, 55); + buttonGoToCheck.TabIndex = 5; + buttonGoToCheck.Text = "Передать на тесты"; + buttonGoToCheck.UseVisualStyleBackColor = true; + buttonGoToCheck.Click += buttonGoToCheck_Click; + // + // buttonDelTanker + // + buttonDelTanker.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonDelTanker.Location = new Point(16, 325); + buttonDelTanker.Name = "buttonDelTanker"; + buttonDelTanker.Size = new Size(226, 55); + buttonDelTanker.TabIndex = 4; + buttonDelTanker.Text = "Удаление грузовика"; + buttonDelTanker.UseVisualStyleBackColor = true; + buttonDelTanker.Click += buttonDelTanker_Click_1; + // + // maskedTextBox1 + // + maskedTextBox1.Location = new Point(16, 262); + maskedTextBox1.Mask = "00"; + maskedTextBox1.Name = "maskedTextBox1"; + maskedTextBox1.Size = new Size(150, 31); + maskedTextBox1.TabIndex = 3; + maskedTextBox1.ValidatingType = typeof(int); + // + // buttonAddGasolineTanker + // + buttonAddGasolineTanker.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonAddGasolineTanker.Location = new Point(16, 179); + buttonAddGasolineTanker.Name = "buttonAddGasolineTanker"; + buttonAddGasolineTanker.Size = new Size(226, 55); + buttonAddGasolineTanker.TabIndex = 2; + buttonAddGasolineTanker.Text = "Добавление Бензовоза"; + buttonAddGasolineTanker.UseVisualStyleBackColor = true; + buttonAddGasolineTanker.Click += buttonAddGasolineTanker_Click_1; + // + // buttonAddTanker + // + buttonAddTanker.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonAddTanker.Location = new Point(16, 118); + buttonAddTanker.Name = "buttonAddTanker"; + buttonAddTanker.Size = new Size(226, 55); + buttonAddTanker.TabIndex = 1; + buttonAddTanker.Text = "Добавление грузовика"; + buttonAddTanker.UseVisualStyleBackColor = true; + buttonAddTanker.Click += buttonAddTanker_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(16, 30); + comboBoxSelectorCompany.Name = "comboBoxSelectorCompany"; + comboBoxSelectorCompany.Size = new Size(226, 33); + comboBoxSelectorCompany.TabIndex = 0; + comboBoxSelectorCompany.SelectedIndexChanged += comboBoxSelectorCompany_SelectedIndexChanged_1; + // + // pictureBox + // + pictureBox.Dock = DockStyle.Fill; + pictureBox.Location = new Point(0, 0); + pictureBox.Name = "pictureBox"; + pictureBox.Size = new Size(1095, 681); + pictureBox.TabIndex = 1; + pictureBox.TabStop = false; + // + // FormTankerCollection + // + AutoScaleDimensions = new SizeF(10F, 25F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1349, 681); + Controls.Add(pictureBox); + Controls.Add(groupBoxTools); + Name = "FormTankerCollection"; + Text = "Коллекция Грузовиков"; + groupBoxTools.ResumeLayout(false); + groupBoxTools.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); + ResumeLayout(false); + } + + #endregion + + private GroupBox groupBoxTools; + private ComboBox comboBoxSelectorCompany; + private Button buttonAddGasolineTanker; + private Button buttonAddTanker; + private MaskedTextBox maskedTextBox1; + private PictureBox pictureBox; + private Button buttonRefresh; + private Button buttonGoToCheck; + private Button buttonDelTanker; + } +} \ No newline at end of file diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/FormTankerCollection.cs b/ProjectGasolineTanker/ProjectGasolineTanker/FormTankerCollection.cs new file mode 100644 index 0000000..3e63ca6 --- /dev/null +++ b/ProjectGasolineTanker/ProjectGasolineTanker/FormTankerCollection.cs @@ -0,0 +1,194 @@ +using ProjectGasolineTanker.CollectionGenericObjects; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using ProjectGasolineTanker.Drawings; + +namespace ProjectGasolineTanker; + +public partial class FormTankerCollection : Form +{ + /// + /// Компания + /// + private AbstractCompany? _company = null; + + /// + /// Конструктор + /// + public FormTankerCollection() + { + InitializeComponent(); + } + + /// + /// Выбор компании + /// + /// + /// + private void comboBoxSelectorCompany_SelectedIndexChanged_1(object sender, EventArgs e) + { + switch (comboBoxSelectorCompany.Text) + { + case "Хранилище": + _company = new TankerSharingService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects()); + break; + } + } + + /// + /// Создание объекта класса-перемещения + /// + /// Тип создаваемого объекта + private void CreateObject(string type) + { + if (_company == null) + { + return; + } + Random random = new(); + DrawingTanker drawingTanker; + switch (type) + { + case nameof(DrawingTanker): + drawingTanker = new DrawingTanker(random.Next(100, 300), random.Next(1000, 3000), GetColor(random)); + break; + case nameof(DrawingGasolineTanker): + drawingTanker = new DrawingGasolineTanker(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 + drawingTanker != -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 buttonAddTanker_Click(object sender, EventArgs e) => CreateObject(nameof(DrawingTanker)); + + /// + /// Добавление самолета с радаром + /// + /// + /// + private void buttonAddGasolineTanker_Click_1(object sender, EventArgs e) => CreateObject(nameof(DrawingGasolineTanker)); + + /// + /// Удаление объекта + /// + /// + /// + private void buttonDelTanker_Click_1(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(maskedTextBox1.Text) || _company == null) + { + return; + } + + if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) + { + return; + } + + int pos = Convert.ToInt32(maskedTextBox1.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; + } + + DrawingTanker? tanker = null; + int counter = 100; + while (tanker == null) + { + tanker = _company.GetRandomObject(); + counter--; + if (counter <= 0) + { + break; + } + } + + if (tanker == null) + { + return; + } + + FormGasolineTanker form = new() + { + SetTanker = tanker + }; + form.ShowDialog(); + } + + /// + /// Перерисовка коллекции + /// + /// + /// + private void buttonRefresh_Click(object sender, EventArgs e) + { + if (_company == null) + { + return; + } + + pictureBox.Image = _company.Show(); + } +} diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/FormTankerCollection.resx b/ProjectGasolineTanker/ProjectGasolineTanker/FormTankerCollection.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectGasolineTanker/ProjectGasolineTanker/FormTankerCollection.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/ProjectGasolineTanker/ProjectGasolineTanker/Program.cs b/ProjectGasolineTanker/ProjectGasolineTanker/Program.cs index 12d41fa..913060e 100644 --- a/ProjectGasolineTanker/ProjectGasolineTanker/Program.cs +++ b/ProjectGasolineTanker/ProjectGasolineTanker/Program.cs @@ -11,7 +11,7 @@ namespace ProjectGasolineTanker // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormGasolineTanker()); + Application.Run(new FormTankerCollection()); } } } \ No newline at end of file diff --git a/laboap1/laboap1.sln b/laboap1/laboap1.sln deleted file mode 100644 index 9f5ffa8..0000000 --- a/laboap1/laboap1.sln +++ /dev/null @@ -1,31 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.8.34525.116 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "laboap1", "laboap1\laboap1.vcxproj", "{1F4724C2-6BC1-42C2-ACC1-93AAA85BA624}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|x64 = Debug|x64 - Debug|x86 = Debug|x86 - Release|x64 = Release|x64 - Release|x86 = Release|x86 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {1F4724C2-6BC1-42C2-ACC1-93AAA85BA624}.Debug|x64.ActiveCfg = Debug|x64 - {1F4724C2-6BC1-42C2-ACC1-93AAA85BA624}.Debug|x64.Build.0 = Debug|x64 - {1F4724C2-6BC1-42C2-ACC1-93AAA85BA624}.Debug|x86.ActiveCfg = Debug|Win32 - {1F4724C2-6BC1-42C2-ACC1-93AAA85BA624}.Debug|x86.Build.0 = Debug|Win32 - {1F4724C2-6BC1-42C2-ACC1-93AAA85BA624}.Release|x64.ActiveCfg = Release|x64 - {1F4724C2-6BC1-42C2-ACC1-93AAA85BA624}.Release|x64.Build.0 = Release|x64 - {1F4724C2-6BC1-42C2-ACC1-93AAA85BA624}.Release|x86.ActiveCfg = Release|Win32 - {1F4724C2-6BC1-42C2-ACC1-93AAA85BA624}.Release|x86.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {898933DD-7FA8-4FA7-872F-63991ACB024A} - EndGlobalSection -EndGlobal diff --git a/laboap1/laboap1/laboap1.cpp b/laboap1/laboap1/laboap1.cpp deleted file mode 100644 index 0329b66..0000000 --- a/laboap1/laboap1/laboap1.cpp +++ /dev/null @@ -1,151 +0,0 @@ -#include -#include -#include - -void printArray(int arr[], int size) { - for (int i = 0; i < size; i++) { - printf("%d ", arr[i]); - } - printf("\n"); -} - -void insertionSort(int arr[], int size) { - int i, key, j; - for (i = 1; i < size; i++) { - key = arr[i]; - j = i - 1; - - while (j >= 0 && arr[j] > key) { - arr[j + 1] = arr[j]; - j = j - 1; - } - arr[j + 1] = key; - } -} - -void merge(int arr[], int left, int mid, int right) { - int i, j, k; - int n1 = mid - left + 1; - int n2 = right - mid; - - int L[n1], R[n2]; - - for (i = 0; i < n1; i++) - L[i] = arr[left + i]; - for (j = 0; j < n2; j++) - R[j] = arr[mid + 1 + j]; - - i = 0; - j = 0; - k = left; - while (i < n1 && j < n2) { - if (L[i] <= R[j]) { - arr[k] = L[i]; - i++; - } - else { - arr[k] = R[j]; - j++; - } - k++; - } - - while (i < n1) { - arr[k] = L[i]; - i++; - k++; - } - - while (j < n2) { - arr[k] = R[j]; - j++; - k++; - } -} - -void mergeSort(int arr[], int left, int right) { - if (left < right) { - int mid = left + (right - left) / 2; - - mergeSort(arr, left, mid); - mergeSort(arr, mid + 1, right); - - merge(arr, left, mid, right); - } -} - -int main() { - srand(time(0)); - - int size; - printf("Enter the size of the array: "); - scanf("%d", &size); - - int arr[size]; - for (int i = 0; i < size; i++) { - arr[i] = rand() % 100; - } - - printf("Randomly generated array: "); - printArray(arr, size); - - int choice; - printf("Enter 1 to delete an element, 2 to insert a new element: "); - scanf("%d", &choice); - - if (choice == 1) { - int index; - printf("Enter the index of the element you want to delete: "); - scanf("%d", &index); - - for (int i = index; i < size - 1; i++) { - arr[i] = arr[i + 1]; - } - size--; - } - else if (choice == 2) { - int index, element; - printf("Enter the index at which you want to insert the new element: "); - scanf("%d", &index); - printf("Enter the new element: "); - scanf("%d", &element); - - for (int i = size; i > index; i--) { - arr[i] = arr[i - 1]; - } - arr[index] = element; - size++; - } - else { - printf("Invalid choice"); - return 0; - } - - printf("Modified array: "); - printArray(arr, size); - - int arr_copy[size]; - for (int i = 0; i < size; i++) { - arr_copy[i] = arr[i]; - } - - clock_t start_time = clock(); - insertionSort(arr, size); - clock_t end_time = clock(); - double insertion_time = ((double)(end_time - start_time)) / CLOCKS_PER_SEC; - - printf("Array sorted using Insertion Sort: "); - printArray(arr, size); - printf("Time taken by Insertion Sort: %f seconds\n", insertion_time); - - start_time = clock(); - mergeSort(arr_copy, 0, size - 1); - end_time = clock(); - double merge_time = ((double)(end_time - start_time)) / CLOCKS_PER_SEC; - - printf("Array sorted using Merge Sort: "); - printArray(arr_copy, size); - printf("Time taken by Merge Sort: %f seconds\n", merge_time); - - return 0; -} \ No newline at end of file diff --git a/laboap1/laboap1/laboap1.vcxproj b/laboap1/laboap1/laboap1.vcxproj deleted file mode 100644 index 085cb5f..0000000 --- a/laboap1/laboap1/laboap1.vcxproj +++ /dev/null @@ -1,136 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - 17.0 - Win32Proj - {1f4724c2-6bc1-42c2-acc1-93aaa85ba624} - laboap1 - 10.0 - - - - Application - true - v143 - Unicode - - - Application - false - v143 - true - Unicode - - - Application - true - v143 - Unicode - - - Application - false - v143 - true - Unicode - - - - - - - - - - - - - - - - - - - - - - Level3 - true - WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - - - - - Level3 - true - true - true - WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - true - true - - - - - Level3 - true - _DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - Default - - - Console - true - - - - - Level3 - true - true - true - NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - true - true - - - - - - - - - \ No newline at end of file diff --git a/laboap1/laboap1/laboap1.vcxproj.filters b/laboap1/laboap1/laboap1.vcxproj.filters deleted file mode 100644 index 2bff827..0000000 --- a/laboap1/laboap1/laboap1.vcxproj.filters +++ /dev/null @@ -1,22 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - - - Исходные файлы - - - \ No newline at end of file