diff --git a/ProjectCar/ProjectCar/CollectionGenericObjects/Autopark.cs b/ProjectCar/ProjectCar/CollectionGenericObjects/Autopark.cs new file mode 100644 index 0000000..0aa791e --- /dev/null +++ b/ProjectCar/ProjectCar/CollectionGenericObjects/Autopark.cs @@ -0,0 +1,62 @@ +using ProjectGasMachine.Drawnings; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectGasMachine.CollectionGenericObjects; + +public class Autopark : AbstractCompany +{ + public Autopark(int picWidth, int picHeight, ICollectionGenericObjects collection) : base(picWidth, picHeight, collection) + { + } + + protected override void DrawBackground(Graphics g) + { + Pen pen = new(Color.Black, 2); + Pen Pen2 = new(Color.Black, 3); + + for (int i = 0; i < _pictureHeight / _placeSizeHeight; i++) + { + int y = _placeSizeHeight; + y *= i; + + for (int j = 0; j <= _pictureWidth / _placeSizeWidth; j++) + { + int x = _placeSizeWidth; + x *= j; + + g.DrawLine(Pen2, x, y, x + _placeSizeWidth / 2, y); + g.DrawLine(Pen2, x, y + _placeSizeHeight - 10, x + _placeSizeWidth / 2, y + _placeSizeHeight - 10); + g.DrawLine(pen, x, y, x, y + _placeSizeHeight - 10); + } + } + } + protected override void SetObjectsPosition() + { + int n = 0; + int m = 0; + + for (int i = 0; i < (_collection?.Count ?? 0); i++) + { + if (_collection?.Get(i) != null) + { + int x = 5 + _placeSizeWidth * n; + int y = (-3 + _placeSizeHeight * (_pictureHeight / _placeSizeHeight - 1)) - _placeSizeHeight * m; + + _collection?.Get(i)?.SetPictureSize(_pictureWidth, _pictureHeight); + _collection?.Get(i)?.SetPosition(x, y); + } + + if (n < _pictureWidth / _placeSizeWidth) + n++; + else + { + n = 0; + m++; + } + } + } +} diff --git a/ProjectCar/ProjectCar/CollectionGenericObjects/MachineSharingService.cs b/ProjectCar/ProjectCar/CollectionGenericObjects/MachineSharingService.cs deleted file mode 100644 index a842369..0000000 --- a/ProjectCar/ProjectCar/CollectionGenericObjects/MachineSharingService.cs +++ /dev/null @@ -1,25 +0,0 @@ -using ProjectGasMachine.Drawnings; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ProjectGasMachine.CollectionGenericObjects; - -public class MachineSharingService : AbstractCompany -{ - public MachineSharingService(int picWidth, int picHeight, ICollectionGenericObjects collection) : base(picWidth, picHeight, collection) - { - } - - protected override void DrawBackground(Graphics g) - { - throw new NotImplementedException(); - } - - protected override void SetObjectsPosition() - { - throw new NotImplementedException(); - } -} diff --git a/ProjectCar/ProjectCar/FormGasMachine.Designer.cs b/ProjectCar/ProjectCar/FormGasMachine.Designer.cs index 09d6b1b..dfd7830 100644 --- a/ProjectCar/ProjectCar/FormGasMachine.Designer.cs +++ b/ProjectCar/ProjectCar/FormGasMachine.Designer.cs @@ -28,29 +28,16 @@ /// private void InitializeComponent() { - buttonCreate = new Button(); buttonLeft = new Button(); buttonRight = new Button(); buttonUp = new Button(); buttonDown = new Button(); pictureBoxGasMachine = new PictureBox(); - buttonCreateMachine = new Button(); comboBoxStrategy = new ComboBox(); buttonStrategyStep = new Button(); ((System.ComponentModel.ISupportInitialize)pictureBoxGasMachine).BeginInit(); SuspendLayout(); // - // buttonCreate - // - buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonCreate.Location = new Point(12, 493); - buttonCreate.Name = "buttonCreate"; - buttonCreate.Size = new Size(216, 23); - buttonCreate.TabIndex = 1; - buttonCreate.Text = "Создать газовоз"; - buttonCreate.UseVisualStyleBackColor = true; - buttonCreate.Click += ButtonCreate_Click; - // // buttonLeft // buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; @@ -108,17 +95,6 @@ pictureBoxGasMachine.TabIndex = 0; pictureBoxGasMachine.TabStop = false; // - // buttonCreateMachine - // - buttonCreateMachine.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonCreateMachine.Location = new Point(245, 493); - buttonCreateMachine.Name = "buttonCreateMachine"; - buttonCreateMachine.Size = new Size(216, 23); - buttonCreateMachine.TabIndex = 6; - buttonCreateMachine.Text = "Создать орнамент на колесах"; - buttonCreateMachine.UseVisualStyleBackColor = true; - buttonCreateMachine.Click += ButtonCreateMachine_Click; - // // comboBoxStrategy // comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList; @@ -146,12 +122,10 @@ ClientSize = new Size(988, 528); Controls.Add(buttonStrategyStep); Controls.Add(comboBoxStrategy); - Controls.Add(buttonCreateMachine); Controls.Add(buttonDown); Controls.Add(buttonUp); Controls.Add(buttonRight); Controls.Add(buttonLeft); - Controls.Add(buttonCreate); Controls.Add(pictureBoxGasMachine); Name = "FormGasMachine"; Text = "Газовоз"; @@ -160,13 +134,11 @@ } #endregion - private Button buttonCreate; private Button buttonLeft; private Button buttonRight; private Button buttonUp; private Button buttonDown; private PictureBox pictureBoxGasMachine; - private Button buttonCreateMachine; private ComboBox comboBoxStrategy; private Button buttonStrategyStep; } diff --git a/ProjectCar/ProjectCar/FormGasMachine.cs b/ProjectCar/ProjectCar/FormGasMachine.cs index 8aa8104..4f05009 100644 --- a/ProjectCar/ProjectCar/FormGasMachine.cs +++ b/ProjectCar/ProjectCar/FormGasMachine.cs @@ -15,6 +15,18 @@ public partial class FormGasMachine : Form /// private AbstractStrategy? _strategy; + public DrawningMachine SetMachine + { + set + { + _drawningMachine = value; + _drawningMachine.SetPictureSize(pictureBoxGasMachine.Height, pictureBoxGasMachine.Width); + comboBoxStrategy.Enabled = true; + _strategy = null; + Draw(); + } + } + /// /// конструктор формы /// @@ -41,57 +53,6 @@ public partial class FormGasMachine : Form _drawningMachine.DrawTransport(gr); pictureBoxGasMachine.Image = bmp; } - /// - /// создание объекта класса-перемещение - /// - /// - private void CreateObject(string type) - { - Random random = new(); - switch (type) - { - case nameof(DrawningMachine): - _drawningMachine = new DrawningMachine(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(DrawningGasMachine): - _drawningMachine = new DrawningGasMachine(random.Next(100, 300), random.Next(1000, 3000), - Color.FromArgb(random.Next(0, 256), 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), random.Next(0, 256)), - Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2))); - break; - default: - return; - } - - - _drawningMachine.SetPictureSize(pictureBoxGasMachine.Width, pictureBoxGasMachine.Height); - _drawningMachine.SetPosition(random.Next(10, 100), random.Next(10, 100)); - _strategy = null; - comboBoxStrategy.Enabled = true; - Draw(); - } - - - - - - - /// - /// обработка нажатия кнопки "создать газовоз" - /// - /// - /// - private void ButtonCreate_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningGasMachine)); - - - /// - /// обработка нажатия кнопки "создать орнамент на колесах" - /// - /// - /// - - private void ButtonCreateMachine_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningMachine)); diff --git a/ProjectCar/ProjectCar/FormGasMachineCollection.Designer.cs b/ProjectCar/ProjectCar/FormGasMachineCollection.Designer.cs new file mode 100644 index 0000000..206aab2 --- /dev/null +++ b/ProjectCar/ProjectCar/FormGasMachineCollection.Designer.cs @@ -0,0 +1,173 @@ +namespace ProjectGasMachine +{ + partial class FormGasMachineCollection + { + /// + /// 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(); + buttonRemoveMachine = new Button(); + maskedTextBoxPosition = new MaskedTextBox(); + buttonAddMachine = new Button(); + buttonAddGasMachine = new Button(); + comboBoxSelectorCompany = new ComboBox(); + pictureBox = new PictureBox(); + groupBoxTools.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit(); + SuspendLayout(); + // + // groupBoxTools + // + groupBoxTools.Controls.Add(buttonRefresh); + groupBoxTools.Controls.Add(buttonGoToCheck); + groupBoxTools.Controls.Add(buttonRemoveMachine); + groupBoxTools.Controls.Add(maskedTextBoxPosition); + groupBoxTools.Controls.Add(buttonAddMachine); + groupBoxTools.Controls.Add(buttonAddGasMachine); + groupBoxTools.Controls.Add(comboBoxSelectorCompany); + groupBoxTools.Dock = DockStyle.Right; + groupBoxTools.Location = new Point(727, 0); + groupBoxTools.Name = "groupBoxTools"; + groupBoxTools.Size = new Size(196, 543); + groupBoxTools.TabIndex = 0; + groupBoxTools.TabStop = false; + groupBoxTools.Text = "Инструменты"; + // + // buttonRefresh + // + buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonRefresh.Location = new Point(6, 487); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(184, 50); + buttonRefresh.TabIndex = 7; + buttonRefresh.Text = "Обновить"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += ButtonRefresh_Click; + // + // buttonGoToCheck + // + buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonGoToCheck.Location = new Point(6, 365); + buttonGoToCheck.Name = "buttonGoToCheck"; + buttonGoToCheck.Size = new Size(184, 50); + buttonGoToCheck.TabIndex = 6; + buttonGoToCheck.Text = "Передать на тесты"; + buttonGoToCheck.UseVisualStyleBackColor = true; + buttonGoToCheck.Click += ButtonGoToCheck_Click; + // + // buttonRemoveMachine + // + buttonRemoveMachine.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonRemoveMachine.Location = new Point(6, 265); + buttonRemoveMachine.Name = "buttonRemoveMachine"; + buttonRemoveMachine.Size = new Size(184, 50); + buttonRemoveMachine.TabIndex = 5; + buttonRemoveMachine.Text = "Удалить газовоз"; + buttonRemoveMachine.UseVisualStyleBackColor = true; + buttonRemoveMachine.Click += ButtonRemoveMachine_Click; + // + // maskedTextBoxPosition + // + maskedTextBoxPosition.Location = new Point(6, 236); + maskedTextBoxPosition.Mask = "00"; + maskedTextBoxPosition.Name = "maskedTextBoxPosition"; + maskedTextBoxPosition.Size = new Size(184, 23); + maskedTextBoxPosition.TabIndex = 4; + maskedTextBoxPosition.ValidatingType = typeof(int); + // + // buttonAddMachine + // + buttonAddMachine.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonAddMachine.Location = new Point(6, 140); + buttonAddMachine.Name = "buttonAddMachine"; + buttonAddMachine.Size = new Size(184, 50); + buttonAddMachine.TabIndex = 2; + buttonAddMachine.Text = "Добавление грузовика"; + buttonAddMachine.UseVisualStyleBackColor = true; + buttonAddMachine.Click += ButtonAddMachine_Click; + // + // buttonAddGasMachine + // + buttonAddGasMachine.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonAddGasMachine.Location = new Point(6, 84); + buttonAddGasMachine.Name = "buttonAddGasMachine"; + buttonAddGasMachine.Size = new Size(184, 50); + buttonAddGasMachine.TabIndex = 1; + buttonAddGasMachine.Text = "Добавление газовоза"; + buttonAddGasMachine.UseVisualStyleBackColor = true; + buttonAddGasMachine.Click += ButtonAddGasMachine_Click; + // + // comboBoxSelectorCompany + // + comboBoxSelectorCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxSelectorCompany.FormattingEnabled = true; + comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" }); + comboBoxSelectorCompany.Location = new Point(6, 22); + comboBoxSelectorCompany.Name = "comboBoxSelectorCompany"; + comboBoxSelectorCompany.Size = new Size(184, 23); + comboBoxSelectorCompany.TabIndex = 0; + comboBoxSelectorCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged; + // + // pictureBox + // + pictureBox.Dock = DockStyle.Fill; + pictureBox.Location = new Point(0, 0); + pictureBox.Name = "pictureBox"; + pictureBox.Size = new Size(727, 543); + pictureBox.TabIndex = 3; + pictureBox.TabStop = false; + // + // FormGasMachineCollection + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(923, 543); + Controls.Add(pictureBox); + Controls.Add(groupBoxTools); + Name = "FormGasMachineCollection"; + Text = "Коллекция газовозов"; + groupBoxTools.ResumeLayout(false); + groupBoxTools.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); + ResumeLayout(false); + } + + #endregion + + private GroupBox groupBoxTools; + private ComboBox comboBoxSelectorCompany; + private Button buttonAddMachine; + private Button buttonAddGasMachine; + private Button buttonRemoveMachine; + private MaskedTextBox maskedTextBoxPosition; + private PictureBox pictureBox; + private Button buttonRefresh; + private Button buttonGoToCheck; + } +} \ No newline at end of file diff --git a/ProjectCar/ProjectCar/FormGasMachineCollection.cs b/ProjectCar/ProjectCar/FormGasMachineCollection.cs new file mode 100644 index 0000000..6b1d249 --- /dev/null +++ b/ProjectCar/ProjectCar/FormGasMachineCollection.cs @@ -0,0 +1,186 @@ +using ProjectGasMachine.CollectionGenericObjects; +using ProjectGasMachine.Drawnings; + +namespace ProjectGasMachine +{ + /// + /// Форма работы с компанией и ее коллекцией + /// + public partial class FormGasMachineCollection : Form + { + /// + /// Компания + /// + private AbstractCompany? _company = null; + + /// + /// конструктор + /// + public FormGasMachineCollection() + { + InitializeComponent(); + } + + /// + /// Выбор компании + /// + /// + /// + private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e) + { + switch (comboBoxSelectorCompany.Text) + { + case "Хранилище": + _company = new Autopark(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects()); + break; + } + } + /// + /// Создание объекта класса-перемещения + /// + /// + private void CreateObject(string type) + { + if (_company == null) + { + return; + } + Random random = new(); + DrawningMachine drawningMachine; + switch (type) + { + case nameof(DrawningMachine): + drawningMachine = new DrawningMachine(random.Next(100, 300), random.Next(1000, 3000), GetColor(random)); + break; + case nameof(DrawningGasMachine): + drawningMachine = new DrawningGasMachine(random.Next(100, 300), random.Next(1000, 3000), GetColor(random), GetColor(random), + Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2))); + break; + default: + return; + } + + if (_company + drawningMachine != -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 ButtonAddGasMachine_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningGasMachine)); + + /// + /// добавление грузовика + /// + /// + /// + private void ButtonAddMachine_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningMachine)); + + /// + /// удаление объекта + /// + /// + /// + private void ButtonRemoveMachine_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(maskedTextBoxPosition.Text) || _company == null) + { + return; + } + + + if (MessageBox.Show("Удалить объект", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) + { + return; + } + + int pos = Convert.ToInt32(maskedTextBoxPosition.Text); + if (_company - pos != null) + { + MessageBox.Show("Объект удален"); + pictureBox.Image = _company.Show(); + } + else + { + MessageBox.Show("Не удалось удалить объект"); + } + } + + /// + /// Передача объекта в другую форму + /// + /// + /// + private void ButtonGoToCheck_Click(object sender, EventArgs e) + { + if (_company == null) + { + return; + } + + DrawningMachine? machine = null; + int counter = 100; + + while (machine == null) + { + machine = _company.GetRandomObject(); + counter--; + if (counter <= 0) + { + break; + } + } + + if (machine == null) + { + return; + } + + FormGasMachine form = new() + { + SetMachine = machine + }; + form.ShowDialog(); + } + + /// + /// Перерисовка коллекции + /// + /// + /// + private void ButtonRefresh_Click(object sender, EventArgs e) + { + if (_company == null) + { + return; + } + + pictureBox.Image = _company.Show(); + } + } +} diff --git a/ProjectCar/ProjectCar/FormGasMachineCollection.resx b/ProjectCar/ProjectCar/FormGasMachineCollection.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectCar/ProjectCar/FormGasMachineCollection.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/ProjectCar/ProjectCar/Program.cs b/ProjectCar/ProjectCar/Program.cs index 407e6fa..0c06c51 100644 --- a/ProjectCar/ProjectCar/Program.cs +++ b/ProjectCar/ProjectCar/Program.cs @@ -11,7 +11,7 @@ namespace ProjectGasMachine // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormGasMachine()); + Application.Run(new FormGasMachineCollection()); } } } \ No newline at end of file