From 0cef2fe107006963553537b1d1f41d7896664025 Mon Sep 17 00:00:00 2001 From: mara-1 <147929076+mara-1@users.noreply.github.com> Date: Sat, 30 Mar 2024 22:55:26 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BB=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=203?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ProjectBulldozer/.editorconfig | 4 + ProjectBulldozer/ProjectBulldozer.sln | 7 +- .../AbstractCompany.cs | 116 ++++++++++ .../CollectionGenericObjects/Garage.cs | 52 +++++ .../Drawnings/DrawingBulldozer.cs | 22 +- .../Drawnings/DrawningBulldozerProstoy.cs | 3 +- .../FormBulldozer.Designer.cs | 29 --- .../ProjectBulldozer/FormBulldozer.cs | 85 +++----- .../FormMachineCollectoin.Designer.cs | 174 +++++++++++++++ .../ProjectBulldozer/FormMachineCollectoin.cs | 206 ++++++++++++++++++ .../FormMachineCollectoin.resx | 120 ++++++++++ ProjectBulldozer/ProjectBulldozer/Program.cs | 2 +- 12 files changed, 715 insertions(+), 105 deletions(-) create mode 100644 ProjectBulldozer/.editorconfig create mode 100644 ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/AbstractCompany.cs create mode 100644 ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/Garage.cs create mode 100644 ProjectBulldozer/ProjectBulldozer/FormMachineCollectoin.Designer.cs create mode 100644 ProjectBulldozer/ProjectBulldozer/FormMachineCollectoin.cs create mode 100644 ProjectBulldozer/ProjectBulldozer/FormMachineCollectoin.resx diff --git a/ProjectBulldozer/.editorconfig b/ProjectBulldozer/.editorconfig new file mode 100644 index 0000000..90e42cd --- /dev/null +++ b/ProjectBulldozer/.editorconfig @@ -0,0 +1,4 @@ +[*.cs] + +# IDE0004: Удалить ненужное приведение +dotnet_diagnostic.IDE0004.severity = none diff --git a/ProjectBulldozer/ProjectBulldozer.sln b/ProjectBulldozer/ProjectBulldozer.sln index 294805f..b47825b 100644 --- a/ProjectBulldozer/ProjectBulldozer.sln +++ b/ProjectBulldozer/ProjectBulldozer.sln @@ -3,7 +3,12 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.9.34607.119 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProjectBulldozer", "ProjectBulldozer\ProjectBulldozer.csproj", "{B5EB70F6-27D7-48D1-B3A2-22049B8286F2}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ProjectBulldozer", "ProjectBulldozer\ProjectBulldozer.csproj", "{B5EB70F6-27D7-48D1-B3A2-22049B8286F2}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{5D00A175-7BBA-4247-B014-5919F831C588}" + ProjectSection(SolutionItems) = preProject + .editorconfig = .editorconfig + EndProjectSection EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/AbstractCompany.cs b/ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/AbstractCompany.cs new file mode 100644 index 0000000..eabef91 --- /dev/null +++ b/ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/AbstractCompany.cs @@ -0,0 +1,116 @@ +using ProjectBulldozer.Drawnings; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectBulldozer.CollectionGenericObjects; + +public abstract class AbstractCompany +{ + /// + /// Размер места (ширина) + /// + protected readonly int _placeSizeWidth = 180; + + /// + /// Размер места (высота) + /// + protected readonly int _placeSizeHeight = 150; + + /// + /// Ширина окна + /// + 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, DrawningTrackedMachine trackedMachine) + { + return company._collection.Insert(trackedMachine); + } + + /// + /// Перегрузка оператора удаления для класса + /// + /// Компания + /// Номер удаляемого объекта + /// + public static DrawningTrackedMachine operator -(AbstractCompany company, int position) + { + return company._collection.Remove(position); + } + + /// + /// Получение случайного объекта из коллекции + /// + /// + public DrawningTrackedMachine? 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) + { + DrawningTrackedMachine? obj = _collection?.Get(i); + obj?.DrawTransport(graphics); + } + return bitmap; + } + + /// + /// Вывод заднего фона + /// + /// + protected abstract void DrawBackgound(Graphics g); + /// + /// Расстановка объектов + /// + protected abstract void SetObjectsPosition(); +} diff --git a/ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/Garage.cs b/ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/Garage.cs new file mode 100644 index 0000000..e3673e1 --- /dev/null +++ b/ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/Garage.cs @@ -0,0 +1,52 @@ +using ProjectBulldozer.Drawnings; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectBulldozer.CollectionGenericObjects; + +public class Garage : AbstractCompany +{ + public Garage(int picWidth, int picHeight, ICollectionGenericObjects collection) : base(picWidth, picHeight, collection) + { + } + + protected override void DrawBackgound(Graphics g) + { + Pen pen = new(Color.Black, 4f); + for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++) + { + for (int j = 0; j < _pictureHeight / _placeSizeHeight; j++) + { + g.DrawLine(pen, new(_placeSizeWidth * i, _placeSizeHeight * j), new((int)(_placeSizeWidth * (i + 0.5f)), _placeSizeHeight * j)); + g.DrawLine(pen, new(_placeSizeWidth * i, _placeSizeHeight * j), new(_placeSizeWidth * i, _placeSizeHeight * (j + 1))); + } + g.DrawLine(pen, new(_placeSizeWidth * i, _placeSizeHeight * (_pictureHeight / _placeSizeHeight)), new((int)(_placeSizeWidth * (i + 0.5f)), _placeSizeHeight * (_pictureHeight / _placeSizeHeight))); + } + } + + protected override void SetObjectsPosition() + { + + int n = 0; + for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++) + { + for (int j = 0; j < _pictureHeight / _placeSizeHeight; j++) + { + + DrawningTrackedMachine? drawningTrackedMachine = _collection?.Get(n); + n++; + if (drawningTrackedMachine != null) + { + drawningTrackedMachine.SetPictureSize(_pictureWidth, _pictureHeight); + drawningTrackedMachine.SetPosition(i * _placeSizeWidth + 5, j * _placeSizeHeight + 5); + + } + + } + } + + } +} diff --git a/ProjectBulldozer/ProjectBulldozer/Drawnings/DrawingBulldozer.cs b/ProjectBulldozer/ProjectBulldozer/Drawnings/DrawingBulldozer.cs index 79f0a78..bbb04b3 100644 --- a/ProjectBulldozer/ProjectBulldozer/Drawnings/DrawingBulldozer.cs +++ b/ProjectBulldozer/ProjectBulldozer/Drawnings/DrawingBulldozer.cs @@ -36,7 +36,7 @@ public class DrawningBulldozer : DrawningTrackedMachine Pen pen = new(Color.Black); Brush bodyBrush = new SolidBrush(Bulldozer.BodyColor); - Brush bodyBrush2 = new SolidBrush(Bulldozer.AdditionalColor); + @@ -46,11 +46,10 @@ public class DrawningBulldozer : DrawningTrackedMachine base.DrawTransport(g); _startPosX -= 10; - Brush bl = new SolidBrush(Bulldozer.AdditionalColor); + Brush bodyBrush2 = new SolidBrush(Bulldozer.AdditionalColor); /////////отвал /// - if (Bulldozer.AdditionalOtval) - { + Point[] Otval = { new Point(_startPosX.Value + 142, _startPosY.Value + 70), @@ -60,17 +59,6 @@ public class DrawningBulldozer : DrawningTrackedMachine }; - g.FillPolygon(bl, Otval); - g.DrawPolygon(pen, Otval); - } - - - - - - ///рыхлитель - if (Bulldozer.AdditionalRihl) - { Brush black = new SolidBrush(Color.Black); Point[] Rihl = { @@ -93,7 +81,9 @@ public class DrawningBulldozer : DrawningTrackedMachine g.FillPolygon(black, Ttt); g.DrawPolygon(pen, Ttt); - } + g.FillPolygon(bodyBrush2, Otval); + g.DrawPolygon(pen, Otval); + } } diff --git a/ProjectBulldozer/ProjectBulldozer/Drawnings/DrawningBulldozerProstoy.cs b/ProjectBulldozer/ProjectBulldozer/Drawnings/DrawningBulldozerProstoy.cs index e563f4c..9920768 100644 --- a/ProjectBulldozer/ProjectBulldozer/Drawnings/DrawningBulldozerProstoy.cs +++ b/ProjectBulldozer/ProjectBulldozer/Drawnings/DrawningBulldozerProstoy.cs @@ -148,8 +148,7 @@ public class DrawningTrackedMachine public bool MoveTransport(DirectionType direction) { - if (EntityTrackedMachine == null || !_startPosX.HasValue || - !_startPosY.HasValue) + if (EntityTrackedMachine == null || !_startPosX.HasValue || !_startPosY.HasValue) { return false; } diff --git a/ProjectBulldozer/ProjectBulldozer/FormBulldozer.Designer.cs b/ProjectBulldozer/ProjectBulldozer/FormBulldozer.Designer.cs index 4f1123f..d9ad7ab 100644 --- a/ProjectBulldozer/ProjectBulldozer/FormBulldozer.Designer.cs +++ b/ProjectBulldozer/ProjectBulldozer/FormBulldozer.Designer.cs @@ -29,12 +29,10 @@ private void InitializeComponent() { pictureBoxBulldozer = new PictureBox(); - buttonCreate = new Button(); buttonRight = new Button(); buttonDown = new Button(); buttonLeft = new Button(); buttonUp = new Button(); - buttonCreateBulldozerProstoy = new Button(); ButtonStrategyStep = new Button(); comboBoxStrategy = new ComboBox(); ((System.ComponentModel.ISupportInitialize)pictureBoxBulldozer).BeginInit(); @@ -49,17 +47,6 @@ pictureBoxBulldozer.TabIndex = 0; pictureBoxBulldozer.TabStop = false; // - // buttonCreate - // - buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonCreate.Location = new Point(12, 511); - buttonCreate.Name = "buttonCreate"; - buttonCreate.Size = new Size(231, 29); - buttonCreate.TabIndex = 1; - buttonCreate.Text = "Создать бульозер с доп."; - buttonCreate.UseVisualStyleBackColor = true; - buttonCreate.Click += ButtonCreateBulldozer_Click; - // // buttonRight // buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; @@ -108,17 +95,6 @@ buttonUp.UseVisualStyleBackColor = true; buttonUp.Click += ButtonMove_Click; // - // buttonCreateBulldozerProstoy - // - buttonCreateBulldozerProstoy.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonCreateBulldozerProstoy.Location = new Point(274, 511); - buttonCreateBulldozerProstoy.Name = "buttonCreateBulldozerProstoy"; - buttonCreateBulldozerProstoy.Size = new Size(231, 29); - buttonCreateBulldozerProstoy.TabIndex = 6; - buttonCreateBulldozerProstoy.Text = "Создать простой бульдозер"; - buttonCreateBulldozerProstoy.UseVisualStyleBackColor = true; - buttonCreateBulldozerProstoy.Click += buttonCreateBulldozerProstoy_Click; - // // ButtonStrategyStep // ButtonStrategyStep.Location = new Point(793, 46); @@ -138,19 +114,16 @@ comboBoxStrategy.Name = "comboBoxStrategy"; comboBoxStrategy.Size = new Size(143, 28); comboBoxStrategy.TabIndex = 9; - // // FormBulldozer // ClientSize = new Size(899, 552); Controls.Add(comboBoxStrategy); Controls.Add(ButtonStrategyStep); - Controls.Add(buttonCreateBulldozerProstoy); Controls.Add(buttonUp); Controls.Add(buttonLeft); Controls.Add(buttonDown); Controls.Add(buttonRight); - Controls.Add(buttonCreate); Controls.Add(pictureBoxBulldozer); Name = "FormBulldozer"; ((System.ComponentModel.ISupportInitialize)pictureBoxBulldozer).EndInit(); @@ -161,12 +134,10 @@ private PictureBox pictureBoxBulldozer; - private Button buttonCreate; private Button buttonRight; private Button buttonDown; private Button buttonLeft; private Button buttonUp; - private Button buttonCreateBulldozerProstoy; private Button ButtonStrategyStep; private ComboBox comboBoxStrategy; } diff --git a/ProjectBulldozer/ProjectBulldozer/FormBulldozer.cs b/ProjectBulldozer/ProjectBulldozer/FormBulldozer.cs index e689bfb..abd47f2 100644 --- a/ProjectBulldozer/ProjectBulldozer/FormBulldozer.cs +++ b/ProjectBulldozer/ProjectBulldozer/FormBulldozer.cs @@ -17,9 +17,28 @@ namespace ProjectBulldozer /// /// Поле-объект для прорисовки объекта /// - private DrawningTrackedMachine? _drawningBulldozerProstoy; + private DrawningTrackedMachine? _drawningTrackedMachine; + /// + /// Стратегия перемещения + /// private AbstractStrategy? _strategy; + + /// + /// Получение объекта + /// + public DrawningTrackedMachine SetTrackedMachine + { + set + { + _drawningTrackedMachine = value; + _drawningTrackedMachine.SetPictureSize(pictureBoxBulldozer.Width, pictureBoxBulldozer.Height); + comboBoxStrategy.Enabled = true; + _strategy = null; + Draw(); + } + } + /// /// Конструктор формы /// @@ -33,63 +52,17 @@ namespace ProjectBulldozer /// private void Draw() { - if (_drawningBulldozerProstoy == null) + if (_drawningTrackedMachine == null) { return; } Bitmap bmp = new(pictureBoxBulldozer.Width, pictureBoxBulldozer.Height); Graphics gr = Graphics.FromImage(bmp); - _drawningBulldozerProstoy.DrawTransport(gr); + _drawningTrackedMachine.DrawTransport(gr); pictureBoxBulldozer.Image = bmp; } - /// - /// создеание объекта класса-перемещения - /// - /// Тип создаваемого объекта - private void CreateObject(string type) - { - Random random = new(); - switch (type) - { - case nameof(DrawningTrackedMachine): - _drawningBulldozerProstoy = new DrawningTrackedMachine(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(DrawningBulldozer): - _drawningBulldozerProstoy = new DrawningBulldozer(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; - } - - _drawningBulldozerProstoy.SetPictureSize(pictureBoxBulldozer.Width, pictureBoxBulldozer.Height); - _drawningBulldozerProstoy.SetPosition(random.Next(10, 100), random.Next(10, 100)); - _strategy = null; - comboBoxStrategy.Enabled = true; - Draw(); - } - - - /// - /// Обработка нажатия кнопки "Создать бульдозер с доп." - /// - /// - /// - private void ButtonCreateBulldozer_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningBulldozer)); - - /// - /// Обработка нажатия кнопки "Создать обычный бульдозер" - /// - /// - /// - private void buttonCreateBulldozerProstoy_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningTrackedMachine)); - /// /// Перемещение объекта по форме (нажатие кнопок навигации) /// @@ -97,7 +70,7 @@ namespace ProjectBulldozer /// private void ButtonMove_Click(object sender, EventArgs e) { - if (_drawningBulldozerProstoy == null) + if (_drawningTrackedMachine == null) { return; } @@ -107,19 +80,19 @@ namespace ProjectBulldozer { case "buttonUp": result = - _drawningBulldozerProstoy.MoveTransport(DirectionType.Up); + _drawningTrackedMachine.MoveTransport(DirectionType.Up); break; case "buttonDown": result = - _drawningBulldozerProstoy.MoveTransport(DirectionType.Down); + _drawningTrackedMachine.MoveTransport(DirectionType.Down); break; case "buttonLeft": result = - _drawningBulldozerProstoy.MoveTransport(DirectionType.Left); + _drawningTrackedMachine.MoveTransport(DirectionType.Left); break; case "buttonRight": result = - _drawningBulldozerProstoy.MoveTransport(DirectionType.Right); + _drawningTrackedMachine.MoveTransport(DirectionType.Right); break; } if (result) @@ -130,7 +103,7 @@ namespace ProjectBulldozer private void ButtonStrategyStep_Click(object sender, EventArgs e) { - if (_drawningBulldozerProstoy == null) + if (_drawningTrackedMachine == null) { return; } @@ -147,7 +120,7 @@ namespace ProjectBulldozer { return; } - _strategy.SetData(new MoveableBulldozer(_drawningBulldozerProstoy), + _strategy.SetData(new MoveableBulldozer(_drawningTrackedMachine), pictureBoxBulldozer.Width, pictureBoxBulldozer.Height); } diff --git a/ProjectBulldozer/ProjectBulldozer/FormMachineCollectoin.Designer.cs b/ProjectBulldozer/ProjectBulldozer/FormMachineCollectoin.Designer.cs new file mode 100644 index 0000000..9e9b294 --- /dev/null +++ b/ProjectBulldozer/ProjectBulldozer/FormMachineCollectoin.Designer.cs @@ -0,0 +1,174 @@ +namespace ProjectBulldozer +{ + partial class FormMachineCollectoin + { + /// + /// 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(); + maskedTextBox = new MaskedTextBox(); + comboBoxSelectorCompany = new ComboBox(); + buttonGoToCheck = new Button(); + buttonRemoveMachine = new Button(); + buttonAddBulldozer = new Button(); + buttonAddMachine = new Button(); + pictureBox = new PictureBox(); + groupBoxTools.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit(); + SuspendLayout(); + // + // groupBoxTools + // + groupBoxTools.Controls.Add(buttonRefresh); + groupBoxTools.Controls.Add(maskedTextBox); + groupBoxTools.Controls.Add(comboBoxSelectorCompany); + groupBoxTools.Controls.Add(buttonGoToCheck); + groupBoxTools.Controls.Add(buttonRemoveMachine); + groupBoxTools.Controls.Add(buttonAddBulldozer); + groupBoxTools.Controls.Add(buttonAddMachine); + groupBoxTools.Dock = DockStyle.Right; + groupBoxTools.Location = new Point(742, 0); + groupBoxTools.Name = "groupBoxTools"; + groupBoxTools.Size = new Size(200, 583); + groupBoxTools.TabIndex = 0; + groupBoxTools.TabStop = false; + groupBoxTools.Text = "Инструменты"; + // + // buttonRefresh + // + buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonRefresh.Location = new Point(6, 435); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(188, 51); + buttonRefresh.TabIndex = 6; + buttonRefresh.Text = "Обновить"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += ButtonRefresh_Click; + // + // maskedTextBox + // + maskedTextBox.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + maskedTextBox.Location = new Point(6, 227); + maskedTextBox.Mask = "00"; + maskedTextBox.Name = "maskedTextBox"; + maskedTextBox.Size = new Size(188, 27); + maskedTextBox.TabIndex = 5; + maskedTextBox.ValidatingType = typeof(int); + // + // comboBoxSelectorCompany + // + comboBoxSelectorCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxSelectorCompany.FormattingEnabled = true; + comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" }); + comboBoxSelectorCompany.Location = new Point(6, 26); + comboBoxSelectorCompany.Name = "comboBoxSelectorCompany"; + comboBoxSelectorCompany.Size = new Size(188, 28); + comboBoxSelectorCompany.TabIndex = 4; + comboBoxSelectorCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged; + // + // buttonGoToCheck + // + buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonGoToCheck.Location = new Point(6, 349); + buttonGoToCheck.Name = "buttonGoToCheck"; + buttonGoToCheck.Size = new Size(188, 51); + buttonGoToCheck.TabIndex = 3; + buttonGoToCheck.Text = "Передать на тесты"; + buttonGoToCheck.UseVisualStyleBackColor = true; + buttonGoToCheck.Click += ButtonGoToCheck_Click; + // + // buttonRemoveMachine + // + buttonRemoveMachine.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonRemoveMachine.Location = new Point(6, 260); + buttonRemoveMachine.Name = "buttonRemoveMachine"; + buttonRemoveMachine.Size = new Size(188, 51); + buttonRemoveMachine.TabIndex = 2; + buttonRemoveMachine.Text = "Удалить машину"; + buttonRemoveMachine.UseVisualStyleBackColor = true; + buttonRemoveMachine.Click += ButtonRemoveMachine_Click; + // + // buttonAddBulldozer + // + buttonAddBulldozer.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonAddBulldozer.Location = new Point(6, 135); + buttonAddBulldozer.Name = "buttonAddBulldozer"; + buttonAddBulldozer.Size = new Size(188, 51); + buttonAddBulldozer.TabIndex = 1; + buttonAddBulldozer.Text = "Добавление бульдозера"; + buttonAddBulldozer.UseVisualStyleBackColor = true; + buttonAddBulldozer.Click += ButtonAddBulldozer_Click; + // + // buttonAddMachine + // + buttonAddMachine.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonAddMachine.Location = new Point(6, 78); + buttonAddMachine.Name = "buttonAddMachine"; + buttonAddMachine.Size = new Size(188, 51); + buttonAddMachine.TabIndex = 0; + buttonAddMachine.Text = "Добавление гусеничной машины"; + buttonAddMachine.UseVisualStyleBackColor = true; + buttonAddMachine.Click += ButtonAddMachine_Click; + // + // pictureBox + // + pictureBox.Dock = DockStyle.Fill; + pictureBox.Location = new Point(0, 0); + pictureBox.Name = "pictureBox"; + pictureBox.Size = new Size(742, 583); + pictureBox.TabIndex = 5; + pictureBox.TabStop = false; + // + // FormMachineCollectoin + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(942, 583); + Controls.Add(pictureBox); + Controls.Add(groupBoxTools); + Name = "FormMachineCollectoin"; + Text = "Коллекция машин"; + groupBoxTools.ResumeLayout(false); + groupBoxTools.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); + ResumeLayout(false); + } + + #endregion + + private GroupBox groupBoxTools; + private ComboBox comboBoxSelectorCompany; + private Button buttonGoToCheck; + private Button buttonRemoveMachine; + private Button buttonAddBulldozer; + private Button buttonAddMachine; + private MaskedTextBox maskedTextBox; + private PictureBox pictureBox; + private Button buttonRefresh; + } +} \ No newline at end of file diff --git a/ProjectBulldozer/ProjectBulldozer/FormMachineCollectoin.cs b/ProjectBulldozer/ProjectBulldozer/FormMachineCollectoin.cs new file mode 100644 index 0000000..533d432 --- /dev/null +++ b/ProjectBulldozer/ProjectBulldozer/FormMachineCollectoin.cs @@ -0,0 +1,206 @@ +using ProjectBulldozer.CollectionGenericObjects; +using ProjectBulldozer.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 ProjectBulldozer; + +/// +/// Форма работы с компанией и ее коллекцией +/// + /// Компания + /// + private AbstractCompany? _company = null; + + /// + /// Конструктор + /// + public FormMachineCollectoin() + { + InitializeComponent(); + } + + /// + /// Выбор компании + /// + /// + /// + private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e) + { + switch (comboBoxSelectorCompany.Text) + { + case "Хранилище": + _company = new Garage(pictureBox.Width, + pictureBox.Height, new MassiveGenericObjects()); + break; + } + + } + + /// + /// создеание объекта класса-перемещения + /// + /// Тип создаваемого объекта + private void CreateObject(string type) + { + if (_company == null) + { + return; + } + + Random random = new(); + DrawningTrackedMachine drawningTrackedMachine; + + switch (type) + { + case nameof(DrawningTrackedMachine): + drawningTrackedMachine = new DrawningTrackedMachine(random.Next(100, 300), random.Next(1000, 3000), GetColor(random)); + break; + case nameof(DrawningBulldozer): + drawningTrackedMachine = new DrawningBulldozer(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 + drawningTrackedMachine >= 0) + { + 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 ButtonAddMachine_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningTrackedMachine)); + + + /// + /// Добавление бульдозера + /// + /// + /// + private void ButtonAddBulldozer_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningBulldozer)); + + /// + /// Удаление объекта + /// + /// + /// + private void ButtonRemoveMachine_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; + } + + DrawningTrackedMachine? trackedMachine = null; + int counter = 100; + while (trackedMachine == null) + { + trackedMachine = _company.GetRandomObject(); + counter--; + if (counter <= 0) + { + break; + } + } + if (trackedMachine == null) + { + return; + } + + FormBulldozer form = new() + { + SetTrackedMachine = trackedMachine + }; + form.ShowDialog(); + + + } + + /// + /// Перерисовка коллекции + /// + /// + /// + private void ButtonRefresh_Click(object sender, EventArgs e) + { + if (_company == null) + { + return; + } + + pictureBox.Image = _company.Show(); + } + + +} diff --git a/ProjectBulldozer/ProjectBulldozer/FormMachineCollectoin.resx b/ProjectBulldozer/ProjectBulldozer/FormMachineCollectoin.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectBulldozer/ProjectBulldozer/FormMachineCollectoin.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/ProjectBulldozer/ProjectBulldozer/Program.cs b/ProjectBulldozer/ProjectBulldozer/Program.cs index ce4d1f0..ecc7358 100644 --- a/ProjectBulldozer/ProjectBulldozer/Program.cs +++ b/ProjectBulldozer/ProjectBulldozer/Program.cs @@ -11,7 +11,7 @@ namespace ProjectBulldozer // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormBulldozer()); + Application.Run(new FormMachineCollectoin()); } } } \ No newline at end of file