From a666cfd26161b70e51f0d038b240e5428c98e614 Mon Sep 17 00:00:00 2001 From: KirillFirsof <117719052+KirillFirsof@users.noreply.github.com> Date: Thu, 9 Nov 2023 14:31:52 +0400 Subject: [PATCH 1/6] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RPP_FirstLaba_Tractor/DrawningTractor.cs | 7 + .../RPP_FirstLaba_Tractor/FormTractor.cs | 141 +++++++++++++---- .../FormTractorCollection.Designer.cs | 146 ++++++++++++++++++ .../FormTractorCollection.cs | 20 +++ .../FormTractorCollection.resx | 60 +++++++ .../RPP_FirstLaba_Tractor/SetGeneric.cs | 101 ++++++++++++ .../TractorsGenericCollection.cs | 146 ++++++++++++++++++ 7 files changed, 590 insertions(+), 31 deletions(-) create mode 100644 RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.Designer.cs create mode 100644 RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.cs create mode 100644 RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.resx create mode 100644 RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/SetGeneric.cs create mode 100644 RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericCollection.cs diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/DrawningTractor.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/DrawningTractor.cs index c5af8d8..578ec20 100644 --- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/DrawningTractor.cs +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/DrawningTractor.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using ProjectTractor.Entities; +using ProjectTractor.MovementStrategy; namespace ProjectTractor.DrawningObjects { @@ -79,6 +80,12 @@ namespace ProjectTractor.DrawningObjects { EntityTractor = new EntityTractor(speed, weight, bodyColor); } + /// + /// Получение объекта IMoveableObject из объекта DrawningCar + /// + public IMoveableObject GetMoveableObject => new + DrawningObjectTractor(this); + /// /// Координата X объекта diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractor.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractor.cs index 4dcb86d..7bd9091 100644 --- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractor.cs +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractor.cs @@ -20,30 +20,26 @@ namespace ProjectTractor private ComboBox comboBoxStrategy; private Button buttonRight; - /// - /// - /// - private AbstractStrategy? _abstractStrategy; - - public int getPictureWidth() - { - return pictureBoxTractor.Width; - } - public int getPictureHeight() - { - return pictureBoxTractor.Height; - } - /// /// - /// private DrawningTractor? _drawningTractor; /// + /// + /// + private AbstractStrategy? _strategy; + /// + /// + /// + public DrawningTractor? SelectedTractor { get; private set; } + /// /// /// public FormTractor() { InitializeComponent(); + _strategy = null; + SelectedTractor = null; } /// /// @@ -65,19 +61,26 @@ namespace ProjectTractor /// /// /// - private void ButtonCreate_Click(object sender, EventArgs e) + private void ButtonCreateBulldoserTractor_Click(object sender, EventArgs e) { Random random = new(); - _drawningTractor = new DrawningTractor(random.Next(100, 300), - random.Next(1000, 3000), - Color.FromArgb(random.Next(0, 256), random.Next(0, 256), - random.Next(0, 256)), - pictureBoxTractor.Width, pictureBoxTractor.Height); - _drawningTractor.SetPosition(random.Next(10, 100), - random.Next(10, 100)); + Color color = Color.FromArgb(random.Next(0, 256), + random.Next(0, 256), random.Next(0, 256)); + //TODO + Color dopColor = Color.FromArgb(random.Next(0, 256), + random.Next(0, 256), random.Next(0, 256)); + //TODO + _drawningTractor = new DrawningBulldoser(random.Next(100, 300), + random.Next(1000, 3000), + color, + dopColor, + Convert.ToBoolean(random.Next(0, 2)), + Convert.ToBoolean(random.Next(0, 2)), + pictureBoxTractor.Width, + pictureBoxTractor.Height); + _drawningTractor.SetPosition(random.Next(10, 100), random.Next(10, 100)); Draw(); } - /// /// /// @@ -92,7 +95,7 @@ namespace ProjectTractor string name = ((Button)sender)?.Name ?? string.Empty; switch (name) { - case "buttonTop": + case "buttonUp": _drawningTractor.MoveTransport(DirectionType.Up); break; case "buttonDown": @@ -107,6 +110,76 @@ namespace ProjectTractor } Draw(); } + /// + /// + /// + /// + /// + private void ButtonCreate_Click(object sender, EventArgs e) + { + Random random = new(); + 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; + } + _drawningTractor = new DrawningTractor(random.Next(100, 300), + random.Next(1000, 3000), color, + pictureBoxTractor.Width, pictureBoxTractor.Height); + _drawningTractor.SetPosition(random.Next(10, 100), random.Next(10, + 100)); + Draw(); + } + /// + /// + /// + /// + /// + private void ButtonStartegyStep_Click(object sender, EventArgs e) + { + if (_drawningTractor == null) + { + return; + } + if (comboBoxStrategy.Enabled) + { + _strategy = comboBoxStrategy.SelectedIndex switch + { + 0 => new MoveToCenter(), + 1 => new MoveToBorder(), + _ => null, + }; + if (_strategy == null) + { + return; + } + _strategy.SetData(_drawningTractor.GetMoveableObject, + pictureBoxTractor.Width, pictureBoxTractor.Height); + } + if (_strategy == null) + { + return; + } + comboBoxStrategy.Enabled = false; + _strategy.MakeStep(); + Draw(); + if (_strategy.GetStatus() == Status.Finish) + { + comboBoxStrategy.Enabled = true; + _strategy = null; + } + } + /// + /// + /// + /// + /// + private void ButtonSelectCar_Click(object sender, EventArgs e) + { + SelectedTractor = _drawningTractor; + DialogResult = DialogResult.OK; + } private void InitializeComponent() { @@ -239,6 +312,7 @@ namespace ProjectTractor this.Controls.Add(this.buttonCreateTractor); this.Controls.Add(this.pictureBoxTractor); this.Name = "FormTractor"; + this.Load += new System.EventHandler(this.FormTractor_Load); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxTractor)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -271,33 +345,38 @@ namespace ProjectTractor } if (comboBoxStrategy.Enabled) { - _abstractStrategy = comboBoxStrategy.SelectedIndex + _strategy = comboBoxStrategy.SelectedIndex switch { 0 => new MoveToCenter(), 1 => new MoveToBorder(), _ => null, }; - if (_abstractStrategy == null) + if (_strategy == null) { return; } - _abstractStrategy.SetData(new + _strategy.SetData(new DrawningObjectTractor(_drawningTractor), pictureBoxTractor.Width, pictureBoxTractor.Height); comboBoxStrategy.Enabled = false; } - if (_abstractStrategy == null) + if (_strategy == null) { return; } - _abstractStrategy.MakeStep(); + _strategy.MakeStep(); Draw(); - if (_abstractStrategy.GetStatus() == Status.Finish) + if (_strategy.GetStatus() == Status.Finish) { comboBoxStrategy.Enabled = true; - _abstractStrategy = null; + _strategy = null; } } + + private void FormTractor_Load(object sender, EventArgs e) + { + + } } } \ No newline at end of file diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.Designer.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.Designer.cs new file mode 100644 index 0000000..baa946f --- /dev/null +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.Designer.cs @@ -0,0 +1,146 @@ +namespace ProjectTractor +{ + partial class FormTractorCollection + { + /// + /// 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() + { + this.splitContainer1 = new System.Windows.Forms.SplitContainer(); + this.pictureBox1 = new System.Windows.Forms.PictureBox(); + this.labelPanelInstuments = new System.Windows.Forms.Label(); + this.maskedTextBoxNumber = new System.Windows.Forms.MaskedTextBox(); + this.button1 = new System.Windows.Forms.Button(); + this.button2 = new System.Windows.Forms.Button(); + this.button3 = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); + this.splitContainer1.Panel1.SuspendLayout(); + this.splitContainer1.Panel2.SuspendLayout(); + this.splitContainer1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); + this.SuspendLayout(); + // + // splitContainer1 + // + this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill; + this.splitContainer1.Location = new System.Drawing.Point(0, 0); + this.splitContainer1.Name = "splitContainer1"; + // + // splitContainer1.Panel1 + // + this.splitContainer1.Panel1.Controls.Add(this.pictureBox1); + // + // splitContainer1.Panel2 + // + this.splitContainer1.Panel2.Controls.Add(this.button3); + this.splitContainer1.Panel2.Controls.Add(this.button2); + this.splitContainer1.Panel2.Controls.Add(this.button1); + this.splitContainer1.Panel2.Controls.Add(this.maskedTextBoxNumber); + this.splitContainer1.Panel2.Controls.Add(this.labelPanelInstuments); + this.splitContainer1.Size = new System.Drawing.Size(800, 450); + this.splitContainer1.SplitterDistance = 591; + this.splitContainer1.TabIndex = 0; + // + // pictureBox1 + // + this.pictureBox1.Dock = System.Windows.Forms.DockStyle.Fill; + this.pictureBox1.Location = new System.Drawing.Point(0, 0); + this.pictureBox1.Name = "pictureBox1"; + this.pictureBox1.Size = new System.Drawing.Size(591, 450); + this.pictureBox1.TabIndex = 0; + this.pictureBox1.TabStop = false; + // + // labelPanelInstuments + // + this.labelPanelInstuments.AutoSize = true; + this.labelPanelInstuments.Location = new System.Drawing.Point(8, 9); + this.labelPanelInstuments.Name = "labelPanelInstuments"; + this.labelPanelInstuments.Size = new System.Drawing.Size(103, 20); + this.labelPanelInstuments.TabIndex = 0; + this.labelPanelInstuments.Text = "Инструменты"; + // + // maskedTextBoxNumber + // + this.maskedTextBoxNumber.Location = new System.Drawing.Point(8, 146); + this.maskedTextBoxNumber.Name = "maskedTextBoxNumber"; + this.maskedTextBoxNumber.Size = new System.Drawing.Size(185, 27); + this.maskedTextBoxNumber.TabIndex = 1; + // + // button1 + // + this.button1.Location = new System.Drawing.Point(8, 54); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(185, 40); + this.button1.TabIndex = 2; + this.button1.Text = "Добавить трактор"; + this.button1.UseVisualStyleBackColor = true; + // + // button2 + // + this.button2.Location = new System.Drawing.Point(8, 179); + this.button2.Name = "button2"; + this.button2.Size = new System.Drawing.Size(185, 36); + this.button2.TabIndex = 3; + this.button2.Text = "Удалить трактор"; + this.button2.UseVisualStyleBackColor = true; + // + // button3 + // + this.button3.Location = new System.Drawing.Point(8, 376); + this.button3.Name = "button3"; + this.button3.Size = new System.Drawing.Size(185, 42); + this.button3.TabIndex = 4; + this.button3.Text = "Обновить коллекцию"; + this.button3.UseVisualStyleBackColor = true; + // + // FormTractorCollection + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.splitContainer1); + this.Name = "FormTractorCollection"; + this.Text = "FormTractorCollection"; + this.splitContainer1.Panel1.ResumeLayout(false); + this.splitContainer1.Panel2.ResumeLayout(false); + this.splitContainer1.Panel2.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit(); + this.splitContainer1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private SplitContainer splitContainer1; + private PictureBox pictureBox1; + private Button button3; + private Button button2; + private Button button1; + private MaskedTextBox maskedTextBoxNumber; + private Label labelPanelInstuments; + } +} \ No newline at end of file diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.cs new file mode 100644 index 0000000..6ed2112 --- /dev/null +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.cs @@ -0,0 +1,20 @@ +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 ProjectTractor +{ + public partial class FormTractorCollection : Form + { + public FormTractorCollection() + { + InitializeComponent(); + } + } +} diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.resx b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/SetGeneric.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/SetGeneric.cs new file mode 100644 index 0000000..ee4787f --- /dev/null +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/SetGeneric.cs @@ -0,0 +1,101 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectTractor.Generics +{ + internal class SetGeneric + where T : class + { + /// + /// Массив объектов, которые храним + /// + private readonly T?[] _places; + /// + /// Количество объектов в массиве + /// + public int Count => _places.Length; + /// + /// Конструктор + /// + /// + public SetGeneric(int count) + { + _places = new T?[count]; + } + /// + /// Добавление объекта в набор + /// + /// Добавляемый трактор + /// + public bool Insert(T tractor) + { + if (_places[0] == null) + { + _places[0] = tractor; + } + else + { + Insert(tractor, 0); + } + // TODO вставка в начало набора + return true; + } + /// + /// Добавление объекта в набор на конкретную позицию + /// + /// Добавляемый автомобиль + /// Позиция + /// + public bool Insert(T tractor, int position) + { + + if (!(position >= 0 && position < Count)) + return false; + if (_places[position] != null) + { + int ind = position; + while (ind < Count && _places[ind] != null) + ind++; + if (ind == Count) + return false; + for (int i = ind - 1; i >= position; i--) + _places[i + 1] = _places[i]; + } + _places[position] = tractor; + return true; + } + /// + /// Удаление объекта из набора с конкретной позиции + /// + /// + /// + public bool Remove(int position) + { + if (!(position >= 0 && position < Count)) + { + return false; + } + _places[position] = null; + return true; + // TODO проверка позиции + // TODO удаление объекта из массива, присвоив элементу массива значение null + } + /// + /// Получение объекта из набора по позиции + /// + /// + /// + public T? Get(int position) + { + if (!(position >= 0 && position < Count)) + { + return null; + } + // TODO проверка позиции + return _places[position]; + } + } +} diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericCollection.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericCollection.cs new file mode 100644 index 0000000..46f2036 --- /dev/null +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericCollection.cs @@ -0,0 +1,146 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ProjectTractor.DrawningObjects; +using ProjectTractor.MovementStrategy; + +namespace ProjectTractor.Generics +{ + /// + /// Параметризованный класс для набора объектов DrawningCar + /// + /// + /// + internal class TractorsGenericCollection + where T : DrawningTractor + where U : IMoveableObject + { + /// + /// Ширина окна прорисовки + /// + private readonly int _pictureWidth; + /// + /// Высота окна прорисовки + /// + private readonly int _pictureHeight; + /// + /// Размер занимаемого объектом места (ширина) + /// + private readonly int _placeSizeWidth = 210; + /// + /// Размер занимаемого объектом места (высота) + /// + private readonly int _placeSizeHeight = 90; + /// + /// Набор объектов + /// + private readonly SetGeneric _collection; + /// + /// Конструктор + /// + /// + /// + public TractorsGenericCollection(int picWidth, int picHeight) + { + int width = picWidth / _placeSizeWidth; + int height = picHeight / _placeSizeHeight; + _pictureWidth = picWidth; + _pictureHeight = picHeight; + _collection = new SetGeneric(width * height); + } + /// + /// Перегрузка оператора сложения + /// + /// + /// + /// + public static bool operator +(TractorsGenericCollection collect, T? + obj) + { + if (obj == null) + { + return false; + } + return collect?._collection.Insert(obj) ?? false; + } + /// + /// Перегрузка оператора вычитания + /// + /// + /// + /// + public static T? operator -(TractorsGenericCollection collect, int pos) + { + T? obj = collect._collection.Get(pos); + if (obj != null) + { + collect._collection.Remove(pos); + } + return obj; + } + /// + /// Получение объекта IMoveableObject + /// + /// + /// + public U? GetU(int pos) + { + return (U?)_collection.Get(pos)?.GetMoveableObject; + } + /// + /// Вывод всего набора объектов + /// + /// + public Bitmap ShowCars() + { + Bitmap bmp = new(_pictureWidth, _pictureHeight); + Graphics gr = Graphics.FromImage(bmp); + DrawBackground(gr); + DrawObjects(gr); + return bmp; + } + /// + /// Метод отрисовки фона + /// + /// + private void DrawBackground(Graphics g) + { + Pen pen = new(Color.Black, 3); + for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++) + { + for (int j = 0; j < _pictureHeight / _placeSizeHeight + + 1; ++j) + {//линия рамзетки места + g.DrawLine(pen, i * _placeSizeWidth, j * + _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * + _placeSizeHeight); + } + g.DrawLine(pen, i * _placeSizeWidth, 0, i * + _placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight); + } + } + /// Метод прорисовки объектов + /// + /// + private void DrawObjects(Graphics g) + { + for (int i = 0; i < _collection.Count; i++) + { + + DrawningTractor? tractor = _collection.Get(i); + if (tractor != null) + { + int inRow = _pictureWidth / _placeSizeWidth; + tractor.SetPosition(_pictureWidth - _placeSizeWidth - (i % inRow * _placeSizeWidth) - _placeSizeHeight / 2 - 8, i / inRow * _placeSizeHeight + 20); + tractor.DrawTransport(g); + } + // TODO получение объекта + // TODO установка позиции + // TODO прорисовка объекта + } + } + } +} + -- 2.25.1 From d3b2e3a0ec7d183ac5a3a549104fc0344bd89b1f Mon Sep 17 00:00:00 2001 From: KirillFirsof <117719052+KirillFirsof@users.noreply.github.com> Date: Thu, 9 Nov 2023 15:06:11 +0400 Subject: [PATCH 2/6] =?UTF-8?q?=D0=A7=D1=83=D1=82=D0=BA=D0=B0=20=D0=B2?= =?UTF-8?q?=D1=80=D0=BE=D0=B4=D0=B5=20=D0=BE=D1=81=D1=82=D0=B0=D0=BB=D0=BE?= =?UTF-8?q?=D1=81=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FormTractorCollection.Designer.cs | 146 --------------- .../FormTractorCollection.cs | 169 +++++++++++++++++- .../RPP_FirstLaba_Tractor/Program.cs | 2 +- .../RPP_FirstLaba_Tractor/SetGeneric.cs | 4 - 4 files changed, 169 insertions(+), 152 deletions(-) delete mode 100644 RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.Designer.cs diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.Designer.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.Designer.cs deleted file mode 100644 index baa946f..0000000 --- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.Designer.cs +++ /dev/null @@ -1,146 +0,0 @@ -namespace ProjectTractor -{ - partial class FormTractorCollection - { - /// - /// 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() - { - this.splitContainer1 = new System.Windows.Forms.SplitContainer(); - this.pictureBox1 = new System.Windows.Forms.PictureBox(); - this.labelPanelInstuments = new System.Windows.Forms.Label(); - this.maskedTextBoxNumber = new System.Windows.Forms.MaskedTextBox(); - this.button1 = new System.Windows.Forms.Button(); - this.button2 = new System.Windows.Forms.Button(); - this.button3 = new System.Windows.Forms.Button(); - ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); - this.splitContainer1.Panel1.SuspendLayout(); - this.splitContainer1.Panel2.SuspendLayout(); - this.splitContainer1.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); - this.SuspendLayout(); - // - // splitContainer1 - // - this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill; - this.splitContainer1.Location = new System.Drawing.Point(0, 0); - this.splitContainer1.Name = "splitContainer1"; - // - // splitContainer1.Panel1 - // - this.splitContainer1.Panel1.Controls.Add(this.pictureBox1); - // - // splitContainer1.Panel2 - // - this.splitContainer1.Panel2.Controls.Add(this.button3); - this.splitContainer1.Panel2.Controls.Add(this.button2); - this.splitContainer1.Panel2.Controls.Add(this.button1); - this.splitContainer1.Panel2.Controls.Add(this.maskedTextBoxNumber); - this.splitContainer1.Panel2.Controls.Add(this.labelPanelInstuments); - this.splitContainer1.Size = new System.Drawing.Size(800, 450); - this.splitContainer1.SplitterDistance = 591; - this.splitContainer1.TabIndex = 0; - // - // pictureBox1 - // - this.pictureBox1.Dock = System.Windows.Forms.DockStyle.Fill; - this.pictureBox1.Location = new System.Drawing.Point(0, 0); - this.pictureBox1.Name = "pictureBox1"; - this.pictureBox1.Size = new System.Drawing.Size(591, 450); - this.pictureBox1.TabIndex = 0; - this.pictureBox1.TabStop = false; - // - // labelPanelInstuments - // - this.labelPanelInstuments.AutoSize = true; - this.labelPanelInstuments.Location = new System.Drawing.Point(8, 9); - this.labelPanelInstuments.Name = "labelPanelInstuments"; - this.labelPanelInstuments.Size = new System.Drawing.Size(103, 20); - this.labelPanelInstuments.TabIndex = 0; - this.labelPanelInstuments.Text = "Инструменты"; - // - // maskedTextBoxNumber - // - this.maskedTextBoxNumber.Location = new System.Drawing.Point(8, 146); - this.maskedTextBoxNumber.Name = "maskedTextBoxNumber"; - this.maskedTextBoxNumber.Size = new System.Drawing.Size(185, 27); - this.maskedTextBoxNumber.TabIndex = 1; - // - // button1 - // - this.button1.Location = new System.Drawing.Point(8, 54); - this.button1.Name = "button1"; - this.button1.Size = new System.Drawing.Size(185, 40); - this.button1.TabIndex = 2; - this.button1.Text = "Добавить трактор"; - this.button1.UseVisualStyleBackColor = true; - // - // button2 - // - this.button2.Location = new System.Drawing.Point(8, 179); - this.button2.Name = "button2"; - this.button2.Size = new System.Drawing.Size(185, 36); - this.button2.TabIndex = 3; - this.button2.Text = "Удалить трактор"; - this.button2.UseVisualStyleBackColor = true; - // - // button3 - // - this.button3.Location = new System.Drawing.Point(8, 376); - this.button3.Name = "button3"; - this.button3.Size = new System.Drawing.Size(185, 42); - this.button3.TabIndex = 4; - this.button3.Text = "Обновить коллекцию"; - this.button3.UseVisualStyleBackColor = true; - // - // FormTractorCollection - // - this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Controls.Add(this.splitContainer1); - this.Name = "FormTractorCollection"; - this.Text = "FormTractorCollection"; - this.splitContainer1.Panel1.ResumeLayout(false); - this.splitContainer1.Panel2.ResumeLayout(false); - this.splitContainer1.Panel2.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit(); - this.splitContainer1.ResumeLayout(false); - ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); - this.ResumeLayout(false); - - } - - #endregion - - private SplitContainer splitContainer1; - private PictureBox pictureBox1; - private Button button3; - private Button button2; - private Button button1; - private MaskedTextBox maskedTextBoxNumber; - private Label labelPanelInstuments; - } -} \ No newline at end of file diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.cs index 6ed2112..74c04d8 100644 --- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.cs +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.cs @@ -7,14 +7,181 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using ProjectTractor.DrawningObjects; +using ProjectTractor.Generics; +using ProjectTractor.MovementStrategy; namespace ProjectTractor { public partial class FormTractorCollection : Form - { + { + + /// + /// Набор объектов + /// + private readonly TractorsGenericCollection _cars; + /// + /// Конструктор + /// public FormTractorCollection() { InitializeComponent(); + _cars = new TractorsGenericCollection(pictureBoxCollection.Width, pictureBoxCollection.Height); } + /// + /// Добавление объекта в набор + /// + /// + /// + private void ButtonAddTractor_Click(object sender, EventArgs e) + { + FormTractor form = new(); + if (form.ShowDialog() == DialogResult.OK) + { + if (_cars + form.SelectedTractor) + { + MessageBox.Show("Объект добавлен"); + pictureBoxCollection.Image = _cars.ShowCars(); + } + else + { + MessageBox.Show("Не удалось добавить объект"); + } + } + } + /// + /// Удаление объекта из набора + /// + /// + /// + private void ButtonRemoveTractor_Click(object sender, EventArgs e) + { + if (MessageBox.Show("Удалить объект?", "Удаление", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) + { + return; + } + int pos = Convert.ToInt32(maskedTextBoxNumber.Text); + if (_cars - pos != null) + { + MessageBox.Show("Объект удален"); + pictureBoxCollection.Image = _cars.ShowCars(); + } + else + { + MessageBox.Show("Не удалось удалить объект"); + } + } + /// + /// Обновление рисунка по набору + /// + /// + /// + private void ButtonRefreshCollection_Click(object sender, EventArgs + e) + { + pictureBoxCollection.Image = _cars.ShowCars(); + } + + private void InitializeComponent() + { + this.panelInstruments = new System.Windows.Forms.Panel(); + this.ButtonRefreshCollection = new System.Windows.Forms.Button(); + this.ButtonRemoveTractor = new System.Windows.Forms.Button(); + this.ButtonAddTractor = new System.Windows.Forms.Button(); + this.maskedTextBoxNumber = new System.Windows.Forms.MaskedTextBox(); + this.labelPanelInstrumets = new System.Windows.Forms.Label(); + this.pictureBoxCollection = new System.Windows.Forms.PictureBox(); + this.panelInstruments.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).BeginInit(); + this.SuspendLayout(); + // + // panelInstruments + // + this.panelInstruments.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.panelInstruments.Controls.Add(this.ButtonRefreshCollection); + this.panelInstruments.Controls.Add(this.ButtonRemoveTractor); + this.panelInstruments.Controls.Add(this.ButtonAddTractor); + this.panelInstruments.Controls.Add(this.maskedTextBoxNumber); + this.panelInstruments.Controls.Add(this.labelPanelInstrumets); + this.panelInstruments.Location = new System.Drawing.Point(657, 7); + this.panelInstruments.Name = "panelInstruments"; + this.panelInstruments.Size = new System.Drawing.Size(228, 422); + this.panelInstruments.TabIndex = 0; + // + // ButtonRefreshCollection + // + this.ButtonRefreshCollection.Location = new System.Drawing.Point(8, 334); + this.ButtonRefreshCollection.Name = "ButtonRefreshCollection"; + this.ButtonRefreshCollection.Size = new System.Drawing.Size(211, 35); + this.ButtonRefreshCollection.TabIndex = 4; + this.ButtonRefreshCollection.Text = "Обновить коллекцию"; + this.ButtonRefreshCollection.UseVisualStyleBackColor = true; + // + // ButtonRemoveTractor + // + this.ButtonRemoveTractor.Location = new System.Drawing.Point(16, 159); + this.ButtonRemoveTractor.Name = "ButtonRemoveTractor"; + this.ButtonRemoveTractor.Size = new System.Drawing.Size(203, 33); + this.ButtonRemoveTractor.TabIndex = 3; + this.ButtonRemoveTractor.Text = "Удалить трактор"; + this.ButtonRemoveTractor.UseVisualStyleBackColor = true; + // + // ButtonAddTractor + // + this.ButtonAddTractor.Location = new System.Drawing.Point(16, 49); + this.ButtonAddTractor.Name = "ButtonAddTractor"; + this.ButtonAddTractor.Size = new System.Drawing.Size(203, 34); + this.ButtonAddTractor.TabIndex = 2; + this.ButtonAddTractor.Text = "Добавить трактор"; + this.ButtonAddTractor.UseVisualStyleBackColor = true; + // + // maskedTextBoxNumber + // + this.maskedTextBoxNumber.Location = new System.Drawing.Point(16, 116); + this.maskedTextBoxNumber.Name = "maskedTextBoxNumber"; + this.maskedTextBoxNumber.Size = new System.Drawing.Size(203, 27); + this.maskedTextBoxNumber.TabIndex = 1; + // + // labelPanelInstrumets + // + this.labelPanelInstrumets.AutoSize = true; + this.labelPanelInstrumets.Location = new System.Drawing.Point(8, 13); + this.labelPanelInstrumets.Name = "labelPanelInstrumets"; + this.labelPanelInstrumets.Size = new System.Drawing.Size(103, 20); + this.labelPanelInstrumets.TabIndex = 0; + this.labelPanelInstrumets.Text = "Инструменты"; + // + // pictureBoxCollection + // + this.pictureBoxCollection.Dock = System.Windows.Forms.DockStyle.Left; + this.pictureBoxCollection.Location = new System.Drawing.Point(0, 0); + this.pictureBoxCollection.Name = "pictureBoxCollection"; + this.pictureBoxCollection.Size = new System.Drawing.Size(651, 437); + this.pictureBoxCollection.TabIndex = 1; + this.pictureBoxCollection.TabStop = false; + // + // FormTractorCollection + // + this.ClientSize = new System.Drawing.Size(893, 437); + this.Controls.Add(this.pictureBoxCollection); + this.Controls.Add(this.panelInstruments); + this.Name = "FormTractorCollection"; + this.panelInstruments.ResumeLayout(false); + this.panelInstruments.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).EndInit(); + this.ResumeLayout(false); + + } + + private Panel panelInstruments; + private Button ButtonRefreshCollection; + private Button ButtonRemoveTractor; + private Button ButtonAddTractor; + private MaskedTextBox maskedTextBoxNumber; + private Label labelPanelInstrumets; + private PictureBox pictureBoxCollection; } } diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/Program.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/Program.cs index 61dbba1..56558ed 100644 --- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/Program.cs +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/Program.cs @@ -11,7 +11,7 @@ namespace ProjectTractor // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormTractor()); + Application.Run(new FormTractorCollection()); } } } \ No newline at end of file diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/SetGeneric.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/SetGeneric.cs index ee4787f..4ce7be5 100644 --- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/SetGeneric.cs +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/SetGeneric.cs @@ -40,7 +40,6 @@ namespace ProjectTractor.Generics { Insert(tractor, 0); } - // TODO вставка в начало набора return true; } /// @@ -80,8 +79,6 @@ namespace ProjectTractor.Generics } _places[position] = null; return true; - // TODO проверка позиции - // TODO удаление объекта из массива, присвоив элементу массива значение null } /// /// Получение объекта из набора по позиции @@ -94,7 +91,6 @@ namespace ProjectTractor.Generics { return null; } - // TODO проверка позиции return _places[position]; } } -- 2.25.1 From 6cb1d0eeea5c0aa97b5a38fb81b325f90c784bf5 Mon Sep 17 00:00:00 2001 From: KirillFirsof <117719052+KirillFirsof@users.noreply.github.com> Date: Thu, 9 Nov 2023 16:30:36 +0400 Subject: [PATCH 3/6] =?UTF-8?q?=D0=92=D1=80=D0=BE=D0=B4=D0=B5=20=D0=B2?= =?UTF-8?q?=D1=81=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RPP_FirstLaba_Tractor/FormTractor.cs | 22 ++- .../FormTractorCollection.cs | 134 ++++++++---------- .../TractorsGenericCollection.cs | 11 +- 3 files changed, 82 insertions(+), 85 deletions(-) diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractor.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractor.cs index 7bd9091..f0055aa 100644 --- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractor.cs +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractor.cs @@ -24,6 +24,8 @@ namespace ProjectTractor /// - /// private DrawningTractor? _drawningTractor; + private Button ButtonSelectTractor; + /// /// /// @@ -175,7 +177,7 @@ namespace ProjectTractor /// /// /// - private void ButtonSelectCar_Click(object sender, EventArgs e) + private void ButtonSelectTractor_Click(object sender, EventArgs e) { SelectedTractor = _drawningTractor; DialogResult = DialogResult.OK; @@ -192,6 +194,7 @@ namespace ProjectTractor this.buttonCreateBulldoserTractor = new System.Windows.Forms.Button(); this.buttonStep = new System.Windows.Forms.Button(); this.comboBoxStrategy = new System.Windows.Forms.ComboBox(); + this.ButtonSelectTractor = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxTractor)).BeginInit(); this.SuspendLayout(); // @@ -299,9 +302,21 @@ namespace ProjectTractor this.comboBoxStrategy.Size = new System.Drawing.Size(151, 28); this.comboBoxStrategy.TabIndex = 8; // + // ButtonSelectTractor + // + this.ButtonSelectTractor.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.ButtonSelectTractor.Location = new System.Drawing.Point(469, 403); + this.ButtonSelectTractor.Name = "ButtonSelectTractor"; + this.ButtonSelectTractor.Size = new System.Drawing.Size(199, 29); + this.ButtonSelectTractor.TabIndex = 9; + this.ButtonSelectTractor.Text = " "; + this.ButtonSelectTractor.UseVisualStyleBackColor = true; + this.ButtonSelectTractor.Click += new System.EventHandler(this.ButtonSelectTractor_Click); + // // FormTractor // this.ClientSize = new System.Drawing.Size(882, 453); + this.Controls.Add(this.ButtonSelectTractor); this.Controls.Add(this.comboBoxStrategy); this.Controls.Add(this.buttonStep); this.Controls.Add(this.buttonCreateBulldoserTractor); @@ -312,7 +327,6 @@ namespace ProjectTractor this.Controls.Add(this.buttonCreateTractor); this.Controls.Add(this.pictureBoxTractor); this.Name = "FormTractor"; - this.Load += new System.EventHandler(this.FormTractor_Load); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxTractor)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -374,9 +388,5 @@ namespace ProjectTractor } } - private void FormTractor_Load(object sender, EventArgs e) - { - - } } } \ No newline at end of file diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.cs index 74c04d8..6b3e486 100644 --- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.cs +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.cs @@ -30,11 +30,7 @@ namespace ProjectTractor _cars = new TractorsGenericCollection(pictureBoxCollection.Width, pictureBoxCollection.Height); } - /// - /// Добавление объекта в набор - /// - /// - /// + private void ButtonAddTractor_Click(object sender, EventArgs e) { FormTractor form = new(); @@ -51,6 +47,7 @@ namespace ProjectTractor } } } + /// /// Удаление объекта из набора /// @@ -64,7 +61,7 @@ namespace ProjectTractor return; } int pos = Convert.ToInt32(maskedTextBoxNumber.Text); - if (_cars - pos != null) + if (_cars - pos) { MessageBox.Show("Объект удален"); pictureBoxCollection.Image = _cars.ShowCars(); @@ -87,101 +84,94 @@ namespace ProjectTractor private void InitializeComponent() { - this.panelInstruments = new System.Windows.Forms.Panel(); + this.pictureBoxCollection = new System.Windows.Forms.PictureBox(); + this.groupBox = new System.Windows.Forms.GroupBox(); this.ButtonRefreshCollection = new System.Windows.Forms.Button(); this.ButtonRemoveTractor = new System.Windows.Forms.Button(); this.ButtonAddTractor = new System.Windows.Forms.Button(); this.maskedTextBoxNumber = new System.Windows.Forms.MaskedTextBox(); - this.labelPanelInstrumets = new System.Windows.Forms.Label(); - this.pictureBoxCollection = new System.Windows.Forms.PictureBox(); - this.panelInstruments.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).BeginInit(); + this.groupBox.SuspendLayout(); this.SuspendLayout(); // - // panelInstruments - // - this.panelInstruments.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.panelInstruments.Controls.Add(this.ButtonRefreshCollection); - this.panelInstruments.Controls.Add(this.ButtonRemoveTractor); - this.panelInstruments.Controls.Add(this.ButtonAddTractor); - this.panelInstruments.Controls.Add(this.maskedTextBoxNumber); - this.panelInstruments.Controls.Add(this.labelPanelInstrumets); - this.panelInstruments.Location = new System.Drawing.Point(657, 7); - this.panelInstruments.Name = "panelInstruments"; - this.panelInstruments.Size = new System.Drawing.Size(228, 422); - this.panelInstruments.TabIndex = 0; - // - // ButtonRefreshCollection - // - this.ButtonRefreshCollection.Location = new System.Drawing.Point(8, 334); - this.ButtonRefreshCollection.Name = "ButtonRefreshCollection"; - this.ButtonRefreshCollection.Size = new System.Drawing.Size(211, 35); - this.ButtonRefreshCollection.TabIndex = 4; - this.ButtonRefreshCollection.Text = "Обновить коллекцию"; - this.ButtonRefreshCollection.UseVisualStyleBackColor = true; - // - // ButtonRemoveTractor - // - this.ButtonRemoveTractor.Location = new System.Drawing.Point(16, 159); - this.ButtonRemoveTractor.Name = "ButtonRemoveTractor"; - this.ButtonRemoveTractor.Size = new System.Drawing.Size(203, 33); - this.ButtonRemoveTractor.TabIndex = 3; - this.ButtonRemoveTractor.Text = "Удалить трактор"; - this.ButtonRemoveTractor.UseVisualStyleBackColor = true; - // - // ButtonAddTractor - // - this.ButtonAddTractor.Location = new System.Drawing.Point(16, 49); - this.ButtonAddTractor.Name = "ButtonAddTractor"; - this.ButtonAddTractor.Size = new System.Drawing.Size(203, 34); - this.ButtonAddTractor.TabIndex = 2; - this.ButtonAddTractor.Text = "Добавить трактор"; - this.ButtonAddTractor.UseVisualStyleBackColor = true; - // - // maskedTextBoxNumber - // - this.maskedTextBoxNumber.Location = new System.Drawing.Point(16, 116); - this.maskedTextBoxNumber.Name = "maskedTextBoxNumber"; - this.maskedTextBoxNumber.Size = new System.Drawing.Size(203, 27); - this.maskedTextBoxNumber.TabIndex = 1; - // - // labelPanelInstrumets - // - this.labelPanelInstrumets.AutoSize = true; - this.labelPanelInstrumets.Location = new System.Drawing.Point(8, 13); - this.labelPanelInstrumets.Name = "labelPanelInstrumets"; - this.labelPanelInstrumets.Size = new System.Drawing.Size(103, 20); - this.labelPanelInstrumets.TabIndex = 0; - this.labelPanelInstrumets.Text = "Инструменты"; - // // pictureBoxCollection // this.pictureBoxCollection.Dock = System.Windows.Forms.DockStyle.Left; this.pictureBoxCollection.Location = new System.Drawing.Point(0, 0); this.pictureBoxCollection.Name = "pictureBoxCollection"; - this.pictureBoxCollection.Size = new System.Drawing.Size(651, 437); + this.pictureBoxCollection.Size = new System.Drawing.Size(620, 437); this.pictureBoxCollection.TabIndex = 1; this.pictureBoxCollection.TabStop = false; // + // groupBox + // + this.groupBox.Controls.Add(this.ButtonRefreshCollection); + this.groupBox.Controls.Add(this.ButtonRemoveTractor); + this.groupBox.Controls.Add(this.ButtonAddTractor); + this.groupBox.Controls.Add(this.maskedTextBoxNumber); + this.groupBox.Location = new System.Drawing.Point(626, 12); + this.groupBox.Name = "groupBox"; + this.groupBox.Size = new System.Drawing.Size(255, 413); + this.groupBox.TabIndex = 2; + this.groupBox.TabStop = false; + this.groupBox.Text = "Инструменты"; + // + // ButtonRefreshCollection + // + this.ButtonRefreshCollection.Location = new System.Drawing.Point(20, 331); + this.ButtonRefreshCollection.Name = "ButtonRefreshCollection"; + this.ButtonRefreshCollection.Size = new System.Drawing.Size(211, 35); + this.ButtonRefreshCollection.TabIndex = 8; + this.ButtonRefreshCollection.Text = "Обновить коллекцию"; + this.ButtonRefreshCollection.UseVisualStyleBackColor = true; + this.ButtonRefreshCollection.Click += new System.EventHandler(this.ButtonRefreshCollection_Click); + // + // ButtonRemoveTractor + // + this.ButtonRemoveTractor.Location = new System.Drawing.Point(28, 156); + this.ButtonRemoveTractor.Name = "ButtonRemoveTractor"; + this.ButtonRemoveTractor.Size = new System.Drawing.Size(203, 33); + this.ButtonRemoveTractor.TabIndex = 7; + this.ButtonRemoveTractor.Text = "Удалить трактор"; + this.ButtonRemoveTractor.UseVisualStyleBackColor = true; + this.ButtonRemoveTractor.Click += new System.EventHandler(this.ButtonRemoveTractor_Click); + // + // ButtonAddTractor + // + this.ButtonAddTractor.Location = new System.Drawing.Point(28, 46); + this.ButtonAddTractor.Name = "ButtonAddTractor"; + this.ButtonAddTractor.Size = new System.Drawing.Size(203, 34); + this.ButtonAddTractor.TabIndex = 6; + this.ButtonAddTractor.Text = "Добавить трактор"; + this.ButtonAddTractor.UseVisualStyleBackColor = true; + this.ButtonAddTractor.Click += new System.EventHandler(this.ButtonAddTractor_Click); + // + // maskedTextBoxNumber + // + this.maskedTextBoxNumber.Location = new System.Drawing.Point(28, 113); + this.maskedTextBoxNumber.Name = "maskedTextBoxNumber"; + this.maskedTextBoxNumber.Size = new System.Drawing.Size(203, 27); + this.maskedTextBoxNumber.TabIndex = 5; + // // FormTractorCollection // this.ClientSize = new System.Drawing.Size(893, 437); + this.Controls.Add(this.groupBox); this.Controls.Add(this.pictureBoxCollection); - this.Controls.Add(this.panelInstruments); this.Name = "FormTractorCollection"; - this.panelInstruments.ResumeLayout(false); - this.panelInstruments.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).EndInit(); + this.groupBox.ResumeLayout(false); + this.groupBox.PerformLayout(); this.ResumeLayout(false); } - private Panel panelInstruments; + private GroupBox groupBox; private Button ButtonRefreshCollection; private Button ButtonRemoveTractor; private Button ButtonAddTractor; private MaskedTextBox maskedTextBoxNumber; - private Label labelPanelInstrumets; private PictureBox pictureBoxCollection; + } } diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericCollection.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericCollection.cs index 46f2036..2bec09d 100644 --- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericCollection.cs +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericCollection.cs @@ -71,14 +71,14 @@ namespace ProjectTractor.Generics /// /// /// - public static T? operator -(TractorsGenericCollection collect, int pos) + public static bool operator -(TractorsGenericCollection collect, int pos) { T? obj = collect._collection.Get(pos); if (obj != null) { collect._collection.Remove(pos); } - return obj; + return true; } /// /// Получение объекта IMoveableObject @@ -132,13 +132,10 @@ namespace ProjectTractor.Generics DrawningTractor? tractor = _collection.Get(i); if (tractor != null) { - int inRow = _pictureWidth / _placeSizeWidth; - tractor.SetPosition(_pictureWidth - _placeSizeWidth - (i % inRow * _placeSizeWidth) - _placeSizeHeight / 2 - 8, i / inRow * _placeSizeHeight + 20); + int countRows = _pictureWidth / _placeSizeWidth; + tractor.SetPosition(_pictureWidth - _placeSizeWidth*2 - (i % countRows * _placeSizeWidth) + 20, _pictureHeight - i / countRows * _placeSizeHeight - 150); tractor.DrawTransport(g); } - // TODO получение объекта - // TODO установка позиции - // TODO прорисовка объекта } } } -- 2.25.1 From bd7a35bdf7462664d47199687f07d5bc077830f3 Mon Sep 17 00:00:00 2001 From: KirillFirsof <117719052+KirillFirsof@users.noreply.github.com> Date: Thu, 9 Nov 2023 19:09:59 +0400 Subject: [PATCH 4/6] =?UTF-8?q?=D0=A2=D0=B5=D0=BF=D0=B5=D1=80=D1=8C=20?= =?UTF-8?q?=D1=82=D0=BE=D1=87=D0=BD=D0=BE=20=D0=B2=D1=81=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RPP_FirstLaba_Tractor/FormTractor.cs | 53 +++++++------------ .../FormTractorCollection.cs | 4 ++ .../RPP_FirstLaba_Tractor/SetGeneric.cs | 2 +- 3 files changed, 24 insertions(+), 35 deletions(-) diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractor.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractor.cs index f0055aa..4c4dd75 100644 --- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractor.cs +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractor.cs @@ -59,31 +59,6 @@ namespace ProjectTractor pictureBoxTractor.Image = bmp; } /// - /// "" - /// - /// - /// - private void ButtonCreateBulldoserTractor_Click(object sender, EventArgs e) - { - Random random = new(); - Color color = Color.FromArgb(random.Next(0, 256), - random.Next(0, 256), random.Next(0, 256)); - //TODO - Color dopColor = Color.FromArgb(random.Next(0, 256), - random.Next(0, 256), random.Next(0, 256)); - //TODO - _drawningTractor = new DrawningBulldoser(random.Next(100, 300), - random.Next(1000, 3000), - color, - dopColor, - Convert.ToBoolean(random.Next(0, 2)), - Convert.ToBoolean(random.Next(0, 2)), - pictureBoxTractor.Width, - pictureBoxTractor.Height); - _drawningTractor.SetPosition(random.Next(10, 100), random.Next(10, 100)); - Draw(); - } - /// /// /// /// @@ -336,19 +311,30 @@ namespace ProjectTractor private void buttonCreateBulldoserTractor_Click(object sender, EventArgs e) { Random random = new(); + Color color = Color.FromArgb(random.Next(0, 256), + random.Next(0, 256), random.Next(0, 256)); + ColorDialog dialogColor = new(); + if (dialogColor.ShowDialog() == DialogResult.OK) + { + color = dialogColor.Color; + } + Color dopColor = Color.FromArgb(random.Next(0, 256), + random.Next(0, 256), random.Next(0, 256)); + ColorDialog dialogDopColor = new(); + if (dialogDopColor.ShowDialog() == DialogResult.OK) + { + dopColor = dialogDopColor.Color; + } _drawningTractor = new DrawningBulldoser(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)), + color, + dopColor, Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), - pictureBoxTractor.Width, pictureBoxTractor.Height); - _drawningTractor.SetPosition(random.Next(10, 100), random.Next(10, - 100)); + pictureBoxTractor.Width, + pictureBoxTractor.Height); + _drawningTractor.SetPosition(random.Next(10, 100), random.Next(10, 100)); Draw(); - } private void buttonStep_Click(object sender, EventArgs e) @@ -387,6 +373,5 @@ namespace ProjectTractor _strategy = null; } } - } } \ No newline at end of file diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.cs index 6b3e486..ce60c1b 100644 --- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.cs +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.cs @@ -158,7 +158,11 @@ namespace ProjectTractor this.ClientSize = new System.Drawing.Size(893, 437); this.Controls.Add(this.groupBox); this.Controls.Add(this.pictureBoxCollection); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; + this.MinimizeBox = false; this.Name = "FormTractorCollection"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "Набор тракторов"; ((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).EndInit(); this.groupBox.ResumeLayout(false); this.groupBox.PerformLayout(); diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/SetGeneric.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/SetGeneric.cs index 4ce7be5..6ca1fd8 100644 --- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/SetGeneric.cs +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/SetGeneric.cs @@ -38,7 +38,7 @@ namespace ProjectTractor.Generics } else { - Insert(tractor, 0); + return Insert(tractor, 0); } return true; } -- 2.25.1 From 65e6415db6005b6f106087c469a3645f0e4e4c6f Mon Sep 17 00:00:00 2001 From: KirillFirsof <117719052+KirillFirsof@users.noreply.github.com> Date: Thu, 9 Nov 2023 21:39:14 +0400 Subject: [PATCH 5/6] =?UTF-8?q?=D0=A1=D0=B5=D0=B9=D1=87=D0=B0=D1=81=20?= =?UTF-8?q?=D1=82=D0=BE=D1=87=D0=BD=D0=BE=20=D0=B2=D1=81=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RPP_FirstLaba_Tractor/DrawningTractor.cs | 2 +- .../RPP_FirstLaba_Tractor/FormTractorCollection.cs | 14 +++++++------- .../RPP_FirstLaba_Tractor/SetGeneric.cs | 2 +- .../TractorsGenericCollection.cs | 4 ++-- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/DrawningTractor.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/DrawningTractor.cs index 578ec20..99015c2 100644 --- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/DrawningTractor.cs +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/DrawningTractor.cs @@ -81,7 +81,7 @@ namespace ProjectTractor.DrawningObjects { } /// - /// Получение объекта IMoveableObject из объекта DrawningCar + /// Получение объекта IMoveableObject из объекта DrawningTractor /// public IMoveableObject GetMoveableObject => new DrawningObjectTractor(this); diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.cs index ce60c1b..b2708e0 100644 --- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.cs +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.cs @@ -20,14 +20,14 @@ namespace ProjectTractor /// Набор объектов /// private readonly TractorsGenericCollection _cars; + DrawningObjectTractor> _tractors; /// /// Конструктор /// public FormTractorCollection() { InitializeComponent(); - _cars = new TractorsGenericCollection(pictureBoxCollection.Width, pictureBoxCollection.Height); } @@ -36,10 +36,10 @@ namespace ProjectTractor FormTractor form = new(); if (form.ShowDialog() == DialogResult.OK) { - if (_cars + form.SelectedTractor) + if (_tractors + form.SelectedTractor) { MessageBox.Show("Объект добавлен"); - pictureBoxCollection.Image = _cars.ShowCars(); + pictureBoxCollection.Image = _tractors.ShowTractors(); } else { @@ -61,10 +61,10 @@ namespace ProjectTractor return; } int pos = Convert.ToInt32(maskedTextBoxNumber.Text); - if (_cars - pos) + if (_tractors - pos) { MessageBox.Show("Объект удален"); - pictureBoxCollection.Image = _cars.ShowCars(); + pictureBoxCollection.Image = _tractors.ShowTractors(); } else { @@ -79,7 +79,7 @@ namespace ProjectTractor private void ButtonRefreshCollection_Click(object sender, EventArgs e) { - pictureBoxCollection.Image = _cars.ShowCars(); + pictureBoxCollection.Image = _tractors.ShowTractors(); } private void InitializeComponent() diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/SetGeneric.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/SetGeneric.cs index 6ca1fd8..2ad9043 100644 --- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/SetGeneric.cs +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/SetGeneric.cs @@ -45,7 +45,7 @@ namespace ProjectTractor.Generics /// /// Добавление объекта в набор на конкретную позицию /// - /// Добавляемый автомобиль + /// Добавляемый трактор /// Позиция /// public bool Insert(T tractor, int position) diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericCollection.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericCollection.cs index 2bec09d..da5fb77 100644 --- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericCollection.cs +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericCollection.cs @@ -9,7 +9,7 @@ using ProjectTractor.MovementStrategy; namespace ProjectTractor.Generics { /// - /// Параметризованный класс для набора объектов DrawningCar + /// Параметризованный класс для набора объектов DrawningTractor /// /// /// @@ -93,7 +93,7 @@ namespace ProjectTractor.Generics /// Вывод всего набора объектов /// /// - public Bitmap ShowCars() + public Bitmap ShowTractors() { Bitmap bmp = new(_pictureWidth, _pictureHeight); Graphics gr = Graphics.FromImage(bmp); -- 2.25.1 From b3f332db43f397fe876d24e36ef50f75d6ffcc17 Mon Sep 17 00:00:00 2001 From: KirillFirsof <117719052+KirillFirsof@users.noreply.github.com> Date: Fri, 10 Nov 2023 11:03:52 +0400 Subject: [PATCH 6/6] =?UTF-8?q?=D1=81=D0=B4=D0=B0=D0=BB=20=D1=82=D1=80?= =?UTF-8?q?=D0=B5=D1=82=D1=8C=D1=8E=20=D0=BB=D0=B0=D0=B1=D1=83,=20=D0=B4?= =?UTF-8?q?=D0=BE=D0=BF=20=D0=B7=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D1=8F=20?= =?UTF-8?q?=D1=83=D0=B4=D0=B0=D0=BB=D0=B8=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FormTractorCollection.cs | 2 +- .../RPP_FirstLaba_Tractor/SetGeneric.cs | 23 ++++++++----------- .../TractorsGenericCollection.cs | 15 ++++++------ 3 files changed, 17 insertions(+), 23 deletions(-) diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.cs index b2708e0..4c32193 100644 --- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.cs +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.cs @@ -36,7 +36,7 @@ namespace ProjectTractor FormTractor form = new(); if (form.ShowDialog() == DialogResult.OK) { - if (_tractors + form.SelectedTractor) + if (_tractors + form.SelectedTractor != -1) { MessageBox.Show("Объект добавлен"); pictureBoxCollection.Image = _tractors.ShowTractors(); diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/SetGeneric.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/SetGeneric.cs index 2ad9043..c0d112a 100644 --- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/SetGeneric.cs +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/SetGeneric.cs @@ -30,17 +30,12 @@ namespace ProjectTractor.Generics /// /// Добавляемый трактор /// - public bool Insert(T tractor) + public int Insert(T tractor) { - if (_places[0] == null) - { - _places[0] = tractor; - } - else - { - return Insert(tractor, 0); - } - return true; + if (_places[Count - 1] != null) + return -1; + + return Insert(tractor, 0); } /// /// Добавление объекта в набор на конкретную позицию @@ -48,23 +43,23 @@ namespace ProjectTractor.Generics /// Добавляемый трактор /// Позиция /// - public bool Insert(T tractor, int position) + public int Insert(T tractor, int position) { if (!(position >= 0 && position < Count)) - return false; + return -1; if (_places[position] != null) { int ind = position; while (ind < Count && _places[ind] != null) ind++; if (ind == Count) - return false; + return -1; for (int i = ind - 1; i >= position; i--) _places[i + 1] = _places[i]; } _places[position] = tractor; - return true; + return position; } /// /// Удаление объекта из набора с конкретной позиции diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericCollection.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericCollection.cs index da5fb77..8a333eb 100644 --- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericCollection.cs +++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericCollection.cs @@ -28,7 +28,7 @@ namespace ProjectTractor.Generics /// /// Размер занимаемого объектом места (ширина) /// - private readonly int _placeSizeWidth = 210; + private readonly int _placeSizeWidth = 200; /// /// Размер занимаемого объектом места (высота) /// @@ -56,14 +56,12 @@ namespace ProjectTractor.Generics /// /// /// - public static bool operator +(TractorsGenericCollection collect, T? - obj) + public static int operator +(TractorsGenericCollection collect, T? obj) { if (obj == null) - { - return false; - } - return collect?._collection.Insert(obj) ?? false; + return -1; + + return collect._collection.Insert(obj); } /// /// Перегрузка оператора вычитания @@ -85,6 +83,7 @@ namespace ProjectTractor.Generics /// /// /// + /// public U? GetU(int pos) { return (U?)_collection.Get(pos)?.GetMoveableObject; @@ -133,7 +132,7 @@ namespace ProjectTractor.Generics if (tractor != null) { int countRows = _pictureWidth / _placeSizeWidth; - tractor.SetPosition(_pictureWidth - _placeSizeWidth*2 - (i % countRows * _placeSizeWidth) + 20, _pictureHeight - i / countRows * _placeSizeHeight - 150); + tractor.SetPosition(_pictureWidth - _placeSizeWidth - (i % countRows * _placeSizeWidth), _pictureHeight - i / countRows * _placeSizeHeight - 150); tractor.DrawTransport(g); } } -- 2.25.1