From 41ab07e21a4bcb53434add5e3172e2fdfa0017d4 Mon Sep 17 00:00:00 2001 From: "safiulova.k" Date: Mon, 23 Oct 2023 22:55:50 +0400 Subject: [PATCH 1/4] =?UTF-8?q?=D1=81=D0=BE=D0=B7=D0=B4=D0=B0=D0=BB=D0=B0?= =?UTF-8?q?=20generic=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Catamaran/CatamaransGenericCollection.cs | 157 ++++++++++++++++++ base/Catamaran/Catamaran/DrawningCatamaran.cs | 5 + base/Catamaran/Catamaran/SetGeneric.cs | 106 ++++++++++++ 3 files changed, 268 insertions(+) create mode 100644 base/Catamaran/Catamaran/CatamaransGenericCollection.cs create mode 100644 base/Catamaran/Catamaran/SetGeneric.cs diff --git a/base/Catamaran/Catamaran/CatamaransGenericCollection.cs b/base/Catamaran/Catamaran/CatamaransGenericCollection.cs new file mode 100644 index 0000000..c75563d --- /dev/null +++ b/base/Catamaran/Catamaran/CatamaransGenericCollection.cs @@ -0,0 +1,157 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using Catamaran.DrawningObjects; +using Catamaran.MovementStrategy; +namespace Catamaran.Generics +{ + /// + /// Параметризованный класс для набора объектов DrawningCatamaran + /// + /// + /// + internal class CatamaransGenericCollection + where T : DrawningCatamaran + where U : IMoveableObject + { + /// + /// Ширина окна прорисовки + /// + private readonly int _pictureWidth; + /// + /// Высота окна прорисовки + /// + private readonly int _pictureHeight; + /// + /// Размер занимаемого объектом места (ширина) + /// + private readonly int _placeSizeWidth = 190; + /// + /// Размер занимаемого объектом места (высота) + /// + private readonly int _placeSizeHeight = 120; + /// + /// Набор объектов + /// + private readonly SetGeneric _collection; + /// + /// Конструктор + /// + /// + /// + public CatamaransGenericCollection(int picWidth, int picHeight) + { + int width = picWidth / _placeSizeWidth; + int height = picHeight / _placeSizeHeight; + _pictureWidth = picWidth; + _pictureHeight = picHeight; + _collection = new SetGeneric(width * height); + } + /// + /// Перегрузка оператора сложения + /// + /// + /// + /// + public static int operator +(CatamaransGenericCollection collect, T? obj) + { + if (obj == null) + { + return -1; + } + return collect._collection.Insert(obj); + } + /// + /// Перегрузка оператора вычитания + /// + /// + /// + /// + public static bool operator -(CatamaransGenericCollection collect, int pos) + { + T? obj = collect._collection.Get(pos); + if (obj != null) + { + return collect._collection.Remove(pos); + } + return false; + } + /// + /// Получение объекта IMoveableObject + /// + /// + /// + public U? GetU(int pos) + { + return (U?)_collection.Get(pos)?.GetMoveableObject; + } + /// + /// Вывод всего набора объектов + /// + /// + public Bitmap ShowCatamarans() + { + 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++) + //{ + // TODO получение объекта + // TODO установка позиции + // TODO прорисовка объекта + T? obj; + int width = _pictureWidth / _placeSizeWidth; + int height = _pictureHeight / _placeSizeHeight; + int diff = 1, currWidth = 0; + for (int i = 0; i < _collection.Count; i++) + { + currWidth++; + if (currWidth > width) + { + diff++; + currWidth = 1; + } + obj = _collection.Get(i); + if (obj != null) + { + obj.SetPosition(i % width * _placeSizeWidth + _placeSizeWidth / 40, + (height - diff) * _placeSizeHeight + _placeSizeHeight / 15); + obj.DrawTransport(g); + } + } + //} + } + } +} diff --git a/base/Catamaran/Catamaran/DrawningCatamaran.cs b/base/Catamaran/Catamaran/DrawningCatamaran.cs index c56fe11..7e75c63 100644 --- a/base/Catamaran/Catamaran/DrawningCatamaran.cs +++ b/base/Catamaran/Catamaran/DrawningCatamaran.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using Catamaran.Entities; +using Catamaran.MovementStrategy; namespace Catamaran.DrawningObjects { @@ -57,6 +58,10 @@ namespace Catamaran.DrawningObjects /// public int GetHeight => _CatamaranHeight; /// + /// Получение объекта IMoveableObject из объекта DrawningCar + /// + public IMoveableObject GetMoveableObject => new DrawningObjectCatamaran(this); + /// /// Конструктор /// /// Скорость diff --git a/base/Catamaran/Catamaran/SetGeneric.cs b/base/Catamaran/Catamaran/SetGeneric.cs new file mode 100644 index 0000000..116b0bc --- /dev/null +++ b/base/Catamaran/Catamaran/SetGeneric.cs @@ -0,0 +1,106 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Catamaran +{ + /// + /// Параметризованный набор объектов + /// + /// + internal class SetGeneric + where T : class + { + /// + /// Массив объектов, которые храним + /// + private readonly T?[] _places; + /// + /// Количество объектов в массиве + /// + public int Count => _places.Length; + /// + /// Конструктор + /// + /// + public SetGeneric(int count) + { + _places = new T?[count]; + } + /// + /// Добавление объекта в набор + /// + /// Добавляемый катамаран + /// + public int Insert(T catamaran) + { + // TODO вставка в начало набора + return Insert(catamaran, 0); + } + /// + /// Добавление объекта в набор на конкретную позицию + /// + /// Добавляемый катамаран + /// Позиция + /// + public int Insert(T catamaran, int position) + { + // TODO проверка позиции + // TODO проверка, что элемент массива по этой позиции пустой, + //если нет, то проверка, что после вставляемого элемента в массиве есть пустой элемент + // сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента + // TODO вставка по позиции + int nullIndex = -1, i; + + if (position < 0 || position >= Count) + return -1; + + for (i = position; i < Count; i++) + { + if (_places[i] == null) + { + nullIndex = i; + break; + } + } + if (nullIndex < 0) + return -1; + + for (i = nullIndex; i > position; i--) + { + _places[i] = _places[i - 1]; + } + + _places[position] = catamaran; + return position; + } + /// + /// Удаление объекта из набора с конкретной позиции + /// + /// + /// + public bool Remove(int position) + { + // TODO проверка позиции + // TODO удаление объекта из массива, присвоив элементу массива значение null + if (position < 0 || position >= Count) { + return false; } + _places[position] = null; + return true; + } + /// + /// Получение объекта из набора по позиции + /// + /// + /// + public T? Get(int position) + { + // TODO проверка позиции + if (position < 0 || position >= Count) + return null; + return _places[position]; + } + } +} \ No newline at end of file -- 2.25.1 From 239d88ff26f4c3e5cd84e1e7ab612a8383115c6f Mon Sep 17 00:00:00 2001 From: "safiulova.k" Date: Tue, 24 Oct 2023 23:08:47 +0400 Subject: [PATCH 2/4] =?UTF-8?q?=D0=BB=D0=B0=D0=B1=D0=B0=203=20=D0=B3=D0=BE?= =?UTF-8?q?=D1=82=D0=BE=D0=B2=D0=B0=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Catamaran/Catamaran/Catamaran.Designer.cs | 38 ++++-- base/Catamaran/Catamaran/Catamaran.cs | 81 ++++++++---- .../Catamaran/CatamaransGenericCollection.cs | 49 ++++--- .../FormCatamaranCollection.Designer.cs | 124 ++++++++++++++++++ .../Catamaran/FormCatamaranCollection.cs | 81 ++++++++++++ .../Catamaran/FormCatamaranCollection.resx | 60 +++++++++ base/Catamaran/Catamaran/Program.cs | 2 +- 7 files changed, 374 insertions(+), 61 deletions(-) create mode 100644 base/Catamaran/Catamaran/FormCatamaranCollection.Designer.cs create mode 100644 base/Catamaran/Catamaran/FormCatamaranCollection.cs create mode 100644 base/Catamaran/Catamaran/FormCatamaranCollection.resx diff --git a/base/Catamaran/Catamaran/Catamaran.Designer.cs b/base/Catamaran/Catamaran/Catamaran.Designer.cs index 213cc04..89919aa 100644 --- a/base/Catamaran/Catamaran/Catamaran.Designer.cs +++ b/base/Catamaran/Catamaran/Catamaran.Designer.cs @@ -35,8 +35,9 @@ this.buttonLeft = new System.Windows.Forms.Button(); this.buttonDown = new System.Windows.Forms.Button(); this.comboBoxStrategy = new System.Windows.Forms.ComboBox(); - this.buttonStep = new System.Windows.Forms.Button(); + this.buttonStrategyStep = new System.Windows.Forms.Button(); this.buttonCreateSailCatamaran = new System.Windows.Forms.Button(); + this.buttonSelectCatamaran = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxCatamaran)).BeginInit(); this.SuspendLayout(); // @@ -116,20 +117,20 @@ this.comboBoxStrategy.Items.AddRange(new object[] { "До центра", "До края"}); - this.comboBoxStrategy.Location = new System.Drawing.Point(688, 12); + this.comboBoxStrategy.Location = new System.Drawing.Point(711, 12); this.comboBoxStrategy.Name = "comboBoxStrategy"; this.comboBoxStrategy.Size = new System.Drawing.Size(151, 23); this.comboBoxStrategy.TabIndex = 7; // - // buttonStep + // buttonStrategyStep // - this.buttonStep.Location = new System.Drawing.Point(770, 41); - this.buttonStep.Name = "buttonStep"; - this.buttonStep.Size = new System.Drawing.Size(75, 23); - this.buttonStep.TabIndex = 7; - this.buttonStep.Text = "Шаг"; - this.buttonStep.UseVisualStyleBackColor = true; - this.buttonStep.Click += new System.EventHandler(this.ButtonStep_Click); + this.buttonStrategyStep.Location = new System.Drawing.Point(787, 41); + this.buttonStrategyStep.Name = "buttonStrategyStep"; + this.buttonStrategyStep.Size = new System.Drawing.Size(75, 23); + this.buttonStrategyStep.TabIndex = 7; + this.buttonStrategyStep.Text = "Шаг"; + this.buttonStrategyStep.UseVisualStyleBackColor = true; + this.buttonStrategyStep.Click += new System.EventHandler(this.buttonStrategyStep_Click); // // buttonCreateSailCatamaran // @@ -142,11 +143,23 @@ this.buttonCreateSailCatamaran.UseVisualStyleBackColor = true; this.buttonCreateSailCatamaran.Click += new System.EventHandler(this.buttonCreateSailCatamaran_Click); // + // buttonSelectCatamaran + // + this.buttonSelectCatamaran.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.buttonSelectCatamaran.Location = new System.Drawing.Point(268, 398); + this.buttonSelectCatamaran.Name = "buttonSelectCatamaran"; + this.buttonSelectCatamaran.Size = new System.Drawing.Size(167, 51); + this.buttonSelectCatamaran.TabIndex = 11; + this.buttonSelectCatamaran.Text = "Выбрать катамаран"; + this.buttonSelectCatamaran.UseVisualStyleBackColor = true; + this.buttonSelectCatamaran.Click += new System.EventHandler(this.buttonSelectCatamaran_Click); + // // FormCatamaran // this.ClientSize = new System.Drawing.Size(884, 461); + this.Controls.Add(this.buttonSelectCatamaran); this.Controls.Add(this.buttonCreateSailCatamaran); - this.Controls.Add(this.buttonStep); + this.Controls.Add(this.buttonStrategyStep); this.Controls.Add(this.comboBoxStrategy); this.Controls.Add(this.buttonDown); this.Controls.Add(this.buttonLeft); @@ -173,7 +186,8 @@ private Button buttonLeft; private Button buttonDown; private ComboBox comboBoxStrategy; - private Button buttonStep; + private Button buttonStrategyStep; private Button buttonCreateSailCatamaran; + private Button buttonSelectCatamaran; } } \ No newline at end of file diff --git a/base/Catamaran/Catamaran/Catamaran.cs b/base/Catamaran/Catamaran/Catamaran.cs index ceda018..5549617 100644 --- a/base/Catamaran/Catamaran/Catamaran.cs +++ b/base/Catamaran/Catamaran/Catamaran.cs @@ -1,4 +1,3 @@ -using Catamaran.Entities; using Catamaran.DrawningObjects; using Catamaran.MovementStrategy; @@ -7,7 +6,6 @@ namespace Catamaran /// /// "" /// - public partial class FormCatamaran : Form { /// @@ -18,7 +16,12 @@ namespace Catamaran /// /// /// - private AbstractStrategy? _abstractStrategy; + private AbstractStrategy? _strategy; + + /// + /// + /// + public DrawningCatamaran? SelectedCatamaran { get; private set; } /// /// @@ -26,8 +29,10 @@ namespace Catamaran public FormCatamaran() { InitializeComponent(); + _strategy = null; + SelectedCatamaran = null; } - + /// /// /// @@ -52,25 +57,48 @@ namespace Catamaran private void buttonCreateSailCatamaran_Click(object sender, EventArgs e) { Random random = new(); - _drawningCatamaran = new DrawningSailCatamaran(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)), + //TODO + 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; + } + //TODO + 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; + } + + _drawningCatamaran = new DrawningSailCatamaran(random.Next(100, 300), + random.Next(1000, 3000), color, dopColor, Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), - Convert.ToBoolean(random.Next(0, 2)), pictureBoxCatamaran.Width, pictureBoxCatamaran.Height); + pictureBoxCatamaran.Width, pictureBoxCatamaran.Height); _drawningCatamaran.SetPosition(random.Next(10, 100), random.Next(10, 100)); Draw(); } /// - /// " " + /// /// /// /// private void buttonCreateCatamaran_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; + } _drawningCatamaran = new DrawningCatamaran(random.Next(100, 300), - random.Next(1000, 3000), - Color.FromArgb(random.Next(0, 256), random.Next(0, 256), - random.Next(0, 256)), + random.Next(1000, 3000), color, pictureBoxCatamaran.Width, pictureBoxCatamaran.Height); _drawningCatamaran.SetPosition(random.Next(10, 100), random.Next(10, 100)); @@ -108,11 +136,11 @@ namespace Catamaran } /// - /// "" + /// /// /// /// - private void ButtonStep_Click(object sender, EventArgs e) + private void buttonStrategyStep_Click(object sender, EventArgs e) { if (_drawningCatamaran == null) { @@ -120,32 +148,41 @@ namespace Catamaran } if (comboBoxStrategy.Enabled) { - _abstractStrategy = comboBoxStrategy.SelectedIndex - switch + _strategy = comboBoxStrategy.SelectedIndex switch { 0 => new MoveToCenter(), 1 => new MoveToBorder(), _ => null, }; - if (_abstractStrategy == null) + if (_strategy == null) { return; } - _abstractStrategy.SetData(new DrawningObjectCatamaran(_drawningCatamaran), pictureBoxCatamaran.Width, - pictureBoxCatamaran.Height); - comboBoxStrategy.Enabled = false; + _strategy.SetData(_drawningCatamaran.GetMoveableObject, + pictureBoxCatamaran.Width, pictureBoxCatamaran.Height); } - if (_abstractStrategy == null) + if (_strategy == null) { return; } - _abstractStrategy.MakeStep(); + comboBoxStrategy.Enabled = false; + _strategy.MakeStep(); Draw(); - if (_abstractStrategy.GetStatus() == Status.Finish) + if (_strategy.GetStatus() == Status.Finish) { comboBoxStrategy.Enabled = true; - _abstractStrategy = null; + _strategy = null; } } + /// + /// + /// + /// + /// + private void buttonSelectCatamaran_Click(object sender, EventArgs e) + { + SelectedCatamaran = _drawningCatamaran; + DialogResult = DialogResult.OK; + } } } diff --git a/base/Catamaran/Catamaran/CatamaransGenericCollection.cs b/base/Catamaran/Catamaran/CatamaransGenericCollection.cs index c75563d..49eb219 100644 --- a/base/Catamaran/Catamaran/CatamaransGenericCollection.cs +++ b/base/Catamaran/Catamaran/CatamaransGenericCollection.cs @@ -28,11 +28,11 @@ namespace Catamaran.Generics /// /// Размер занимаемого объектом места (ширина) /// - private readonly int _placeSizeWidth = 190; + private readonly int _placeSizeWidth = 200; /// /// Размер занимаемого объектом места (высота) /// - private readonly int _placeSizeHeight = 120; + private readonly int _placeSizeHeight = 150; /// /// Набор объектов /// @@ -126,32 +126,29 @@ namespace Catamaran.Generics /// private void DrawObjects(Graphics g) { - //for (int i = 0; i < _collection.Count; i++) - //{ - // TODO получение объекта - // TODO установка позиции - // TODO прорисовка объекта - T? obj; - int width = _pictureWidth / _placeSizeWidth; - int height = _pictureHeight / _placeSizeHeight; - int diff = 1, currWidth = 0; - for (int i = 0; i < _collection.Count; i++) + // TODO получение объекта + // TODO установка позиции + // TODO прорисовка объекта + T? obj; + int width = _pictureWidth / _placeSizeWidth; + int height = _pictureHeight / _placeSizeHeight; + int diff = 1, currWidth = 0; + for (int i = 0; i < _collection.Count; i++) + { + currWidth++; + if (currWidth > width) { - currWidth++; - if (currWidth > width) - { - diff++; - currWidth = 1; - } - obj = _collection.Get(i); - if (obj != null) - { - obj.SetPosition(i % width * _placeSizeWidth + _placeSizeWidth / 40, - (height - diff) * _placeSizeHeight + _placeSizeHeight / 15); - obj.DrawTransport(g); - } + diff++; + currWidth = 1; } - //} + obj = _collection.Get(i); + if (obj != null) + { + obj.SetPosition(i % width * _placeSizeWidth + _placeSizeWidth / 40, + (height - diff) * _placeSizeHeight + _placeSizeHeight / 15); + obj.DrawTransport(g); + } + } } } } diff --git a/base/Catamaran/Catamaran/FormCatamaranCollection.Designer.cs b/base/Catamaran/Catamaran/FormCatamaranCollection.Designer.cs new file mode 100644 index 0000000..c133790 --- /dev/null +++ b/base/Catamaran/Catamaran/FormCatamaranCollection.Designer.cs @@ -0,0 +1,124 @@ +namespace Catamaran +{ + partial class FormCatamaranCollection + { + /// + /// 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.pictureBoxCollection = new System.Windows.Forms.PictureBox(); + this.groupBoxTools = new System.Windows.Forms.GroupBox(); + this.maskedTextBoxNumber = new System.Windows.Forms.MaskedTextBox(); + this.ButtonRefreshCollection = new System.Windows.Forms.Button(); + this.ButtonRemoveCatamaran = new System.Windows.Forms.Button(); + this.ButtonAddCatamaran = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).BeginInit(); + this.groupBoxTools.SuspendLayout(); + this.SuspendLayout(); + // + // pictureBoxCollection + // + this.pictureBoxCollection.Location = new System.Drawing.Point(0, 1); + this.pictureBoxCollection.Name = "pictureBoxCollection"; + this.pictureBoxCollection.Size = new System.Drawing.Size(741, 459); + this.pictureBoxCollection.TabIndex = 0; + this.pictureBoxCollection.TabStop = false; + // + // groupBoxTools + // + this.groupBoxTools.Controls.Add(this.maskedTextBoxNumber); + this.groupBoxTools.Controls.Add(this.ButtonRefreshCollection); + this.groupBoxTools.Controls.Add(this.ButtonRemoveCatamaran); + this.groupBoxTools.Controls.Add(this.ButtonAddCatamaran); + this.groupBoxTools.Location = new System.Drawing.Point(739, 1); + this.groupBoxTools.Name = "groupBoxTools"; + this.groupBoxTools.Size = new System.Drawing.Size(147, 460); + this.groupBoxTools.TabIndex = 1; + this.groupBoxTools.TabStop = false; + this.groupBoxTools.Text = "Инструменты"; + // + // maskedTextBoxNumber + // + this.maskedTextBoxNumber.Location = new System.Drawing.Point(0, 108); + this.maskedTextBoxNumber.Name = "maskedTextBoxNumber"; + this.maskedTextBoxNumber.Size = new System.Drawing.Size(141, 23); + this.maskedTextBoxNumber.TabIndex = 3; + // + // ButtonRefreshCollection + // + this.ButtonRefreshCollection.Location = new System.Drawing.Point(0, 211); + this.ButtonRefreshCollection.Name = "ButtonRefreshCollection"; + this.ButtonRefreshCollection.Size = new System.Drawing.Size(141, 34); + this.ButtonRefreshCollection.TabIndex = 2; + this.ButtonRefreshCollection.Text = "Обновить коллекцию"; + this.ButtonRefreshCollection.UseVisualStyleBackColor = true; + this.ButtonRefreshCollection.Click += new System.EventHandler(this.ButtonRefreshCollection_Click); + // + // ButtonRemoveCatamaran + // + this.ButtonRemoveCatamaran.Location = new System.Drawing.Point(0, 157); + this.ButtonRemoveCatamaran.Name = "ButtonRemoveCatamaran"; + this.ButtonRemoveCatamaran.Size = new System.Drawing.Size(141, 34); + this.ButtonRemoveCatamaran.TabIndex = 1; + this.ButtonRemoveCatamaran.Text = "Удалить катамаран"; + this.ButtonRemoveCatamaran.UseVisualStyleBackColor = true; + this.ButtonRemoveCatamaran.Click += new System.EventHandler(this.ButtonRemoveCatamaran_Click); + // + // ButtonAddCatamaran + // + this.ButtonAddCatamaran.Location = new System.Drawing.Point(0, 22); + this.ButtonAddCatamaran.Name = "ButtonAddCatamaran"; + this.ButtonAddCatamaran.Size = new System.Drawing.Size(141, 34); + this.ButtonAddCatamaran.TabIndex = 0; + this.ButtonAddCatamaran.Text = "Добавить катамаран"; + this.ButtonAddCatamaran.UseVisualStyleBackColor = true; + this.ButtonAddCatamaran.Click += new System.EventHandler(this.ButtonAddCatamaran_Click); + // + // FormCatamaranCollection + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(884, 461); + this.Controls.Add(this.groupBoxTools); + this.Controls.Add(this.pictureBoxCollection); + this.Name = "FormCatamaranCollection"; + this.Text = "FormCatamaranCollection"; + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).EndInit(); + this.groupBoxTools.ResumeLayout(false); + this.groupBoxTools.PerformLayout(); + this.ResumeLayout(false); + + } + + #endregion + + private PictureBox pictureBoxCollection; + private GroupBox groupBoxTools; + private Button ButtonAddCatamaran; + private Button ButtonRefreshCollection; + private Button ButtonRemoveCatamaran; + private MaskedTextBox maskedTextBoxNumber; + } +} \ No newline at end of file diff --git a/base/Catamaran/Catamaran/FormCatamaranCollection.cs b/base/Catamaran/Catamaran/FormCatamaranCollection.cs new file mode 100644 index 0000000..3db931c --- /dev/null +++ b/base/Catamaran/Catamaran/FormCatamaranCollection.cs @@ -0,0 +1,81 @@ +using Catamaran.DrawningObjects; +using Catamaran.Generics; +using Catamaran.MovementStrategy; + +namespace Catamaran +{ + /// + /// Форма для работы с набором объектов класса DrawningCatamaran + /// + public partial class FormCatamaranCollection : Form + { + /// + /// Набор объектов + /// + private readonly CatamaransGenericCollection _catamarans; + /// + /// Конструктор + /// + public FormCatamaranCollection() + { + InitializeComponent(); + _catamarans = new CatamaransGenericCollection(pictureBoxCollection.Width, pictureBoxCollection.Height); + } + /// + /// Добавление объекта в набор + /// + /// + /// + private void ButtonAddCatamaran_Click(object sender, EventArgs e) + { + FormCatamaran form = new(); + if (form.ShowDialog() == DialogResult.OK) + { + if (_catamarans + form.SelectedCatamaran != -1) + { + MessageBox.Show("Объект добавлен"); + pictureBoxCollection.Image = _catamarans.ShowCatamarans(); + } + else + { + MessageBox.Show("Не удалось добавить объект"); + } + } + } + /// + /// Удаление объекта из набора + /// + /// + /// + private void ButtonRemoveCatamaran_Click(object sender, EventArgs e) + { + if (MessageBox.Show("Удалить объект?", "Удаление", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) + { + return; + } + int pos = Convert.ToInt32(maskedTextBoxNumber.Text); + if (_catamarans - pos != null) + { + MessageBox.Show("Объект удален"); + pictureBoxCollection.Image = _catamarans.ShowCatamarans(); + } + else + { + MessageBox.Show("Не удалось удалить объект"); + } + } + /// + /// Обновление рисунка по набору + /// + /// + /// + private void ButtonRefreshCollection_Click(object sender, EventArgs + e) + { + pictureBoxCollection.Image = _catamarans.ShowCatamarans(); + } + } +} diff --git a/base/Catamaran/Catamaran/FormCatamaranCollection.resx b/base/Catamaran/Catamaran/FormCatamaranCollection.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/base/Catamaran/Catamaran/FormCatamaranCollection.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/base/Catamaran/Catamaran/Program.cs b/base/Catamaran/Catamaran/Program.cs index cad1371..290fdf6 100644 --- a/base/Catamaran/Catamaran/Program.cs +++ b/base/Catamaran/Catamaran/Program.cs @@ -11,7 +11,7 @@ namespace Catamaran // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormCatamaran()); + Application.Run(new FormCatamaranCollection()); } } } \ No newline at end of file -- 2.25.1 From f9da881a3cf0fbd4d132f626e7bd47ebb1c0cb31 Mon Sep 17 00:00:00 2001 From: "safiulova.k" Date: Wed, 25 Oct 2023 07:50:15 +0400 Subject: [PATCH 3/4] =?UTF-8?q?=D0=BB=D0=B0=D0=B1=D0=B0=203=20=D0=B3=D0=BE?= =?UTF-8?q?=D1=82=D0=BE=D0=B2=D0=B0=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- base/Catamaran/Catamaran/Catamaran.Designer.cs | 1 - base/Catamaran/Catamaran/CatamaransGenericCollection.cs | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/base/Catamaran/Catamaran/Catamaran.Designer.cs b/base/Catamaran/Catamaran/Catamaran.Designer.cs index 89919aa..bef1c4d 100644 --- a/base/Catamaran/Catamaran/Catamaran.Designer.cs +++ b/base/Catamaran/Catamaran/Catamaran.Designer.cs @@ -178,7 +178,6 @@ #endregion - private Button buttonCreateCatamaran; private PictureBox pictureBoxCatamaran; private Button buttonUp; diff --git a/base/Catamaran/Catamaran/CatamaransGenericCollection.cs b/base/Catamaran/Catamaran/CatamaransGenericCollection.cs index 49eb219..d86bc47 100644 --- a/base/Catamaran/Catamaran/CatamaransGenericCollection.cs +++ b/base/Catamaran/Catamaran/CatamaransGenericCollection.cs @@ -151,4 +151,4 @@ namespace Catamaran.Generics } } } -} +} \ No newline at end of file -- 2.25.1 From 238c21da970c74494912794506d094f9d9f825a8 Mon Sep 17 00:00:00 2001 From: "safiulova.k" Date: Wed, 25 Oct 2023 08:00:17 +0400 Subject: [PATCH 4/4] =?UTF-8?q?=D0=BB=D0=B0=D0=B1=D0=B0=203=20=D1=82=D0=BE?= =?UTF-8?q?=D1=87=D0=BD=D0=BE=20=D0=B3=D0=BE=D1=82=D0=BE=D0=B2=D0=B0=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- base/Catamaran/Catamaran/SetGeneric.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base/Catamaran/Catamaran/SetGeneric.cs b/base/Catamaran/Catamaran/SetGeneric.cs index 116b0bc..4c1a61a 100644 --- a/base/Catamaran/Catamaran/SetGeneric.cs +++ b/base/Catamaran/Catamaran/SetGeneric.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace Catamaran +namespace Catamaran.Generics { /// /// Параметризованный набор объектов -- 2.25.1