From ceca79942a807699dcc802ff789a680d2192af02 Mon Sep 17 00:00:00 2001 From: Baryshev Dmitry Date: Wed, 20 Mar 2024 13:21:28 +0400 Subject: [PATCH] pochti vse --- .../MassiveGenericObjects.cs | 11 +-- .../FormDumpTruck.Designer.cs | 67 ++++++------------- .../ProjectDumpTruck/FormDumpTruck.cs | 67 +++++-------------- .../FormTruckCollection.Designer.cs | 2 +- .../ProjectDumpTruck/FormTruckCollection.cs | 32 ++++++++- ProjectDumpTruck/ProjectDumpTruck/Program.cs | 2 +- 6 files changed, 69 insertions(+), 112 deletions(-) diff --git a/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObject/MassiveGenericObjects.cs b/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObject/MassiveGenericObjects.cs index 59b76c1..d353df4 100644 --- a/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObject/MassiveGenericObjects.cs +++ b/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObject/MassiveGenericObjects.cs @@ -21,14 +21,9 @@ public class MassiveGenericObjects : ICollectionGenericObject { if (value > 0) { - if (_collection.Length > 0) - { - Array.Resize(ref _collection, value); - } - else - { - _collection = new T?[value]; - } + if (_collection.Length > 0) Array.Resize(ref _collection, value); + + else _collection = new T?[value]; } } } diff --git a/ProjectDumpTruck/ProjectDumpTruck/FormDumpTruck.Designer.cs b/ProjectDumpTruck/ProjectDumpTruck/FormDumpTruck.Designer.cs index 0c2749b..078fcda 100644 --- a/ProjectDumpTruck/ProjectDumpTruck/FormDumpTruck.Designer.cs +++ b/ProjectDumpTruck/ProjectDumpTruck/FormDumpTruck.Designer.cs @@ -28,35 +28,22 @@ /// private void InitializeComponent() { - buttonCreateDumpTruck = new Button(); buttonLeft = new Button(); buttonRight = new Button(); buttonUp = new Button(); buttonDown = new Button(); - buttonCreateTruck = new Button(); comboBoxStrategy = new ComboBox(); buttonStrategyStep = new Button(); - pictureBoxDumpTruck1 = new PictureBox(); - ((System.ComponentModel.ISupportInitialize)pictureBoxDumpTruck1).BeginInit(); + pictureBoxDumpTruck = new PictureBox(); + ((System.ComponentModel.ISupportInitialize)pictureBoxDumpTruck).BeginInit(); SuspendLayout(); // - // buttonCreateDumpTruck - // - buttonCreateDumpTruck.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonCreateDumpTruck.Location = new Point(12, 486); - buttonCreateDumpTruck.Name = "buttonCreateDumpTruck"; - buttonCreateDumpTruck.Size = new Size(188, 29); - buttonCreateDumpTruck.TabIndex = 1; - buttonCreateDumpTruck.Text = "Создать самосвал"; - buttonCreateDumpTruck.UseVisualStyleBackColor = true; - buttonCreateDumpTruck.Click += ButtonCreateDumpTruck_Click; - // // buttonLeft // buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonLeft.BackgroundImage = Properties.Resources.влево; buttonLeft.BackgroundImageLayout = ImageLayout.Stretch; - buttonLeft.Location = new Point(852, 469); + buttonLeft.Location = new Point(850, 469); buttonLeft.Name = "buttonLeft"; buttonLeft.Size = new Size(40, 40); buttonLeft.TabIndex = 2; @@ -68,7 +55,7 @@ buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonRight.BackgroundImage = Properties.Resources.вправо; buttonRight.BackgroundImageLayout = ImageLayout.Stretch; - buttonRight.Location = new Point(944, 469); + buttonRight.Location = new Point(942, 469); buttonRight.Name = "buttonRight"; buttonRight.Size = new Size(40, 40); buttonRight.TabIndex = 3; @@ -80,7 +67,7 @@ buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonUp.BackgroundImage = Properties.Resources.вверх; buttonUp.BackgroundImageLayout = ImageLayout.Stretch; - buttonUp.Location = new Point(898, 423); + buttonUp.Location = new Point(896, 423); buttonUp.Name = "buttonUp"; buttonUp.Size = new Size(40, 40); buttonUp.TabIndex = 4; @@ -92,37 +79,27 @@ buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonDown.BackgroundImage = Properties.Resources.вниз; buttonDown.BackgroundImageLayout = ImageLayout.Stretch; - buttonDown.Location = new Point(898, 469); + buttonDown.Location = new Point(896, 469); buttonDown.Name = "buttonDown"; buttonDown.Size = new Size(40, 40); buttonDown.TabIndex = 5; buttonDown.UseVisualStyleBackColor = true; buttonDown.Click += ButtonMove_Click; // - // buttonCreateTruck - // - buttonCreateTruck.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonCreateTruck.Location = new Point(206, 486); - buttonCreateTruck.Name = "buttonCreateTruck"; - buttonCreateTruck.Size = new Size(188, 29); - buttonCreateTruck.TabIndex = 6; - buttonCreateTruck.Text = "Создать грузовик"; - buttonCreateTruck.UseVisualStyleBackColor = true; - buttonCreateTruck.Click += ButtonCreateTruck_Click; - // // comboBoxStrategy // comboBoxStrategy.Anchor = AnchorStyles.Top | AnchorStyles.Right; comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxStrategy.FormattingEnabled = true; comboBoxStrategy.Items.AddRange(new object[] { "К центру", "К краю" }); - comboBoxStrategy.Location = new Point(833, 21); + comboBoxStrategy.Location = new Point(831, 21); comboBoxStrategy.Name = "comboBoxStrategy"; comboBoxStrategy.Size = new Size(151, 28); comboBoxStrategy.TabIndex = 7; // // buttonStrategyStep // + buttonStrategyStep.Anchor = AnchorStyles.Top | AnchorStyles.Right; buttonStrategyStep.Location = new Point(890, 55); buttonStrategyStep.Name = "buttonStrategyStep"; buttonStrategyStep.Size = new Size(94, 29); @@ -131,46 +108,40 @@ buttonStrategyStep.UseVisualStyleBackColor = true; buttonStrategyStep.Click += ButtonStrategyStep_Click; // - // pictureBoxDumpTruck1 + // pictureBoxDumpTruck // - pictureBoxDumpTruck1.Dock = DockStyle.Fill; - pictureBoxDumpTruck1.Location = new Point(0, 0); - pictureBoxDumpTruck1.Name = "pictureBoxDumpTruck1"; - pictureBoxDumpTruck1.Size = new Size(1006, 527); - pictureBoxDumpTruck1.TabIndex = 10; - pictureBoxDumpTruck1.TabStop = false; + pictureBoxDumpTruck.Dock = DockStyle.Fill; + pictureBoxDumpTruck.Location = new Point(0, 0); + pictureBoxDumpTruck.Name = "pictureBoxDumpTruck"; + pictureBoxDumpTruck.Size = new Size(1004, 527); + pictureBoxDumpTruck.TabIndex = 10; + pictureBoxDumpTruck.TabStop = false; // // FormDumpTruck // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(1006, 527); + ClientSize = new Size(1004, 527); Controls.Add(buttonStrategyStep); Controls.Add(comboBoxStrategy); - Controls.Add(buttonCreateTruck); Controls.Add(buttonDown); Controls.Add(buttonUp); Controls.Add(buttonRight); Controls.Add(buttonLeft); - Controls.Add(buttonCreateDumpTruck); - Controls.Add(pictureBoxDumpTruck1); + Controls.Add(pictureBoxDumpTruck); Name = "FormDumpTruck"; Text = "Самосвал"; - ((System.ComponentModel.ISupportInitialize)pictureBoxDumpTruck1).EndInit(); + ((System.ComponentModel.ISupportInitialize)pictureBoxDumpTruck).EndInit(); ResumeLayout(false); } #endregion - - private PictureBox pictureBoxDumpTruck; - private Button buttonCreateDumpTruck; private Button buttonLeft; private Button buttonRight; private Button buttonUp; private Button buttonDown; - private Button buttonCreateTruck; private ComboBox comboBoxStrategy; private Button buttonStrategyStep; - private PictureBox pictureBoxDumpTruck1; + private PictureBox pictureBoxDumpTruck; } } \ No newline at end of file diff --git a/ProjectDumpTruck/ProjectDumpTruck/FormDumpTruck.cs b/ProjectDumpTruck/ProjectDumpTruck/FormDumpTruck.cs index 90814c7..deeede6 100644 --- a/ProjectDumpTruck/ProjectDumpTruck/FormDumpTruck.cs +++ b/ProjectDumpTruck/ProjectDumpTruck/FormDumpTruck.cs @@ -14,6 +14,18 @@ public partial class FormDumpTruck : Form /// private AbstractStrategy? _strategy; + public DrawningTruck SetTruck + { + set + { + _drawningTruck = value; + _drawningTruck.SetPictureSize(pictureBoxDumpTruck.Width, pictureBoxDumpTruck.Height); + comboBoxStrategy.Enabled = true; + _strategy = null; + Draw(); + } + } + public FormDumpTruck() { InitializeComponent(); @@ -24,61 +36,14 @@ public partial class FormDumpTruck : Form { if (_drawningTruck == null) return; - Bitmap bmp = new(pictureBoxDumpTruck1.Width, - pictureBoxDumpTruck1.Height); + Bitmap bmp = new(pictureBoxDumpTruck.Width, + pictureBoxDumpTruck.Height); Graphics gr = Graphics.FromImage(bmp); _drawningTruck.DrawTransport(gr); - pictureBoxDumpTruck1.Image = bmp; + pictureBoxDumpTruck.Image = bmp; } - /// - /// Создание объекта класса-перемещения - /// - /// - private void CreateObject(string type) - { - - Random random = new(); - switch (type) - { - case nameof(DrawningTruck): - _drawningTruck = new DrawningTruck(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(DrawningDumpTruck): - _drawningTruck = new DrawningDumpTruck(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; - } - _drawningTruck.SetPictureSize(pictureBoxDumpTruck1.Width, pictureBoxDumpTruck1.Height); - _drawningTruck.SetPosition(random.Next(10, 100), random.Next(10, 100)); - _strategy = null; - //comboBoxStrategy.Enabled = true; - Draw(); - - } - - /// - /// Обработка нажатия кнокпки "Создать самосвал" - /// - /// - /// - private void ButtonCreateDumpTruck_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningDumpTruck)); - - /// - /// Обработка нажатия кнокпки "Создать грузовик" - /// - /// - /// - private void ButtonCreateTruck_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningTruck)); - private void ButtonMove_Click(object sender, EventArgs e) { if (_drawningTruck == null) return; @@ -122,7 +87,7 @@ public partial class FormDumpTruck : Form if (_strategy == null) return; - _strategy.SetData(new MoveableTruck(_drawningTruck), pictureBoxDumpTruck1.Width, pictureBoxDumpTruck1.Height); + _strategy.SetData(new MoveableTruck(_drawningTruck), pictureBoxDumpTruck.Width, pictureBoxDumpTruck.Height); } if (_strategy == null) return; diff --git a/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.Designer.cs b/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.Designer.cs index a3aebd8..bc2bbf2 100644 --- a/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.Designer.cs +++ b/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.Designer.cs @@ -86,7 +86,7 @@ buttonRemoveTruck.TabIndex = 4; buttonRemoveTruck.Text = "Удаление\r\n"; buttonRemoveTruck.UseVisualStyleBackColor = true; - buttonRemoveTruck.Click += buttonRemoveTruck_Click; + buttonRemoveTruck.Click += ButtonRemoveTruck_Click; // // maskedTextBoxPosition // diff --git a/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.cs b/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.cs index 34467d7..a798961 100644 --- a/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.cs +++ b/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.cs @@ -12,9 +12,14 @@ using System.Windows.Forms; namespace ProjectDumpTruck; +/// +/// Форма работы с компанией и ее коллекцией +/// public partial class FormTruckCollection : Form { - + /// + /// Компания + /// private AbstractCompany? _company = null; /// @@ -25,6 +30,11 @@ public partial class FormTruckCollection : Form InitializeComponent(); } + /// + /// Выбор компании + /// + /// + /// private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e) { switch (comboBoxSelectorCompany.Text) @@ -89,10 +99,9 @@ public partial class FormTruckCollection : Form private void ButtonAddTruck_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningTruck)); - private void ButtonAddDumpTruck_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningDumpTruck)); - private void buttonRemoveTruck_Click(object sender, EventArgs e) + private void ButtonRemoveTruck_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(maskedTextBoxPosition.Text) || _company == null) return; @@ -124,6 +133,23 @@ public partial class FormTruckCollection : Form { if (_company == null) return; + int counter = 100; + DrawningTruck? truck = null; + while (truck == null) + { + truck = _company.GetRandomObject(); + counter--; + if (counter <= 0) break; + } + + if (truck == null) return; + + FormDumpTruck form = new() + { + SetTruck = truck + }; + form.ShowDialog(); } + } diff --git a/ProjectDumpTruck/ProjectDumpTruck/Program.cs b/ProjectDumpTruck/ProjectDumpTruck/Program.cs index 6379f87..589f4a5 100644 --- a/ProjectDumpTruck/ProjectDumpTruck/Program.cs +++ b/ProjectDumpTruck/ProjectDumpTruck/Program.cs @@ -11,7 +11,7 @@ namespace ProjectDumpTruck // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormDumpTruck()); + Application.Run(new FormTruckCollection()); } } } \ No newline at end of file