From 29edab25335ce2589d7a4649c38b20aa7cc4a69d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=B8=D0=BB=D1=8C=D1=8F?= Date: Fri, 26 Apr 2024 18:04:35 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B0=D0=BF=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbstractCompany.cs | 115 +++++++++++ .../ICollectionGenericObjects.cs | 45 +++++ .../LocomotiveDockingService.cs | 65 +++++++ .../MassiveGenericObjects.cs | 97 +++++++++ .../FormLocomotive.Designer.cs | 68 ++----- .../ProjectLocomotive/FormLocomotive.cs | 79 +++----- .../FormLocomotivesCollection.Designer.cs | 184 ++++++++++++++++++ .../FormLocomotivesCollection.cs | 169 ++++++++++++++++ .../FormLocomotivesCollection.resx | 120 ++++++++++++ .../ProjectLocomotive/Program.cs | 7 +- 10 files changed, 835 insertions(+), 114 deletions(-) create mode 100644 ProjectLocomotive/ProjectLocomotive/CollectionGenericObjects/AbstractCompany.cs create mode 100644 ProjectLocomotive/ProjectLocomotive/CollectionGenericObjects/ICollectionGenericObjects.cs create mode 100644 ProjectLocomotive/ProjectLocomotive/CollectionGenericObjects/LocomotiveDockingService.cs create mode 100644 ProjectLocomotive/ProjectLocomotive/CollectionGenericObjects/MassiveGenericObjects.cs create mode 100644 ProjectLocomotive/ProjectLocomotive/FormLocomotivesCollection.Designer.cs create mode 100644 ProjectLocomotive/ProjectLocomotive/FormLocomotivesCollection.cs create mode 100644 ProjectLocomotive/ProjectLocomotive/FormLocomotivesCollection.resx diff --git a/ProjectLocomotive/ProjectLocomotive/CollectionGenericObjects/AbstractCompany.cs b/ProjectLocomotive/ProjectLocomotive/CollectionGenericObjects/AbstractCompany.cs new file mode 100644 index 0000000..3ea6809 --- /dev/null +++ b/ProjectLocomotive/ProjectLocomotive/CollectionGenericObjects/AbstractCompany.cs @@ -0,0 +1,115 @@ +using ProjectLocomotive.Drawnings; + +namespace ProjectLocomotive.CollectionGenericObjects +{ + /// + /// Абстракция компании, хранящий коллекцию автомобилей + /// + public abstract class AbstractCompany + { + /// + /// Размер места (ширина) + /// + protected readonly int _placeSizeWidth = 180; + + /// + /// Размер места (высота) + /// + protected readonly int _placeSizeHeight = 70; + + /// + /// Ширина окна + /// + 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, DrawningLocomotive сruiser) + { + return company._collection.Insert(сruiser); + } + + /// + /// Перегрузка оператора удаления для класса + /// + /// Компания + /// Номер удаляемого объекта + /// + public static DrawningLocomotive operator -(AbstractCompany company, int position) + { + return company._collection?.Remove(position); + } + + /// + /// Получение случайного объекта из коллекции + /// + /// + public DrawningLocomotive? 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) + { + DrawningLocomotive? obj = _collection?.Get(i); + obj?.DrawTransport(graphics); + } + return bitmap; + } + /// + /// Вывод заднего фона + /// + /// + protected abstract void DrawBackgound(Graphics g); + + /// + /// Расстановка объектов + /// + protected abstract void SetObjectsPosition(); + } +} diff --git a/ProjectLocomotive/ProjectLocomotive/CollectionGenericObjects/ICollectionGenericObjects.cs b/ProjectLocomotive/ProjectLocomotive/CollectionGenericObjects/ICollectionGenericObjects.cs new file mode 100644 index 0000000..21475a1 --- /dev/null +++ b/ProjectLocomotive/ProjectLocomotive/CollectionGenericObjects/ICollectionGenericObjects.cs @@ -0,0 +1,45 @@ +namespace ProjectLocomotive.CollectionGenericObjects +{ + /// + /// Интерфейс описания действий для набора хранимых объектов + /// + /// Параметр: ограничение - ссылочный тип + public interface ICollectionGenericObjects + where T : class + { + /// + /// Количество объектов в коллекции + /// + int Count { get; } + /// + /// Установка максимального количества элементов + /// + int SetMaxCount { set; } + /// + /// Добавление объекта в коллекцию + /// + /// Добавляемый объект + /// true - вставка прошла удачно, false - вставка не удалась + int Insert(T obj); + /// + /// Добавление объекта в коллекцию на конкретную позицию + /// + /// Добавляемый объект + /// Позиция + /// true - вставка прошла удачно, false - вставка не удалась + int Insert(T obj, int position); + /// + /// Удаление объекта из коллекции с конкретной позиции + /// + /// Позиция + /// true - удаление прошло удачно, false - удаление не удалось + T? Remove(int position); + /// + /// Получение объекта по позиции + /// + /// Позиция + /// Объект + T? Get(int position); + } + +} diff --git a/ProjectLocomotive/ProjectLocomotive/CollectionGenericObjects/LocomotiveDockingService.cs b/ProjectLocomotive/ProjectLocomotive/CollectionGenericObjects/LocomotiveDockingService.cs new file mode 100644 index 0000000..ff8620f --- /dev/null +++ b/ProjectLocomotive/ProjectLocomotive/CollectionGenericObjects/LocomotiveDockingService.cs @@ -0,0 +1,65 @@ +using ProjectLocomotive.Drawnings; + +namespace ProjectLocomotive.CollectionGenericObjects +{ + /// + /// Реализация абстрактной компании - каршеринг + /// + public class LocomotiveDockingService : AbstractCompany + { + /// + /// Конструктор + /// + /// + /// + /// + public LocomotiveDockingService(int picWidth, int picHeight, + ICollectionGenericObjects collection) : base(picWidth, picHeight, collection) + { + } + protected override void DrawBackgound(Graphics g) + { + int width = _pictureWidth / _placeSizeWidth; + int height = _pictureHeight / _placeSizeHeight; + Pen pen = new(Color.Black, 2); + for (int i = 0; i < width; i++) + { + for (int j = 0; j < height + 1; ++j) + { + g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth - 20, j * _placeSizeHeight); + g.DrawLine(pen, i * _placeSizeWidth + _placeSizeWidth - 20, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth - 20, 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 + 10, curHeight * _placeSizeHeight + 10); + } + + if (curWidth < width - 1) + curWidth++; + else + { + curWidth = 0; + curHeight ++; + } + + if (curHeight >= height) + { + return; + } + } + } + } +} diff --git a/ProjectLocomotive/ProjectLocomotive/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectLocomotive/ProjectLocomotive/CollectionGenericObjects/MassiveGenericObjects.cs new file mode 100644 index 0000000..ac8a8f2 --- /dev/null +++ b/ProjectLocomotive/ProjectLocomotive/CollectionGenericObjects/MassiveGenericObjects.cs @@ -0,0 +1,97 @@ +using ProjectLocomotive.Drawnings; + +namespace ProjectLocomotive.CollectionGenericObjects +{ + /// + /// Параметризованный набор объектов + /// + /// Параметр: ограничение - ссылочный тип + public class MassiveGenericObjects : ICollectionGenericObjects + where T : class + { + /// + /// Массив объектов, которые храним + /// + private T?[] _collection; + public int Count => _collection.Length; + public int SetMaxCount { set { if (value > 0) { _collection = new T?[value]; } } } + + /// + /// Конструктор + /// + public MassiveGenericObjects() + { + _collection = Array.Empty(); + } + public T? Get(int position) + { + // TODO проверка позиции + if (position >= _collection.Length || position < 0) + { + return null; + } + return _collection[position]; + } + public int Insert(T obj) + { + // TODO вставка в свободное место набора + int index = 0; + while (index < _collection.Length) + { + if (_collection[index] == null) + { + _collection[index] = obj; + return index; + } + index++; + } + return -1; + } + public int Insert(T obj, int position) + { + // TODO проверка позиции + // TODO проверка, что элемент массива по этой позиции пустой, если нет, то + // ищется свободное место после этой позиции и идет вставка туда + // если нет после, ищем до + // TODO вставка + if (position >= _collection.Length || position < 0) + { return -1; } + + if (_collection[position] == null) + { + _collection[position] = obj; + return position; + } + int index; + + for (index = position + 1; index < _collection.Length; ++index) + { + if (_collection[index] == null) + { + _collection[position] = obj; + return position; + } + } + + for (index = position - 1; index >= 0; --index) + { + if (_collection[index] == null) + { + _collection[position] = obj; + return position; + } + } + return -1; + } + public T Remove(int position) + { + // TODO проверка позиции + // TODO удаление объекта из массива, присвоив элементу массива значение null + if (position >= _collection.Length || position < 0) + { return null; } + T drawningLocomotive = _collection[position]; + _collection[position] = null; + return drawningLocomotive; + } + } +} diff --git a/ProjectLocomotive/ProjectLocomotive/FormLocomotive.Designer.cs b/ProjectLocomotive/ProjectLocomotive/FormLocomotive.Designer.cs index b35948e..63ce7ef 100644 --- a/ProjectLocomotive/ProjectLocomotive/FormLocomotive.Designer.cs +++ b/ProjectLocomotive/ProjectLocomotive/FormLocomotive.Designer.cs @@ -30,13 +30,11 @@ { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormLocomotive)); pictureBoxLocomotive = new PictureBox(); - button1 = new Button(); buttonUp = new Button(); buttonDown = new Button(); buttonRight = new Button(); buttonLeft = new Button(); comboBoxStrategy = new ComboBox(); - buttonCretaeLocomotive = new Button(); buttonStrategyStep = new Button(); ((System.ComponentModel.ISupportInitialize)pictureBoxLocomotive).BeginInit(); SuspendLayout(); @@ -45,34 +43,20 @@ // pictureBoxLocomotive.Dock = DockStyle.Fill; pictureBoxLocomotive.Location = new Point(0, 0); - pictureBoxLocomotive.Margin = new Padding(3, 2, 3, 2); pictureBoxLocomotive.Name = "pictureBoxLocomotive"; - pictureBoxLocomotive.Size = new Size(700, 338); + pictureBoxLocomotive.Size = new Size(800, 450); pictureBoxLocomotive.SizeMode = PictureBoxSizeMode.AutoSize; pictureBoxLocomotive.TabIndex = 0; pictureBoxLocomotive.TabStop = false; // - // button1 - // - button1.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - button1.Location = new Point(10, 307); - button1.Margin = new Padding(3, 2, 3, 2); - button1.Name = "button1"; - button1.Size = new Size(186, 22); - button1.TabIndex = 1; - button1.Text = "создать тепловоз"; - button1.UseVisualStyleBackColor = true; - button1.Click += ButtonCreateLocomotive_Click; - // // buttonUp // buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonUp.BackgroundImage = (Image)resources.GetObject("buttonUp.BackgroundImage"); buttonUp.BackgroundImageLayout = ImageLayout.Zoom; - buttonUp.Location = new Point(632, 280); - buttonUp.Margin = new Padding(3, 2, 3, 2); + buttonUp.Location = new Point(722, 373); buttonUp.Name = "buttonUp"; - buttonUp.Size = new Size(26, 22); + buttonUp.Size = new Size(30, 30); buttonUp.TabIndex = 2; buttonUp.UseVisualStyleBackColor = true; buttonUp.Click += ButtonMove_Click; @@ -82,10 +66,9 @@ buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonDown.BackgroundImage = (Image)resources.GetObject("buttonDown.BackgroundImage"); buttonDown.BackgroundImageLayout = ImageLayout.Zoom; - buttonDown.Location = new Point(632, 307); - buttonDown.Margin = new Padding(3, 2, 3, 2); + buttonDown.Location = new Point(722, 409); buttonDown.Name = "buttonDown"; - buttonDown.Size = new Size(26, 22); + buttonDown.Size = new Size(30, 30); buttonDown.TabIndex = 3; buttonDown.UseVisualStyleBackColor = true; buttonDown.Click += ButtonMove_Click; @@ -95,10 +78,9 @@ buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonRight.BackgroundImage = (Image)resources.GetObject("buttonRight.BackgroundImage"); buttonRight.BackgroundImageLayout = ImageLayout.Zoom; - buttonRight.Location = new Point(663, 307); - buttonRight.Margin = new Padding(3, 2, 3, 2); + buttonRight.Location = new Point(758, 409); buttonRight.Name = "buttonRight"; - buttonRight.Size = new Size(26, 22); + buttonRight.Size = new Size(30, 30); buttonRight.TabIndex = 4; buttonRight.UseVisualStyleBackColor = true; buttonRight.Click += ButtonMove_Click; @@ -108,10 +90,9 @@ buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonLeft.BackgroundImage = (Image)resources.GetObject("buttonLeft.BackgroundImage"); buttonLeft.BackgroundImageLayout = ImageLayout.Zoom; - buttonLeft.Location = new Point(600, 307); - buttonLeft.Margin = new Padding(3, 2, 3, 2); + buttonLeft.Location = new Point(686, 409); buttonLeft.Name = "buttonLeft"; - buttonLeft.Size = new Size(26, 22); + buttonLeft.Size = new Size(30, 30); buttonLeft.TabIndex = 5; buttonLeft.UseVisualStyleBackColor = true; buttonLeft.Click += ButtonMove_Click; @@ -122,30 +103,16 @@ comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxStrategy.FormattingEnabled = true; comboBoxStrategy.Items.AddRange(new object[] { "к центру", "к краю" }); - comboBoxStrategy.Location = new Point(557, 9); - comboBoxStrategy.Margin = new Padding(3, 2, 3, 2); + comboBoxStrategy.Location = new Point(637, 12); comboBoxStrategy.Name = "comboBoxStrategy"; - comboBoxStrategy.Size = new Size(133, 23); + comboBoxStrategy.Size = new Size(151, 28); comboBoxStrategy.TabIndex = 6; // - // buttonCretaeLocomotive - // - buttonCretaeLocomotive.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonCretaeLocomotive.Location = new Point(210, 308); - buttonCretaeLocomotive.Margin = new Padding(3, 2, 3, 2); - buttonCretaeLocomotive.Name = "buttonCretaeLocomotive"; - buttonCretaeLocomotive.Size = new Size(186, 22); - buttonCretaeLocomotive.TabIndex = 7; - buttonCretaeLocomotive.Text = "создать поезда"; - buttonCretaeLocomotive.UseVisualStyleBackColor = true; - buttonCretaeLocomotive.Click += buttonCretaeLocomotive_Click; - // // buttonStrategyStep // - buttonStrategyStep.Location = new Point(607, 34); - buttonStrategyStep.Margin = new Padding(3, 2, 3, 2); + buttonStrategyStep.Location = new Point(694, 46); buttonStrategyStep.Name = "buttonStrategyStep"; - buttonStrategyStep.Size = new Size(82, 22); + buttonStrategyStep.Size = new Size(94, 29); buttonStrategyStep.TabIndex = 8; buttonStrategyStep.Text = "шаг"; buttonStrategyStep.UseVisualStyleBackColor = true; @@ -153,19 +120,16 @@ // // FormLocomotive // - AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(700, 338); + ClientSize = new Size(800, 450); Controls.Add(buttonStrategyStep); - Controls.Add(buttonCretaeLocomotive); Controls.Add(comboBoxStrategy); Controls.Add(buttonLeft); Controls.Add(buttonRight); Controls.Add(buttonDown); Controls.Add(buttonUp); - Controls.Add(button1); Controls.Add(pictureBoxLocomotive); - Margin = new Padding(3, 2, 3, 2); Name = "FormLocomotive"; Text = "FormLocomotive"; Click += ButtonMove_Click; @@ -177,13 +141,11 @@ #endregion private PictureBox pictureBoxLocomotive; - private Button button1; private Button buttonUp; private Button buttonDown; private Button buttonRight; private Button buttonLeft; private ComboBox comboBoxStrategy; - private Button buttonCretaeLocomotive; private Button buttonStrategyStep; } } \ No newline at end of file diff --git a/ProjectLocomotive/ProjectLocomotive/FormLocomotive.cs b/ProjectLocomotive/ProjectLocomotive/FormLocomotive.cs index f8bad3a..f7eb923 100644 --- a/ProjectLocomotive/ProjectLocomotive/FormLocomotive.cs +++ b/ProjectLocomotive/ProjectLocomotive/FormLocomotive.cs @@ -15,6 +15,25 @@ namespace ProjectLocomotive /// private AbstractStrategy? _strategy; + /// + /// Получение объекта + /// + public DrawningLocomotive SetLocomotive + { + set + { + _drawningLocomotive = value; + _drawningLocomotive.SetPictureSize(pictureBoxLocomotive.Width, + pictureBoxLocomotive.Height); + comboBoxStrategy.Enabled = true; + _strategy = null; + Draw(); + } + } + + /// + /// Конструктор формы + /// public FormLocomotive() { InitializeComponent(); @@ -37,57 +56,6 @@ namespace ProjectLocomotive pictureBoxLocomotive.Image = bmp; } - /// - /// Создание объекта класса-перемещения - /// - /// Тип создаваемого объекта - private void CreateObject(string type) - { - Random random = new(); - switch (type) - { - case nameof(DrawningLocomotive): - _drawningLocomotive = new DrawningLocomotive(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(DrawningTLocomotive): - _drawningLocomotive = new DrawningTLocomotive(random.Next(100, - 300), random.Next(1000, 3000), - Color.FromArgb(random.Next(0, 256), - random.Next(0, 256), random.Next(0, 256)), - Color.FromArgb(random.Next(0, 256), - random.Next(0, 256), random.Next(0, 256)), - Convert.ToBoolean(random.Next(0, 2)), - Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2))); - break; - default: - return; - } - _drawningLocomotive.SetPictureSize(pictureBoxLocomotive.Width, - pictureBoxLocomotive.Height); - _drawningLocomotive.SetPosition(random.Next(10, 100), random.Next(10, 100)); - _strategy = null; - comboBoxStrategy.Enabled = true; - Draw(); - } - - /// - /// Обработка нажатия кнопки "Создать военный крейсер" - /// - /// - /// - private void ButtonCreateLocomotive_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningTLocomotive)); - - /// - /// Обработка нажатия кнопки "Создать крейсер" - /// - /// - /// - private void buttonCretaeLocomotive_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningLocomotive)); - - /// /// Перемещение объекта по форме (нажатие кнопок навигации) /// @@ -104,16 +72,13 @@ namespace ProjectLocomotive switch (name) { case "buttonUp": - result = - _drawningLocomotive.MoveTransport(DirectionType.Up); + result = _drawningLocomotive.MoveTransport(DirectionType.Up); break; case "buttonDown": - result = - _drawningLocomotive.MoveTransport(DirectionType.Down); + result = _drawningLocomotive.MoveTransport(DirectionType.Down); break; case "buttonLeft": - result = - _drawningLocomotive.MoveTransport(DirectionType.Left); + result = _drawningLocomotive.MoveTransport(DirectionType.Left); break; case "buttonRight": result = diff --git a/ProjectLocomotive/ProjectLocomotive/FormLocomotivesCollection.Designer.cs b/ProjectLocomotive/ProjectLocomotive/FormLocomotivesCollection.Designer.cs new file mode 100644 index 0000000..812f31e --- /dev/null +++ b/ProjectLocomotive/ProjectLocomotive/FormLocomotivesCollection.Designer.cs @@ -0,0 +1,184 @@ +namespace ProjectLocomotive +{ + partial class FormLocomotivesCollection + { + /// + /// 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(); + maskedTextBoxPosision = new MaskedTextBox(); + buttonRefresh = new Button(); + buttonGetToTest = new Button(); + ButtonRemoveLocomotive = new Button(); + ButtonAddTLocomotive = new Button(); + ButtonAddLocomotive = new Button(); + comboBoxSelectorCompany = new ComboBox(); + pictureBoxLocomotive = new PictureBox(); + groupBoxTools.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBoxLocomotive).BeginInit(); + SuspendLayout(); + // + // groupBoxTools + // + groupBoxTools.Controls.Add(maskedTextBoxPosision); + groupBoxTools.Controls.Add(buttonRefresh); + groupBoxTools.Controls.Add(buttonGetToTest); + groupBoxTools.Controls.Add(ButtonRemoveLocomotive); + groupBoxTools.Controls.Add(ButtonAddTLocomotive); + groupBoxTools.Controls.Add(ButtonAddLocomotive); + groupBoxTools.Controls.Add(comboBoxSelectorCompany); + groupBoxTools.Dock = DockStyle.Right; + groupBoxTools.Location = new Point(522, 0); + groupBoxTools.Margin = new Padding(3, 2, 3, 2); + groupBoxTools.Name = "groupBoxTools"; + groupBoxTools.Padding = new Padding(3, 2, 3, 2); + groupBoxTools.Size = new Size(194, 430); + groupBoxTools.TabIndex = 0; + groupBoxTools.TabStop = false; + groupBoxTools.Text = "инструменты"; + // + // maskedTextBoxPosision + // + maskedTextBoxPosision.Location = new Point(18, 172); + maskedTextBoxPosision.Margin = new Padding(3, 2, 3, 2); + maskedTextBoxPosision.Mask = "00"; + maskedTextBoxPosision.Name = "maskedTextBoxPosision"; + maskedTextBoxPosision.Size = new Size(163, 23); + maskedTextBoxPosision.TabIndex = 2; + maskedTextBoxPosision.ValidatingType = typeof(int); + // + // buttonRefresh + // + buttonRefresh.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonRefresh.Location = new Point(18, 359); + buttonRefresh.Margin = new Padding(3, 2, 3, 2); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(163, 30); + buttonRefresh.TabIndex = 5; + buttonRefresh.Text = "обновить"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += ButtonRefresh_Click; + // + // buttonGetToTest + // + buttonGetToTest.Anchor = AnchorStyles.Right; + buttonGetToTest.Location = new Point(18, 274); + buttonGetToTest.Margin = new Padding(3, 2, 3, 2); + buttonGetToTest.Name = "buttonGetToTest"; + buttonGetToTest.Size = new Size(163, 30); + buttonGetToTest.TabIndex = 4; + buttonGetToTest.Text = "передать на тесты"; + buttonGetToTest.UseVisualStyleBackColor = true; + buttonGetToTest.Click += ButtonGetToTest_Click; + // + // ButtonRemoveLocomotive + // + ButtonRemoveLocomotive.Anchor = AnchorStyles.Right; + ButtonRemoveLocomotive.Location = new Point(18, 203); + ButtonRemoveLocomotive.Margin = new Padding(3, 2, 3, 2); + ButtonRemoveLocomotive.Name = "ButtonRemoveLocomotive"; + ButtonRemoveLocomotive.Size = new Size(163, 30); + ButtonRemoveLocomotive.TabIndex = 3; + ButtonRemoveLocomotive.Text = "удалить поезд"; + ButtonRemoveLocomotive.UseVisualStyleBackColor = true; + ButtonRemoveLocomotive.Click += ButtonRemoveLocomotive_Click; + // + // ButtonAddTLocomotive + // + ButtonAddTLocomotive.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + ButtonAddTLocomotive.Location = new Point(18, 114); + ButtonAddTLocomotive.Margin = new Padding(3, 2, 3, 2); + ButtonAddTLocomotive.Name = "ButtonAddTLocomotive"; + ButtonAddTLocomotive.Size = new Size(163, 38); + ButtonAddTLocomotive.TabIndex = 2; + ButtonAddTLocomotive.Text = "добваление тепловоза"; + ButtonAddTLocomotive.UseVisualStyleBackColor = true; + ButtonAddTLocomotive.Click += ButtonAddTLocomotive_Click; + // + // ButtonAddLocomotive + // + ButtonAddLocomotive.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + ButtonAddLocomotive.BackgroundImageLayout = ImageLayout.Center; + ButtonAddLocomotive.Location = new Point(18, 80); + ButtonAddLocomotive.Margin = new Padding(3, 2, 3, 2); + ButtonAddLocomotive.Name = "ButtonAddLocomotive"; + ButtonAddLocomotive.Size = new Size(163, 30); + ButtonAddLocomotive.TabIndex = 1; + ButtonAddLocomotive.Text = "добваление поезда"; + ButtonAddLocomotive.UseVisualStyleBackColor = true; + ButtonAddLocomotive.Click += ButtonAddLocomotive_Click; + // + // comboBoxSelectorCompany + // + comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxSelectorCompany.FormattingEnabled = true; + comboBoxSelectorCompany.Items.AddRange(new object[] { "хранилище" }); + comboBoxSelectorCompany.Location = new Point(18, 20); + comboBoxSelectorCompany.Margin = new Padding(3, 2, 3, 2); + comboBoxSelectorCompany.Name = "comboBoxSelectorCompany"; + comboBoxSelectorCompany.Size = new Size(163, 23); + comboBoxSelectorCompany.TabIndex = 0; + comboBoxSelectorCompany.SelectedIndexChanged += comboBoxSelectorCompany_SelectedIndexChanged_1; + // + // pictureBoxLocomotive + // + pictureBoxLocomotive.Dock = DockStyle.Fill; + pictureBoxLocomotive.Location = new Point(0, 0); + pictureBoxLocomotive.Margin = new Padding(3, 2, 3, 2); + pictureBoxLocomotive.Name = "pictureBoxLocomotive"; + pictureBoxLocomotive.Size = new Size(522, 430); + pictureBoxLocomotive.TabIndex = 1; + pictureBoxLocomotive.TabStop = false; + // + // FormLocomotivesCollection + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(716, 430); + Controls.Add(pictureBoxLocomotive); + Controls.Add(groupBoxTools); + Margin = new Padding(3, 2, 3, 2); + Name = "FormLocomotivesCollection"; + Text = "FormLocomotivesCollection"; + groupBoxTools.ResumeLayout(false); + groupBoxTools.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBoxLocomotive).EndInit(); + ResumeLayout(false); + } + + #endregion + + private GroupBox groupBoxTools; + private ComboBox comboBoxSelectorCompany; + private Button ButtonAddTLocomotive; + private Button ButtonAddLocomotive; + private Button ButtonRemoveLocomotive; + private Button buttonRefresh; + private Button buttonGetToTest; + private PictureBox pictureBoxLocomotive; + private MaskedTextBox maskedTextBoxPosision; + } +} \ No newline at end of file diff --git a/ProjectLocomotive/ProjectLocomotive/FormLocomotivesCollection.cs b/ProjectLocomotive/ProjectLocomotive/FormLocomotivesCollection.cs new file mode 100644 index 0000000..6e75c49 --- /dev/null +++ b/ProjectLocomotive/ProjectLocomotive/FormLocomotivesCollection.cs @@ -0,0 +1,169 @@ +using ProjectLocomotive.CollectionGenericObjects; +using ProjectLocomotive.Drawnings; + +namespace ProjectLocomotive +{ + public partial class FormLocomotivesCollection : Form + { + /// + /// Компания + /// + private AbstractCompany? _company = null; + /// + /// Конструктор + /// + public FormLocomotivesCollection() + { + InitializeComponent(); + } + + /// + /// + /// + /// + /// + private void comboBoxSelectorCompany_SelectedIndexChanged_1(object sender, EventArgs e) + { + switch (comboBoxSelectorCompany.Text) + { + case "хранилище": + _company = new LocomotiveDockingService(pictureBoxLocomotive.Width, + pictureBoxLocomotive.Height, new MassiveGenericObjects()); + break; + } + } + + /// + /// Создание объекта класса-перемещения + /// + /// Тип создаваемого объекта + private void CreateObject(string type) + { + if (_company == null) + { + return; + } + Random random = new(); + DrawningLocomotive drawningLocomotive; + switch (type) + { + case nameof(DrawningLocomotive): + drawningLocomotive = new DrawningLocomotive(random.Next(100, 300), random.Next(1000, 3000), GetColor(random)); + break; + case nameof(DrawningTLocomotive): + drawningLocomotive = new DrawningTLocomotive(random.Next(100, 300), random.Next(1000, 3000), + GetColor(random), + GetColor(random), + Convert.ToBoolean(random.Next(0, 2)), + Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2))); + break; + default: + return; + } + if (_company + drawningLocomotive != -1) + { + MessageBox.Show("объект добавлен"); + pictureBoxLocomotive.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 ButtonAddLocomotive_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningLocomotive)); + + //private void ButtonAddTLocomotive_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningTLocomotive)); + private void ButtonAddLocomotive_Click(object sender, EventArgs e) + { + CreateObject(nameof(DrawningLocomotive)); + } + + private void ButtonAddTLocomotive_Click(object sender, EventArgs e) + { + CreateObject(nameof(DrawningTLocomotive)); + } + + private void ButtonRemoveLocomotive_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(maskedTextBoxPosision.Text) || _company == null) + { + return; + } + if (MessageBox.Show("удалить объект?", "удаление", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) + { + return; + } + int pos = Convert.ToInt32(maskedTextBoxPosision.Text); + if (_company - pos != null) + { + MessageBox.Show("объект удален"); + pictureBoxLocomotive.Image = _company.Show(); + } + else + { + MessageBox.Show("не удалось удалить объект"); + } + } + + private void ButtonGetToTest_Click(object sender, EventArgs e) + { + if (_company == null) + { + return; + } + + DrawningLocomotive? cruiser = null; + int counter = 100; + while (cruiser == null) + { + cruiser = _company.GetRandomObject(); + counter--; + if (counter <= 0) + { + break; + } + } + if (cruiser == null) + { + return; + } + FormLocomotive form = new() + { + SetLocomotive = cruiser + }; + form.ShowDialog(); + + } + + private void ButtonRefresh_Click(object sender, EventArgs e) + { + if (_company == null) + { + return; + } + + pictureBoxLocomotive.Image = _company.Show(); + } + + + } +} diff --git a/ProjectLocomotive/ProjectLocomotive/FormLocomotivesCollection.resx b/ProjectLocomotive/ProjectLocomotive/FormLocomotivesCollection.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectLocomotive/ProjectLocomotive/FormLocomotivesCollection.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/ProjectLocomotive/ProjectLocomotive/Program.cs b/ProjectLocomotive/ProjectLocomotive/Program.cs index 8f40489..ee7921f 100644 --- a/ProjectLocomotive/ProjectLocomotive/Program.cs +++ b/ProjectLocomotive/ProjectLocomotive/Program.cs @@ -3,15 +3,14 @@ namespace ProjectLocomotive internal static class Program { /// - /// The main entry point for the application. + /// The main entry point for the application. /// [STAThread] static void Main() { - // To customize application configuration such as set high DPI settings or default font, - // see https://aka.ms/applicationconfiguration. + // To customize application configuration such as set high DPI settings or default font, see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormLocomotive()); + Application.Run(new FormLocomotivesCollection()); } } } \ No newline at end of file