From 5994dce933f57f56b234b6a2ef9dbb49de30f7ec Mon Sep 17 00:00:00 2001 From: egorvasin Date: Mon, 6 May 2024 16:09:02 +0300 Subject: [PATCH 1/2] =?UTF-8?q?=D0=9A=D0=BE=D0=BB=D0=BB=D0=B5=D0=BA=D1=86?= =?UTF-8?q?=D0=B8=D0=B8=20=D0=BE=D0=B1=D1=8A=D0=B5=D0=BA=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ICollectionGenericObjects.cs | 12 ++++++++++++ .../MassiveGenericObjects.cs | 12 ++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 ProjectBuldozer/ProjectBuldozer/CollectionGenericObjects/ICollectionGenericObjects.cs create mode 100644 ProjectBuldozer/ProjectBuldozer/CollectionGenericObjects/MassiveGenericObjects.cs diff --git a/ProjectBuldozer/ProjectBuldozer/CollectionGenericObjects/ICollectionGenericObjects.cs b/ProjectBuldozer/ProjectBuldozer/CollectionGenericObjects/ICollectionGenericObjects.cs new file mode 100644 index 0000000..f438144 --- /dev/null +++ b/ProjectBuldozer/ProjectBuldozer/CollectionGenericObjects/ICollectionGenericObjects.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectBuldozer.CollectionGenericObjects +{ + internal interface ICollectionGenericObjects + { + } +} diff --git a/ProjectBuldozer/ProjectBuldozer/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectBuldozer/ProjectBuldozer/CollectionGenericObjects/MassiveGenericObjects.cs new file mode 100644 index 0000000..5982b04 --- /dev/null +++ b/ProjectBuldozer/ProjectBuldozer/CollectionGenericObjects/MassiveGenericObjects.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectBuldozer.CollectionGenericObjects +{ + internal class MassiveGenericObjects + { + } +} -- 2.25.1 From f2f631d80f7d96ad1d1df953e6a860d11796d6e0 Mon Sep 17 00:00:00 2001 From: egorvasin Date: Mon, 20 May 2024 18:26:22 +0400 Subject: [PATCH 2/2] =?UTF-8?q?=D0=9A=D0=BE=D0=BC=D0=BF=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbstractCompany.cs | 113 +++++++++++ .../BuldozerSharingService.cs | 63 ++++++ .../ICollectionGenericObjects.cs | 54 ++++- .../MassiveGenericObjects.cs | 117 ++++++++++- .../ProjectBuldozer/FormBuldozer.Designer.cs | 41 +--- .../ProjectBuldozer/FormBuldozer.cs | 17 ++ .../FormBuldozerCollection.Designer.cs | 174 ++++++++++++++++ .../ProjectBuldozer/FormBuldozerCollection.cs | 191 ++++++++++++++++++ .../FormBuldozerCollection.resx | 120 +++++++++++ .../MovementStrategy/AbstractStrategy.cs | 5 +- .../MovementStrategy/IMoveableObject.cs | 4 +- .../MovementStrategy/MoveableTyagach.cs | 1 - ProjectBuldozer/ProjectBuldozer/Program.cs | 2 +- 13 files changed, 846 insertions(+), 56 deletions(-) create mode 100644 ProjectBuldozer/ProjectBuldozer/CollectionGenericObjects/AbstractCompany.cs create mode 100644 ProjectBuldozer/ProjectBuldozer/CollectionGenericObjects/BuldozerSharingService.cs create mode 100644 ProjectBuldozer/ProjectBuldozer/FormBuldozerCollection.Designer.cs create mode 100644 ProjectBuldozer/ProjectBuldozer/FormBuldozerCollection.cs create mode 100644 ProjectBuldozer/ProjectBuldozer/FormBuldozerCollection.resx diff --git a/ProjectBuldozer/ProjectBuldozer/CollectionGenericObjects/AbstractCompany.cs b/ProjectBuldozer/ProjectBuldozer/CollectionGenericObjects/AbstractCompany.cs new file mode 100644 index 0000000..698970b --- /dev/null +++ b/ProjectBuldozer/ProjectBuldozer/CollectionGenericObjects/AbstractCompany.cs @@ -0,0 +1,113 @@ +using ProjectBuldozer.Drawnings; + +namespace ProjectBuldozer.CollectionGenericObjects; + +public abstract class AbstractCompany +{ + /// + /// Размер места (ширина) + /// + protected readonly int _placeSizeWidth = 210; + + /// + /// Размер места (высота) + /// + protected readonly int _placeSizeHeight = 90; + + /// + /// Ширина окна + /// + 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, DrawingUsualBuldozer excavator) + { + return company._collection.Insert(excavator); + } + + /// + /// Перегрузка оператора удаления для класса + /// + /// Компания + /// Номер удаляемого объекта + /// + public static DrawingUsualBuldozer operator -(AbstractCompany company, int position) + { + return company._collection?.Remove(position); + } + + /// + /// Получение случайного объекта из коллекции + /// + /// + public DrawingUsualBuldozer? 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) + { + DrawingUsualBuldozer? obj = _collection?.Get(i); + obj?.DrawTransport(graphics); + } + + return bitmap; + } + + /// + /// Вывод заднего фона + /// + /// + protected abstract void DrawBackgound(Graphics g); + + /// + /// Расстановка объектов + /// + protected abstract void SetObjectsPosition(); +} diff --git a/ProjectBuldozer/ProjectBuldozer/CollectionGenericObjects/BuldozerSharingService.cs b/ProjectBuldozer/ProjectBuldozer/CollectionGenericObjects/BuldozerSharingService.cs new file mode 100644 index 0000000..f8f7cb1 --- /dev/null +++ b/ProjectBuldozer/ProjectBuldozer/CollectionGenericObjects/BuldozerSharingService.cs @@ -0,0 +1,63 @@ +using ProjectBuldozer.Drawnings; + +namespace ProjectBuldozer.CollectionGenericObjects; +public class BuldozerSharingServise : AbstractCompany +{ + /// + /// Конструктор + /// + /// + /// + /// + public BuldozerSharingServise(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, 3); + 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 - 15, j * _placeSizeHeight); + } + } + } + + protected override void SetObjectsPosition() + { + int width = _pictureWidth / _placeSizeWidth; + int height = _pictureHeight / _placeSizeHeight; + + int curWidth = width - 1; + int curHeight = 0; + + for (int i = 0; i < (_collection?.Count ?? 0); i++) + { + if (_collection.Get(i) != null) + { + _collection.Get(i).SetPictureSize(_pictureWidth, _pictureHeight); + _collection.Get(i).SetPosition(_placeSizeWidth * curWidth + 20, curHeight * _placeSizeHeight + 2); + } + if (curWidth > 0) + curWidth--; + else + { + curWidth = width - 1; + curHeight++; + } + if (curHeight > height) + { + return; + } + } + + } +} diff --git a/ProjectBuldozer/ProjectBuldozer/CollectionGenericObjects/ICollectionGenericObjects.cs b/ProjectBuldozer/ProjectBuldozer/CollectionGenericObjects/ICollectionGenericObjects.cs index f438144..175a2e2 100644 --- a/ProjectBuldozer/ProjectBuldozer/CollectionGenericObjects/ICollectionGenericObjects.cs +++ b/ProjectBuldozer/ProjectBuldozer/CollectionGenericObjects/ICollectionGenericObjects.cs @@ -1,12 +1,48 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +namespace ProjectBuldozer.CollectionGenericObjects; -namespace ProjectBuldozer.CollectionGenericObjects +/// +/// Интерфейс описания действий для набора хранимых объектов +/// +/// +public interface ICollectionGenericObjects + where T : class { - internal interface ICollectionGenericObjects - { - } + /// + /// колличество объектов в коллекции + /// + 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/ProjectBuldozer/ProjectBuldozer/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectBuldozer/ProjectBuldozer/CollectionGenericObjects/MassiveGenericObjects.cs index 5982b04..be98ac1 100644 --- a/ProjectBuldozer/ProjectBuldozer/CollectionGenericObjects/MassiveGenericObjects.cs +++ b/ProjectBuldozer/ProjectBuldozer/CollectionGenericObjects/MassiveGenericObjects.cs @@ -1,12 +1,113 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ProjectBuldozer.CollectionGenericObjects +namespace ProjectBuldozer.CollectionGenericObjects; +/// +/// параметризованный набор объектов +/// +/// +public class MassiveGenericObjects : ICollectionGenericObjects + where T : class { - internal class MassiveGenericObjects + /// + /// массив объектов, которые храним + /// + 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) + { + // 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 obj = _collection[position]; + _collection[position] = null; + return obj; } } diff --git a/ProjectBuldozer/ProjectBuldozer/FormBuldozer.Designer.cs b/ProjectBuldozer/ProjectBuldozer/FormBuldozer.Designer.cs index 77dd2bc..7921859 100644 --- a/ProjectBuldozer/ProjectBuldozer/FormBuldozer.Designer.cs +++ b/ProjectBuldozer/ProjectBuldozer/FormBuldozer.Designer.cs @@ -33,12 +33,10 @@ namespace ProjectBuldozer private void InitializeComponent() { pictureBoxBuldozer = new PictureBox(); - buttonCreateBuldozer = new Button(); buttonLeft = new Button(); buttonUp = new Button(); buttonDown = new Button(); buttonRight = new Button(); - buttonCreateTyagach = new Button(); comboBoxStrategy = new ComboBox(); buttonStrategyStep = new Button(); ((System.ComponentModel.ISupportInitialize)pictureBoxBuldozer).BeginInit(); @@ -49,27 +47,16 @@ namespace ProjectBuldozer pictureBoxBuldozer.Dock = DockStyle.Fill; pictureBoxBuldozer.Location = new Point(0, 0); pictureBoxBuldozer.Name = "pictureBoxBuldozer"; - pictureBoxBuldozer.Size = new Size(923, 274); + pictureBoxBuldozer.Size = new Size(923, 403); pictureBoxBuldozer.TabIndex = 0; pictureBoxBuldozer.TabStop = false; // - // buttonCreateBuldozer - // - buttonCreateBuldozer.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonCreateBuldozer.Location = new Point(12, 239); - buttonCreateBuldozer.Name = "buttonCreateBuldozer"; - buttonCreateBuldozer.Size = new Size(176, 23); - buttonCreateBuldozer.TabIndex = 1; - buttonCreateBuldozer.Text = "Создать бульдузер"; - buttonCreateBuldozer.UseVisualStyleBackColor = true; - buttonCreateBuldozer.Click += ButtonCreateBuldozer_Click; - // // buttonLeft // buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonLeft.BackgroundImage = Properties.Resources.arrowLeft; buttonLeft.BackgroundImageLayout = ImageLayout.Stretch; - buttonLeft.Location = new Point(787, 227); + buttonLeft.Location = new Point(787, 356); buttonLeft.Name = "buttonLeft"; buttonLeft.Size = new Size(35, 35); buttonLeft.TabIndex = 2; @@ -81,7 +68,7 @@ namespace ProjectBuldozer buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonUp.BackgroundImage = Properties.Resources.arrowUp; buttonUp.BackgroundImageLayout = ImageLayout.Stretch; - buttonUp.Location = new Point(828, 186); + buttonUp.Location = new Point(828, 315); buttonUp.Name = "buttonUp"; buttonUp.Size = new Size(35, 35); buttonUp.TabIndex = 3; @@ -93,7 +80,7 @@ namespace ProjectBuldozer buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonDown.BackgroundImage = Properties.Resources.arrowDown; buttonDown.BackgroundImageLayout = ImageLayout.Stretch; - buttonDown.Location = new Point(828, 227); + buttonDown.Location = new Point(828, 356); buttonDown.Name = "buttonDown"; buttonDown.Size = new Size(35, 35); buttonDown.TabIndex = 4; @@ -105,24 +92,13 @@ namespace ProjectBuldozer buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonRight.BackgroundImage = Properties.Resources.arrowRight; buttonRight.BackgroundImageLayout = ImageLayout.Stretch; - buttonRight.Location = new Point(869, 227); + buttonRight.Location = new Point(869, 356); buttonRight.Name = "buttonRight"; buttonRight.Size = new Size(35, 35); buttonRight.TabIndex = 5; buttonRight.UseVisualStyleBackColor = true; buttonRight.Click += ButtonMove_Click; // - // buttonCreateTyagach - // - buttonCreateTyagach.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonCreateTyagach.Location = new Point(210, 239); - buttonCreateTyagach.Name = "buttonCreateTyagach"; - buttonCreateTyagach.Size = new Size(163, 23); - buttonCreateTyagach.TabIndex = 6; - buttonCreateTyagach.Text = "Создать тягач"; - buttonCreateTyagach.UseVisualStyleBackColor = true; - buttonCreateTyagach.Click += ButtonCreateUsualBuldozer_Click; - // // comboBoxStrategy // comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList; @@ -147,18 +123,17 @@ namespace ProjectBuldozer // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(923, 274); + ClientSize = new Size(923, 403); Controls.Add(buttonStrategyStep); Controls.Add(comboBoxStrategy); - Controls.Add(buttonCreateTyagach); Controls.Add(buttonRight); Controls.Add(buttonDown); Controls.Add(buttonUp); Controls.Add(buttonLeft); - Controls.Add(buttonCreateBuldozer); Controls.Add(pictureBoxBuldozer); Name = "FormBuldozer"; Text = "Бульдозер"; + Load += FormBuldozer_Load; ((System.ComponentModel.ISupportInitialize)pictureBoxBuldozer).EndInit(); ResumeLayout(false); } @@ -166,12 +141,10 @@ namespace ProjectBuldozer #endregion private PictureBox pictureBoxBuldozer; - private Button buttonCreateBuldozer; private Button buttonLeft; private Button buttonUp; private Button buttonDown; private Button buttonRight; - private Button buttonCreateTyagach; private ComboBox comboBoxStrategy; private Button buttonStrategyStep; } diff --git a/ProjectBuldozer/ProjectBuldozer/FormBuldozer.cs b/ProjectBuldozer/ProjectBuldozer/FormBuldozer.cs index 04429a9..7264592 100644 --- a/ProjectBuldozer/ProjectBuldozer/FormBuldozer.cs +++ b/ProjectBuldozer/ProjectBuldozer/FormBuldozer.cs @@ -18,6 +18,18 @@ public partial class FormBuldozer : Form /// private AbstractStrategy? _strategy; + public DrawingUsualBuldozer SetBuldozer + { + set + { + _drawningUsualBuldozer = value; + _drawningUsualBuldozer.SetPictureSize(pictureBoxBuldozer.Width, pictureBoxBuldozer.Height); + comboBoxStrategy.Enabled = true; + _strategy = null; + Draw(); + } + } + /// /// Конструктор формы /// @@ -203,4 +215,9 @@ public partial class FormBuldozer : Form _strategy = null; } } + + private void FormBuldozer_Load(object sender, EventArgs e) + { + + } } \ No newline at end of file diff --git a/ProjectBuldozer/ProjectBuldozer/FormBuldozerCollection.Designer.cs b/ProjectBuldozer/ProjectBuldozer/FormBuldozerCollection.Designer.cs new file mode 100644 index 0000000..92e15ab --- /dev/null +++ b/ProjectBuldozer/ProjectBuldozer/FormBuldozerCollection.Designer.cs @@ -0,0 +1,174 @@ +namespace ProjectBuldozer +{ + partial class FormBuldozerCollection + { + /// + /// 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(); + buttonRemoveBuldozer = new Button(); + maskedTextBox = new MaskedTextBox(); + buttonAddBuldozer = new Button(); + buttonAddUsualBuldozer = new Button(); + comboBoxSelectCompany = 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(buttonRemoveBuldozer); + groupBoxTools.Controls.Add(maskedTextBox); + groupBoxTools.Controls.Add(buttonAddBuldozer); + groupBoxTools.Controls.Add(buttonAddUsualBuldozer); + groupBoxTools.Controls.Add(comboBoxSelectCompany); + groupBoxTools.Dock = DockStyle.Right; + groupBoxTools.Location = new Point(705, 0); + groupBoxTools.Name = "groupBoxTools"; + groupBoxTools.Size = new Size(220, 450); + groupBoxTools.TabIndex = 0; + groupBoxTools.TabStop = false; + groupBoxTools.Text = "Инструменты"; + // + // buttonRefresh + // + buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonRefresh.Location = new Point(6, 371); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(208, 39); + buttonRefresh.TabIndex = 6; + buttonRefresh.Text = "Обновить"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += ButtonRefresh_Click; + // + // buttonGoToCheck + // + buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonGoToCheck.Location = new Point(6, 257); + buttonGoToCheck.Name = "buttonGoToCheck"; + buttonGoToCheck.Size = new Size(208, 39); + buttonGoToCheck.TabIndex = 5; + buttonGoToCheck.Text = "Передать на тесты"; + buttonGoToCheck.UseVisualStyleBackColor = true; + buttonGoToCheck.Click += ButtonGoToCheck_Click; + // + // buttonRemoveBuldozer + // + buttonRemoveBuldozer.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonRemoveBuldozer.Location = new Point(6, 212); + buttonRemoveBuldozer.Name = "buttonRemoveBuldozer"; + buttonRemoveBuldozer.Size = new Size(208, 39); + buttonRemoveBuldozer.TabIndex = 4; + buttonRemoveBuldozer.Text = "Удаление бульдозера"; + buttonRemoveBuldozer.UseVisualStyleBackColor = true; + buttonRemoveBuldozer.Click += ButtonRemoveBuldozer_Click; + // + // maskedTextBox + // + maskedTextBox.Location = new Point(6, 183); + maskedTextBox.Mask = "00"; + maskedTextBox.Name = "maskedTextBox"; + maskedTextBox.Size = new Size(208, 23); + maskedTextBox.TabIndex = 3; + maskedTextBox.ValidatingType = typeof(int); + // + // buttonAddBuldozer + // + buttonAddBuldozer.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonAddBuldozer.Location = new Point(6, 128); + buttonAddBuldozer.Name = "buttonAddBuldozer"; + buttonAddBuldozer.Size = new Size(208, 39); + buttonAddBuldozer.TabIndex = 2; + buttonAddBuldozer.Text = "Добавление бульдозера"; + buttonAddBuldozer.UseVisualStyleBackColor = true; + buttonAddBuldozer.Click += ButtonAddBuldozer_Click; + // + // buttonAddUsualBuldozer + // + buttonAddUsualBuldozer.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonAddUsualBuldozer.Location = new Point(6, 83); + buttonAddUsualBuldozer.Name = "buttonAddUsualBuldozer"; + buttonAddUsualBuldozer.Size = new Size(208, 39); + buttonAddUsualBuldozer.TabIndex = 1; + buttonAddUsualBuldozer.Text = "Добавление обычного бульдозера"; + buttonAddUsualBuldozer.UseVisualStyleBackColor = true; + buttonAddUsualBuldozer.Click += ButtonAddUsualBuldozer_Click; + // + // comboBoxSelectCompany + // + comboBoxSelectCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + comboBoxSelectCompany.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxSelectCompany.FormattingEnabled = true; + comboBoxSelectCompany.Items.AddRange(new object[] { "Хранилище" }); + comboBoxSelectCompany.Location = new Point(6, 22); + comboBoxSelectCompany.Name = "comboBoxSelectCompany"; + comboBoxSelectCompany.Size = new Size(208, 23); + comboBoxSelectCompany.TabIndex = 0; + comboBoxSelectCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged; + // + // pictureBox + // + pictureBox.Dock = DockStyle.Fill; + pictureBox.Location = new Point(0, 0); + pictureBox.Name = "pictureBox"; + pictureBox.Size = new Size(705, 450); + pictureBox.TabIndex = 1; + pictureBox.TabStop = false; + pictureBox.Click += pictureBox_Click; + // + // FormBuldozerCollection + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(925, 450); + Controls.Add(pictureBox); + Controls.Add(groupBoxTools); + Name = "FormBuldozerCollection"; + Text = "Коллекция бульдозеров"; + groupBoxTools.ResumeLayout(false); + groupBoxTools.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); + ResumeLayout(false); + } + + #endregion + + private GroupBox groupBoxTools; + private ComboBox comboBoxSelectCompany; + private Button buttonAddBuldozer; + private Button buttonAddUsualBuldozer; + private Button buttonRemoveBuldozer; + private MaskedTextBox maskedTextBox; + private PictureBox pictureBox; + private Button buttonRefresh; + private Button buttonGoToCheck; + } +} \ No newline at end of file diff --git a/ProjectBuldozer/ProjectBuldozer/FormBuldozerCollection.cs b/ProjectBuldozer/ProjectBuldozer/FormBuldozerCollection.cs new file mode 100644 index 0000000..10e4166 --- /dev/null +++ b/ProjectBuldozer/ProjectBuldozer/FormBuldozerCollection.cs @@ -0,0 +1,191 @@ +using ProjectBuldozer.CollectionGenericObjects; +using ProjectBuldozer.Drawnings; + +namespace ProjectBuldozer; + +public partial class FormBuldozerCollection : Form +{ + /// + /// компания + /// + AbstractCompany? _company = null; + /// + /// Конструктор + /// + public FormBuldozerCollection() + { + InitializeComponent(); + } + /// + /// Выбор компании + /// + /// + /// + private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e) + { + switch (comboBoxSelectCompany.Text) + { + case "Хранилище": + _company = new BuldozerSharingServise(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects()); + break; + } + } + + /// + /// Добавление обычного экскаватора + /// + /// + /// + private void ButtonAddUsualBuldozer_Click(object sender, EventArgs e) => CreateObject(nameof(DrawingUsualBuldozer)); + + /// + /// Добавление полного экскаватора + /// + /// + /// + private void ButtonAddBuldozer_Click(object sender, EventArgs e) => CreateObject(nameof(DrawingBuldozer)); + + /// + /// Создание объекта класса-перемещения + /// + /// Тип создаваемого объекта + private void CreateObject(string type) + { + if (_company == null) + { + return; + } + + Random random = new(); + DrawingUsualBuldozer drawingUsualBuldozer; + switch (type) + { + case nameof(DrawingUsualBuldozer): + drawingUsualBuldozer = new DrawingUsualBuldozer(random.Next(100, 300), random.Next(1000, 3000), GetColor(random)); + break; + case nameof(DrawingBuldozer): + // TODO вызов диалогового окна для выбора цвета + drawingUsualBuldozer = new DrawingBuldozer(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 + drawingUsualBuldozer != -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 ButtonRemoveBuldozer_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == null) + { + return; + } + + if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) + { + return; + } + + int pos = Convert.ToInt32(maskedTextBox.Text); + if (_company - pos != null) + { + MessageBox.Show("Объект удален"); + pictureBox.Image = _company.Show(); + } + else + { + MessageBox.Show("Не удалось удалить объект"); + } + + } + + private void ButtonGoToCheck_Click(object sender, EventArgs e) + { + if (_company == null) + { + return; + } + + DrawingUsualBuldozer? excavator = null; + int counter = 100; + while (excavator == null) + { + excavator = _company.GetRandomObject(); + counter--; + if (counter <= 0) + { + break; + } + } + + if (excavator == null) + { + return; + } + + FormBuldozer form = new() + { + SetBuldozer = excavator + }; + form.ShowDialog(); + } + + private void ButtonRefresh_Click(object sender, EventArgs e) + { + if (_company == null) + { + return; + } + + pictureBox.Image = _company.Show(); + } + + private void pictureBox_Click(object sender, EventArgs e) + { + + } + + //private void buttonAddUsualBuldozer_Click_1(object sender, EventArgs e) + //{ + + //} + + //private void buttonGoToCheck_Click_1(object sender, EventArgs e) + //{ + + //} +} + diff --git a/ProjectBuldozer/ProjectBuldozer/FormBuldozerCollection.resx b/ProjectBuldozer/ProjectBuldozer/FormBuldozerCollection.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectBuldozer/ProjectBuldozer/FormBuldozerCollection.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/ProjectBuldozer/ProjectBuldozer/MovementStrategy/AbstractStrategy.cs b/ProjectBuldozer/ProjectBuldozer/MovementStrategy/AbstractStrategy.cs index 70fbb2f..64f0732 100644 --- a/ProjectBuldozer/ProjectBuldozer/MovementStrategy/AbstractStrategy.cs +++ b/ProjectBuldozer/ProjectBuldozer/MovementStrategy/AbstractStrategy.cs @@ -1,4 +1,6 @@ -namespace ProjectBuldozer.MovementStrategy; +using ProjectBuldozer.Drawnings; + +namespace ProjectBuldozer.MovementStrategy; /// /// Класс-стратегия перемещения объекта @@ -133,7 +135,6 @@ public abstract class AbstractStrategy { return false; } - return _moveableObject?.TryMoveObject(movementDirection) ?? false; } } diff --git a/ProjectBuldozer/ProjectBuldozer/MovementStrategy/IMoveableObject.cs b/ProjectBuldozer/ProjectBuldozer/MovementStrategy/IMoveableObject.cs index 8c346d3..0d474fc 100644 --- a/ProjectBuldozer/ProjectBuldozer/MovementStrategy/IMoveableObject.cs +++ b/ProjectBuldozer/ProjectBuldozer/MovementStrategy/IMoveableObject.cs @@ -1,4 +1,6 @@ -namespace ProjectBuldozer.MovementStrategy; +using ProjectBuldozer.Drawnings; + +namespace ProjectBuldozer.MovementStrategy; /// /// Интерфейс для работы с перемещаемым объектом diff --git a/ProjectBuldozer/ProjectBuldozer/MovementStrategy/MoveableTyagach.cs b/ProjectBuldozer/ProjectBuldozer/MovementStrategy/MoveableTyagach.cs index e191383..12badb7 100644 --- a/ProjectBuldozer/ProjectBuldozer/MovementStrategy/MoveableTyagach.cs +++ b/ProjectBuldozer/ProjectBuldozer/MovementStrategy/MoveableTyagach.cs @@ -63,5 +63,4 @@ public class MoveableTyagach : IMoveableObjectcs MovementDirection.Down => DirectionType.Down, }; } - } diff --git a/ProjectBuldozer/ProjectBuldozer/Program.cs b/ProjectBuldozer/ProjectBuldozer/Program.cs index 564c1f6..3aa6bae 100644 --- a/ProjectBuldozer/ProjectBuldozer/Program.cs +++ b/ProjectBuldozer/ProjectBuldozer/Program.cs @@ -11,7 +11,7 @@ namespace ProjectBuldozer // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormBuldozer()); + Application.Run(new FormBuldozerCollection()); } } } \ No newline at end of file -- 2.25.1