From cd8d8bdf35fe9e2bdb3eb7268082282bb644e9be Mon Sep 17 00:00:00 2001 From: DanilaSm08 Date: Fri, 29 Mar 2024 00:07:45 +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 | 106 +++++++++ .../CarSharingCompany.cs | 53 +++++ .../ICollectionGenericObjects.cs | 48 ++++ .../MassiveGenericObjects.cs | 97 ++++++++ .../Drawnings/DrawningCar.cs | 2 +- .../FormCarCollection.Designer.cs | 175 ++++++++++++++ .../ProjectCleaningCar/FormCarCollection.cs | 222 ++++++++++++++++++ .../ProjectCleaningCar/FormCarCollection.resx | 120 ++++++++++ .../FormCleaningCar.Designer.cs | 66 ++---- .../ProjectCleaningCar/FormCleaningCar.cs | 56 +---- .../ProjectCleaningCar/Program.cs | 2 +- 11 files changed, 859 insertions(+), 88 deletions(-) create mode 100644 ProjectCleaningCar/ProjectCleaningCar/CollectionGenericObjects/AbstractCompany.cs create mode 100644 ProjectCleaningCar/ProjectCleaningCar/CollectionGenericObjects/CarSharingCompany.cs create mode 100644 ProjectCleaningCar/ProjectCleaningCar/CollectionGenericObjects/ICollectionGenericObjects.cs create mode 100644 ProjectCleaningCar/ProjectCleaningCar/CollectionGenericObjects/MassiveGenericObjects.cs create mode 100644 ProjectCleaningCar/ProjectCleaningCar/FormCarCollection.Designer.cs create mode 100644 ProjectCleaningCar/ProjectCleaningCar/FormCarCollection.cs create mode 100644 ProjectCleaningCar/ProjectCleaningCar/FormCarCollection.resx diff --git a/ProjectCleaningCar/ProjectCleaningCar/CollectionGenericObjects/AbstractCompany.cs b/ProjectCleaningCar/ProjectCleaningCar/CollectionGenericObjects/AbstractCompany.cs new file mode 100644 index 0000000..d97ddb3 --- /dev/null +++ b/ProjectCleaningCar/ProjectCleaningCar/CollectionGenericObjects/AbstractCompany.cs @@ -0,0 +1,106 @@ +using ProjectCleaningCar.Drawnings; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectCleaningCar.CollectionGenericObjects; +/// +/// Абстракция компании, хранящий коллекцию автомобилей +/// +public abstract class AbstractCompany +{ + /// + /// Размер места (ширина) + /// + protected readonly int _placeSizeWidth = 150; + /// + /// Размер места (высота) + /// + protected readonly int _placeSizeHeight = 80; + /// + /// Ширина окна + /// + 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 bool operator +(AbstractCompany company, DrawningCar car) + { + return company._collection?.Insert(car) ?? false; + } + /// + /// Перегрузка оператора удаления для класса + /// + /// Компания + /// Номер удаляемого объекта + /// + public static bool operator -(AbstractCompany company, int position) + { + return company._collection?.Remove(position) ?? false; + } + /// + /// Получение случайного объекта из коллекции + /// + /// + public DrawningCar? 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) + { + DrawningCar? obj = _collection?.Get(i); + obj?.DrawTransport(graphics); + } + return bitmap; + } + /// + /// Вывод заднего фона + /// + /// + protected abstract void DrawBackgound(Graphics g); + /// + /// Расстановка объектов + /// + protected abstract void SetObjectsPosition(); +} diff --git a/ProjectCleaningCar/ProjectCleaningCar/CollectionGenericObjects/CarSharingCompany.cs b/ProjectCleaningCar/ProjectCleaningCar/CollectionGenericObjects/CarSharingCompany.cs new file mode 100644 index 0000000..e51d0f0 --- /dev/null +++ b/ProjectCleaningCar/ProjectCleaningCar/CollectionGenericObjects/CarSharingCompany.cs @@ -0,0 +1,53 @@ +using ProjectCleaningCar.Drawnings; +using System; +using System.Collections.Generic; +using System.Diagnostics.Metrics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectCleaningCar.CollectionGenericObjects; +/// +/// Реализация абстрактной компании - каршеринг +/// +public class CarSharingCompany : AbstractCompany +{ + /// + /// Конструктор + /// + /// + /// + /// + public CarSharingCompany(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 * 190, j * 90, i * 190 + 150, j * 90); + } + g.DrawLine(pen, i * 190, 0, i * 190, 630); + } + } + + protected override void SetObjectsPosition() + { + int counter = 0; + for (int y = 5; y < _pictureHeight; y += 90) + { + for (int x = 5; x < _pictureWidth; x += 190) + { + _collection?.Get(counter)?.SetPictureSize(_pictureWidth, _pictureHeight); + _collection?.Get(counter)?.SetPosition(x, y); + counter++; + } + } + } + +} + diff --git a/ProjectCleaningCar/ProjectCleaningCar/CollectionGenericObjects/ICollectionGenericObjects.cs b/ProjectCleaningCar/ProjectCleaningCar/CollectionGenericObjects/ICollectionGenericObjects.cs new file mode 100644 index 0000000..51961b0 --- /dev/null +++ b/ProjectCleaningCar/ProjectCleaningCar/CollectionGenericObjects/ICollectionGenericObjects.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectCleaningCar.CollectionGenericObjects; +/// +/// Интерфейс описания действий для набора хранимых объектов +/// +/// Параметр: ограничение - ссылочный тип +public interface ICollectionGenericObjects + where T : class +{ + /// + /// Количество объектов в коллекции + /// + int Count { get; } + /// + /// Установка максимального количества элементов + /// + int SetMaxCount { set; } + /// + /// Добавление объекта в коллекцию + /// + /// Добавляемый объект + /// true - вставка прошла удачно, false - вставка не удалась + bool Insert(T obj); + /// + /// Добавление объекта в коллекцию на конкретную позицию + /// + /// Добавляемый объект + /// Позиция + /// true - вставка прошла удачно, false - вставка не удалась + bool Insert(T obj, int position); + /// + /// Удаление объекта из коллекции с конкретной позиции + /// + /// Позиция + /// true - удаление прошло удачно, false - удаление не удалось + bool Remove(int position); + /// + /// Получение объекта по позиции + /// + /// Позиция + /// Объект + T? Get(int position); +} diff --git a/ProjectCleaningCar/ProjectCleaningCar/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectCleaningCar/ProjectCleaningCar/CollectionGenericObjects/MassiveGenericObjects.cs new file mode 100644 index 0000000..f2bcd08 --- /dev/null +++ b/ProjectCleaningCar/ProjectCleaningCar/CollectionGenericObjects/MassiveGenericObjects.cs @@ -0,0 +1,97 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectCleaningCar.CollectionGenericObjects; +/// +/// Параметризованный набор объектов +/// +/// Параметр: ограничение - ссылочный тип +internal 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 >= _collection.Length) + { + throw new IndexOutOfRangeException("Position is out of range."); + } + return _collection[position]; + } + public bool Insert(T obj) + { + for (int i = 0; i < _collection.Length; i++) + { + if (_collection[i] == null) + { + _collection[i] = obj; + return true; + } + } + + return false; + } + public bool Insert(T obj, int position) + { + if (position < 0 || position >= _collection.Length) + { + throw new IndexOutOfRangeException("Position is out of range."); + } + + if (_collection[position] == null) + { + _collection[position] = obj; + return true; + } + + return false; + } + public bool Remove(int position) + { + if (position < 0 || position >= _collection.Length) + { + throw new IndexOutOfRangeException("Position is out of range."); + } + + if (_collection[position] != null) + { + _collection[position] = null; + return true; + } + + return true; + } + +} + diff --git a/ProjectCleaningCar/ProjectCleaningCar/Drawnings/DrawningCar.cs b/ProjectCleaningCar/ProjectCleaningCar/Drawnings/DrawningCar.cs index 8fba228..f2ac935 100644 --- a/ProjectCleaningCar/ProjectCleaningCar/Drawnings/DrawningCar.cs +++ b/ProjectCleaningCar/ProjectCleaningCar/Drawnings/DrawningCar.cs @@ -112,7 +112,7 @@ public class DrawningCar return true; } /// - /// Установка позиция + /// Установка позиции /// /// Координата Х /// Координата Y diff --git a/ProjectCleaningCar/ProjectCleaningCar/FormCarCollection.Designer.cs b/ProjectCleaningCar/ProjectCleaningCar/FormCarCollection.Designer.cs new file mode 100644 index 0000000..94627cb --- /dev/null +++ b/ProjectCleaningCar/ProjectCleaningCar/FormCarCollection.Designer.cs @@ -0,0 +1,175 @@ + +namespace ProjectCleaningCar +{ + 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(); + buttonRemoveCar = new Button(); + maskedTextBoxPosition = new MaskedTextBox(); + buttonAddCleaningCar = new Button(); + buttonAddCar = 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(buttonRemoveCar); + groupBoxTools.Controls.Add(maskedTextBoxPosition); + groupBoxTools.Controls.Add(buttonAddCleaningCar); + groupBoxTools.Controls.Add(buttonAddCar); + groupBoxTools.Controls.Add(comboBoxSelectorCompany); + groupBoxTools.Dock = DockStyle.Right; + groupBoxTools.Location = new Point(933, 0); + groupBoxTools.Name = "groupBoxTools"; + groupBoxTools.Size = new Size(250, 636); + groupBoxTools.TabIndex = 0; + groupBoxTools.TabStop = false; + groupBoxTools.Text = "Инструменты"; + // + // buttonRefresh + // + buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonRefresh.Location = new Point(12, 470); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(226, 69); + 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(12, 378); + buttonGoToCheck.Name = "buttonGoToCheck"; + buttonGoToCheck.Size = new Size(226, 69); + buttonGoToCheck.TabIndex = 5; + buttonGoToCheck.Text = "Передать на тесты"; + buttonGoToCheck.UseVisualStyleBackColor = true; + buttonGoToCheck.Click += buttonGoToCheck_Click; + // + // buttonRemoveCar + // + buttonRemoveCar.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonRemoveCar.Location = new Point(12, 284); + buttonRemoveCar.Name = "buttonRemoveCar"; + buttonRemoveCar.Size = new Size(226, 69); + buttonRemoveCar.TabIndex = 4; + buttonRemoveCar.Text = "Удаление машины"; + buttonRemoveCar.UseVisualStyleBackColor = true; + buttonRemoveCar.Click += buttonRemoveCar_Click; + // + // maskedTextBoxPosition + // + maskedTextBoxPosition.Location = new Point(12, 228); + maskedTextBoxPosition.Mask = "00"; + maskedTextBoxPosition.Name = "maskedTextBoxPosition"; + maskedTextBoxPosition.Size = new Size(226, 27); + maskedTextBoxPosition.TabIndex = 3; + maskedTextBoxPosition.ValidatingType = typeof(int); + maskedTextBoxPosition.MaskInputRejected += maskedTextBoxPosition_MaskInputRejected; + // + // buttonAddCleaningCar + // + buttonAddCleaningCar.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonAddCleaningCar.Location = new Point(12, 129); + buttonAddCleaningCar.Name = "buttonAddCleaningCar"; + buttonAddCleaningCar.Size = new Size(226, 69); + buttonAddCleaningCar.TabIndex = 2; + buttonAddCleaningCar.Text = "Добавление подметально-уборочной машины"; + buttonAddCleaningCar.UseVisualStyleBackColor = true; + buttonAddCleaningCar.Click += buttonAddCleaningCar_Click; + // + // buttonAddCar + // + buttonAddCar.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonAddCar.Location = new Point(12, 69); + buttonAddCar.Name = "buttonAddCar"; + buttonAddCar.Size = new Size(226, 54); + buttonAddCar.TabIndex = 1; + buttonAddCar.Text = "Добавление машины"; + buttonAddCar.UseVisualStyleBackColor = true; + buttonAddCar.Click += buttonAddCar_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(12, 26); + comboBoxSelectorCompany.Name = "comboBoxSelectorCompany"; + comboBoxSelectorCompany.Size = new Size(232, 28); + 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(933, 636); + pictureBox.TabIndex = 1; + pictureBox.TabStop = false; + // + // FormCarCollection + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1183, 636); + 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 comboBoxSelectorCompany; + private Button buttonAddCar; + private Button buttonAddCleaningCar; + private PictureBox pictureBox; + private MaskedTextBox maskedTextBoxPosition; + private Button buttonRemoveCar; + private Button buttonGoToCheck; + private Button buttonRefresh; + } +} \ No newline at end of file diff --git a/ProjectCleaningCar/ProjectCleaningCar/FormCarCollection.cs b/ProjectCleaningCar/ProjectCleaningCar/FormCarCollection.cs new file mode 100644 index 0000000..64f1069 --- /dev/null +++ b/ProjectCleaningCar/ProjectCleaningCar/FormCarCollection.cs @@ -0,0 +1,222 @@ +using ProjectCleaningCar.CollectionGenericObjects; +using ProjectCleaningCar.Drawnings; +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; + +namespace ProjectCleaningCar; +/// +/// Форма работы с компанией и ее коллекцией +/// +public partial class FormCarCollection : Form +{ + /// + /// Компания + /// + private AbstractCompany? _company = null; + + /// + /// Конструктор + /// + public FormCarCollection() + { + InitializeComponent(); + } + + /// + /// Выбор компании + /// + /// + /// + private void comboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e) + { + switch (comboBoxSelectorCompany.Text) + { + case "Хранилище": + _company = new CarSharingCompany(pictureBox.Width, + pictureBox.Height, new MassiveGenericObjects()); + break; + } + } + /// + /// Добавление обычной машины + /// + /// + /// + private void buttonAddCar_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningCar)); + /// + /// Добавление подметально-уборочной машины + /// + /// + /// + private void buttonAddCleaningCar_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningCleaningCar)); + /// + /// Создание объекта класса-перемещения + /// + /// Тип создаваемого объекта + private void CreateObject(string type) + { + if (_company == null) + { + return; + } + Random random = new(); + DrawningCar drawningCar; + switch (type) + { + case nameof(DrawningCar): + drawningCar = new DrawningCar(random.Next(100, 300), + random.Next(1000, 3000), GetColor(random)); + break; + case nameof(DrawningCleaningCar): + // Вызываем диалоговое окно для выбора основного цвета машины + Color bodyColor; + using (ColorDialog dialogBody = new ColorDialog()) + { + if (dialogBody.ShowDialog() == DialogResult.OK) + { + bodyColor = dialogBody.Color; + } + else + { + // Если диалог был закрыт без выбора цвета, выходим из метода + return; + } + } + // Вызываем диалоговое окно для выбора дополнительного цвета машины + Color additionalColor; + using (ColorDialog dialogAdditional = new ColorDialog()) + { + if (dialogAdditional.ShowDialog() == DialogResult.OK) + { + additionalColor = dialogAdditional.Color; + } + else + { + // Если диалог был закрыт без выбора цвета, выходим из метода + return; + } + } + // Создаем объект класса DrawningCleaningCar с выбранными цветами + drawningCar = new DrawningCleaningCar( + random.Next(100, 300), + random.Next(1000, 3000), + bodyColor, + additionalColor, + Convert.ToBoolean(random.Next(0, 2)), + Convert.ToBoolean(random.Next(0, 2))); + break; + default: + return; + } + if (_company + drawningCar) + { + 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 buttonRemoveCar_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) + { + MessageBox.Show("Объект удален"); + pictureBox.Image = _company.Show(); + } + else + { + MessageBox.Show("Не удалось удалить объект"); + } + } + /// + /// Передача объекта в другую форму + /// + /// + /// + private void buttonGoToCheck_Click(object sender, EventArgs e) + { + if (_company == null) + { + return; + } + DrawningCar? car = null; + int counter = 100; + while (car == null) + { + car = _company.GetRandomObject(); + counter--; + if (counter <= 0) + { + break; + } + } + if (car == null) + { + return; + } + FormCleaningCar form = new() + { + SetCar = car + }; + form.ShowDialog(); + } + /// + /// Перерисовка коллекции + /// + /// + /// + private void buttonRefresh_Click(object sender, EventArgs e) + { + if (_company == null) + { + return; + } + pictureBox.Image = _company.Show(); + } + + private void maskedTextBoxPosition_MaskInputRejected(object sender, MaskInputRejectedEventArgs e) + { + + } +} diff --git a/ProjectCleaningCar/ProjectCleaningCar/FormCarCollection.resx b/ProjectCleaningCar/ProjectCleaningCar/FormCarCollection.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectCleaningCar/ProjectCleaningCar/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/ProjectCleaningCar/ProjectCleaningCar/FormCleaningCar.Designer.cs b/ProjectCleaningCar/ProjectCleaningCar/FormCleaningCar.Designer.cs index 36aedca..ca6633d 100644 --- a/ProjectCleaningCar/ProjectCleaningCar/FormCleaningCar.Designer.cs +++ b/ProjectCleaningCar/ProjectCleaningCar/FormCleaningCar.Designer.cs @@ -29,12 +29,10 @@ private void InitializeComponent() { pictureBoxCleaningCar = new PictureBox(); - buttonCreateCleaningCar = new Button(); ButtonUp = new Button(); ButtonRight = new Button(); ButtonLeft = new Button(); ButtonDown = new Button(); - buttonCreateCar = new Button(); comboBoxStrategy = new ComboBox(); buttonStrategyStep = new Button(); ((System.ComponentModel.ISupportInitialize)pictureBoxCleaningCar).BeginInit(); @@ -44,33 +42,24 @@ // pictureBoxCleaningCar.Dock = DockStyle.Fill; pictureBoxCleaningCar.Location = new Point(0, 0); + pictureBoxCleaningCar.Margin = new Padding(3, 4, 3, 4); pictureBoxCleaningCar.Name = "pictureBoxCleaningCar"; - pictureBoxCleaningCar.Size = new Size(884, 461); + pictureBoxCleaningCar.Size = new Size(1010, 615); pictureBoxCleaningCar.SizeMode = PictureBoxSizeMode.AutoSize; pictureBoxCleaningCar.TabIndex = 1; pictureBoxCleaningCar.TabStop = false; pictureBoxCleaningCar.Click += buttonMove_Click; pictureBoxCleaningCar.Resize += PictureBox_Resize; // - // buttonCreateCleaningCar - // - buttonCreateCleaningCar.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonCreateCleaningCar.Location = new Point(22, 409); - buttonCreateCleaningCar.Name = "buttonCreateCleaningCar"; - buttonCreateCleaningCar.Size = new Size(198, 30); - buttonCreateCleaningCar.TabIndex = 2; - buttonCreateCleaningCar.Text = "Создать уборочную машину"; - buttonCreateCleaningCar.UseVisualStyleBackColor = true; - buttonCreateCleaningCar.Click += buttonCreateCleaningCar_Click; - // // ButtonUp // ButtonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; ButtonUp.BackgroundImage = Properties.Resources._1614525823_30_p_strelka_na_belom_fone_33__Up_; ButtonUp.BackgroundImageLayout = ImageLayout.Zoom; - ButtonUp.Location = new Point(761, 373); + ButtonUp.Location = new Point(870, 497); + ButtonUp.Margin = new Padding(3, 4, 3, 4); ButtonUp.Name = "ButtonUp"; - ButtonUp.Size = new Size(30, 30); + ButtonUp.Size = new Size(34, 40); ButtonUp.TabIndex = 3; ButtonUp.UseVisualStyleBackColor = true; ButtonUp.Click += buttonMove_Click; @@ -80,9 +69,10 @@ ButtonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; ButtonRight.BackgroundImage = Properties.Resources._1614525823_30_p_strelka_na_belom_fone__Right_; ButtonRight.BackgroundImageLayout = ImageLayout.Zoom; - ButtonRight.Location = new Point(797, 409); + ButtonRight.Location = new Point(911, 545); + ButtonRight.Margin = new Padding(3, 4, 3, 4); ButtonRight.Name = "ButtonRight"; - ButtonRight.Size = new Size(30, 30); + ButtonRight.Size = new Size(34, 40); ButtonRight.TabIndex = 4; ButtonRight.UseVisualStyleBackColor = true; ButtonRight.Click += buttonMove_Click; @@ -92,9 +82,10 @@ ButtonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; ButtonLeft.BackgroundImage = Properties.Resources._1614525823_30_p_strelka_na_belom_fone_33__Left_; ButtonLeft.BackgroundImageLayout = ImageLayout.Zoom; - ButtonLeft.Location = new Point(725, 409); + ButtonLeft.Location = new Point(829, 545); + ButtonLeft.Margin = new Padding(3, 4, 3, 4); ButtonLeft.Name = "ButtonLeft"; - ButtonLeft.Size = new Size(30, 30); + ButtonLeft.Size = new Size(34, 40); ButtonLeft.TabIndex = 5; ButtonLeft.UseVisualStyleBackColor = true; ButtonLeft.Click += buttonMove_Click; @@ -104,39 +95,31 @@ ButtonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; ButtonDown.BackgroundImage = Properties.Resources._1614525823_30_p_strelka_na_belom_fone_33__Down_; ButtonDown.BackgroundImageLayout = ImageLayout.Zoom; - ButtonDown.Location = new Point(761, 409); + ButtonDown.Location = new Point(870, 545); + ButtonDown.Margin = new Padding(3, 4, 3, 4); ButtonDown.Name = "ButtonDown"; - ButtonDown.Size = new Size(30, 30); + ButtonDown.Size = new Size(34, 40); ButtonDown.TabIndex = 6; ButtonDown.UseVisualStyleBackColor = true; ButtonDown.Click += buttonMove_Click; // - // buttonCreateCar - // - buttonCreateCar.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonCreateCar.Location = new Point(238, 409); - buttonCreateCar.Name = "buttonCreateCar"; - buttonCreateCar.Size = new Size(198, 30); - buttonCreateCar.TabIndex = 7; - buttonCreateCar.Text = "Создать машину"; - buttonCreateCar.UseVisualStyleBackColor = true; - buttonCreateCar.Click += buttonCreateCar_Click; - // // comboBoxStrategy // comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxStrategy.FormattingEnabled = true; comboBoxStrategy.Items.AddRange(new object[] { "К центру ", "К краю" }); - comboBoxStrategy.Location = new Point(761, 12); + comboBoxStrategy.Location = new Point(870, 16); + comboBoxStrategy.Margin = new Padding(3, 4, 3, 4); comboBoxStrategy.Name = "comboBoxStrategy"; - comboBoxStrategy.Size = new Size(121, 23); + comboBoxStrategy.Size = new Size(138, 28); comboBoxStrategy.TabIndex = 8; // // buttonStrategyStep // - buttonStrategyStep.Location = new Point(797, 41); + buttonStrategyStep.Location = new Point(911, 55); + buttonStrategyStep.Margin = new Padding(3, 4, 3, 4); buttonStrategyStep.Name = "buttonStrategyStep"; - buttonStrategyStep.Size = new Size(75, 23); + buttonStrategyStep.Size = new Size(86, 31); buttonStrategyStep.TabIndex = 9; buttonStrategyStep.Text = "Шаг"; buttonStrategyStep.UseVisualStyleBackColor = true; @@ -144,18 +127,17 @@ // // FormCleaningCar // - AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(884, 461); + ClientSize = new Size(1010, 615); Controls.Add(buttonStrategyStep); Controls.Add(comboBoxStrategy); - Controls.Add(buttonCreateCar); Controls.Add(ButtonDown); Controls.Add(ButtonLeft); Controls.Add(ButtonRight); Controls.Add(ButtonUp); - Controls.Add(buttonCreateCleaningCar); Controls.Add(pictureBoxCleaningCar); + Margin = new Padding(3, 4, 3, 4); Name = "FormCleaningCar"; StartPosition = FormStartPosition.CenterScreen; Text = "Подметально-уборочная машина"; @@ -167,12 +149,10 @@ #endregion private PictureBox pictureBoxCleaningCar; - private Button buttonCreateCleaningCar; private Button ButtonUp; private Button ButtonRight; private Button ButtonLeft; private Button ButtonDown; - private Button buttonCreateCar; private ComboBox comboBoxStrategy; private Button buttonStrategyStep; } diff --git a/ProjectCleaningCar/ProjectCleaningCar/FormCleaningCar.cs b/ProjectCleaningCar/ProjectCleaningCar/FormCleaningCar.cs index c389bac..21cfacb 100644 --- a/ProjectCleaningCar/ProjectCleaningCar/FormCleaningCar.cs +++ b/ProjectCleaningCar/ProjectCleaningCar/FormCleaningCar.cs @@ -27,6 +27,19 @@ namespace ProjectCleaningCar /// private AbstractStrategy? _strategy; + public DrawningCar SetCar + { + set + { + _drawningCar = value; + _drawningCar.SetPictureSize(pictureBoxCleaningCar.Width, + pictureBoxCleaningCar.Height); + comboBoxStrategy.Enabled = true; + _strategy = null; + Draw(); + } + } + /// /// Конструктор формы /// @@ -50,49 +63,6 @@ namespace ProjectCleaningCar _drawningCar.DrawTransport(gr); pictureBoxCleaningCar.Image = bmp; } - - /// - /// Создание объекта класса-перемещения - /// - /// Тип создаваемоего объекта - private void CreateObject(string type) - { - Random random = new(); - switch (type) - { - case nameof(DrawningCar): - _drawningCar = new DrawningCar(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(DrawningCleaningCar): - _drawningCar = new DrawningCleaningCar(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; - } - _drawningCar.SetPictureSize(pictureBoxCleaningCar.Width, pictureBoxCleaningCar.Height); - _drawningCar.SetPosition(random.Next(10, 100), random.Next(10, 100)); - _strategy = null; - comboBoxStrategy.Enabled = true; - Draw(); - } - - /// - /// Обработка нажатия кнопки "Создать подметально-уборочную машину" - /// - /// - /// - private void buttonCreateCleaningCar_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningCleaningCar)); - - /// - /// Обработка нажатия кнопки "Создать машину" - /// - /// - /// - private void buttonCreateCar_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningCar)); /// /// Перемещение объекта по форме (нажатие кнопок навигации) diff --git a/ProjectCleaningCar/ProjectCleaningCar/Program.cs b/ProjectCleaningCar/ProjectCleaningCar/Program.cs index 67932ee..302dca5 100644 --- a/ProjectCleaningCar/ProjectCleaningCar/Program.cs +++ b/ProjectCleaningCar/ProjectCleaningCar/Program.cs @@ -11,7 +11,7 @@ namespace ProjectCleaningCar // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormCleaningCar()); + Application.Run(new FormCarCollection()); } } } \ No newline at end of file