From 738f84f43a80f6fb224040c5654c28e50cdeecbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=BE=D0=BB=D0=B8=D0=BD=D0=B0=20=D0=A7=D1=83=D0=B1?= =?UTF-8?q?=D1=8B=D0=BA=D0=B8=D0=BD=D0=B0?= Date: Sat, 21 Oct 2023 23:52:42 +0400 Subject: [PATCH 1/6] =?UTF-8?q?=D0=A1=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 --- Sailboat/Sailboat/BoatsGenericCollection.cs | 143 ++++++++++++++++++++ Sailboat/Sailboat/DrawingBoat.cs | 2 + Sailboat/Sailboat/SetGeneric.cs | 76 +++++++++++ 3 files changed, 221 insertions(+) create mode 100644 Sailboat/Sailboat/BoatsGenericCollection.cs create mode 100644 Sailboat/Sailboat/SetGeneric.cs diff --git a/Sailboat/Sailboat/BoatsGenericCollection.cs b/Sailboat/Sailboat/BoatsGenericCollection.cs new file mode 100644 index 0000000..397920c --- /dev/null +++ b/Sailboat/Sailboat/BoatsGenericCollection.cs @@ -0,0 +1,143 @@ +using Sailboat.DrawingObjects; +using Sailboat.MovementStrategy; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using Sailboat.DrawingObjects; +using Sailboat.MovementStrategy; + +namespace Sailboat.Generics +{ + /// + /// Параметризованный класс для набора объектов DrawingBoat + /// + /// + /// + internal class BoatsGenericCollection + where T : DrawingBoat + where U : IMoveableObject + { + /// + /// Ширина окна прорисовки + /// + private readonly int _pictureWidth; + /// + /// Высота окна прорисовки + /// + private readonly int _pictureHeight; + /// + /// Размер занимаемого объектом места (ширина) + /// + private readonly int _placeSizeWidth = 160; + /// + /// Размер занимаемого объектом места (высота) + /// + private readonly int _placeSizeHeight = 160; + /// + /// Набор объектов + /// + private readonly SetGeneric _collection; + /// + /// Конструктор + /// + /// + /// + public BoatsGenericCollection(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 +(BoatsGenericCollection collect, T? + obj) + { + if (obj == null) + { + return false; + } + return collect?._collection.Insert(obj) ?? false; + } + /// + /// Перегрузка оператора вычитания + /// + /// + /// + /// + public static T? operator -(BoatsGenericCollection 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 ShowBoats() + { + 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 прорисовка объекта + } + } + + } +} diff --git a/Sailboat/Sailboat/DrawingBoat.cs b/Sailboat/Sailboat/DrawingBoat.cs index 882d8f4..a0b5c12 100644 --- a/Sailboat/Sailboat/DrawingBoat.cs +++ b/Sailboat/Sailboat/DrawingBoat.cs @@ -5,6 +5,7 @@ using System.Text; using System.Threading.Tasks; using Sailboat.Entities; +using Sailboat.MovementStrategy; namespace Sailboat.DrawingObjects { @@ -21,6 +22,7 @@ namespace Sailboat.DrawingObjects public int GetPosY => _startPosY; public int GetWidth => _boatWidth; public int GetHeight => _boatHeight; + public IMoveableObject GetMoveableObject => new DrawingObjectBoat(this); public DrawingBoat(int speed, double weight, Color bodyColor, int width, int height) { if (width < _boatWidth || height < _boatHeight) diff --git a/Sailboat/Sailboat/SetGeneric.cs b/Sailboat/Sailboat/SetGeneric.cs new file mode 100644 index 0000000..c754be9 --- /dev/null +++ b/Sailboat/Sailboat/SetGeneric.cs @@ -0,0 +1,76 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Sailboat.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 boat) + { + // TODO вставка в начало набора + return true; + } + /// + /// Добавление объекта в набор на конкретную позицию + /// + /// Добавляемая лодка + /// Позиция + /// + public bool Insert(T boat, int position) + { + // TODO проверка позиции + // TODO проверка, что элемент массива по этой позиции пустой, если нет, то + // проверка, что после вставляемого элемента массиве есть пустой элемент + // сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента + // TODO вставка по позиции + _places[position] = boat; + return true; + } + /// + /// Удаление объекта из набора с конкретной позиции + /// + /// + /// + public bool Remove(int position) + { + // TODO проверка позиции + // TODO удаление объекта из массива, присвоив элементу массива значение null + return true; + } + /// + /// Получение объекта из набора по позиции + /// + /// + /// + public T? Get(int position) + { + // TODO проверка позиции + return _places[position]; + } + + } +} -- 2.25.1 From fe3e0c632fd1998959834f59c23ab108dfd8e94f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=BE=D0=BB=D0=B8=D0=BD=D0=B0=20=D0=A7=D1=83=D0=B1?= =?UTF-8?q?=D1=8B=D0=BA=D0=B8=D0=BD=D0=B0?= Date: Tue, 24 Oct 2023 20:34:16 +0400 Subject: [PATCH 2/6] =?UTF-8?q?=D0=BF=D0=BE=D1=87=D1=82=D0=B8=20=D0=B3?= =?UTF-8?q?=D0=BE=D1=82=D0=BE=D0=B2=D0=B0=D1=8F=20=D0=BB=D0=B0=D0=B1=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sailboat/Sailboat/BoatsGenericCollection.cs | 21 +-- .../Sailboat/FormBoatCollection.Designer.cs | 125 ++++++++++++++++++ Sailboat/Sailboat/FormBoatCollection.cs | 68 ++++++++++ Sailboat/Sailboat/FormBoatCollection.resx | 60 +++++++++ Sailboat/Sailboat/FormSailboat.Designer.cs | 14 ++ Sailboat/Sailboat/FormSailboat.cs | 43 +++++- Sailboat/Sailboat/Program.cs | 2 +- Sailboat/Sailboat/SetGeneric.cs | 53 ++++++-- 8 files changed, 358 insertions(+), 28 deletions(-) create mode 100644 Sailboat/Sailboat/FormBoatCollection.Designer.cs create mode 100644 Sailboat/Sailboat/FormBoatCollection.cs create mode 100644 Sailboat/Sailboat/FormBoatCollection.resx diff --git a/Sailboat/Sailboat/BoatsGenericCollection.cs b/Sailboat/Sailboat/BoatsGenericCollection.cs index 397920c..3f15e67 100644 --- a/Sailboat/Sailboat/BoatsGenericCollection.cs +++ b/Sailboat/Sailboat/BoatsGenericCollection.cs @@ -31,11 +31,11 @@ namespace Sailboat.Generics /// /// Размер занимаемого объектом места (ширина) /// - private readonly int _placeSizeWidth = 160; + private readonly int _placeSizeWidth = 180; /// /// Размер занимаемого объектом места (высота) /// - private readonly int _placeSizeHeight = 160; + private readonly int _placeSizeHeight = 180; /// /// Набор объектов /// @@ -59,14 +59,14 @@ namespace Sailboat.Generics /// /// /// - public static bool operator +(BoatsGenericCollection collect, T? + public static int operator +(BoatsGenericCollection collect, T? obj) { if (obj == null) { - return false; + return -1; } - return collect?._collection.Insert(obj) ?? false; + return collect._collection.Insert(obj); } /// /// Перегрузка оператора вычитания @@ -133,9 +133,14 @@ namespace Sailboat.Generics { for (int i = 0; i < _collection.Count; i++) { - // TODO получение объекта - // TODO установка позиции - // TODO прорисовка объекта + DrawingBoat boat = _collection.Get(i); + + if (boat != null) + { + int inRow = _pictureWidth / _placeSizeWidth; + boat.SetPosition((inRow - 1 - (i % inRow)) * _placeSizeWidth, i / inRow * _placeSizeHeight); + boat.DrawTransport(g); + } } } diff --git a/Sailboat/Sailboat/FormBoatCollection.Designer.cs b/Sailboat/Sailboat/FormBoatCollection.Designer.cs new file mode 100644 index 0000000..521443f --- /dev/null +++ b/Sailboat/Sailboat/FormBoatCollection.Designer.cs @@ -0,0 +1,125 @@ +namespace Sailboat +{ + partial class FormBoatCollection + { + /// + /// 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.panelTools = new System.Windows.Forms.Panel(); + this.maskedTextBoxNumber = new System.Windows.Forms.MaskedTextBox(); + this.buttonRefreshCollection = new System.Windows.Forms.Button(); + this.buttonRemoveBoat = new System.Windows.Forms.Button(); + this.buttonAddBoat = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).BeginInit(); + this.panelTools.SuspendLayout(); + this.SuspendLayout(); + // + // pictureBoxCollection + // + this.pictureBoxCollection.Location = new System.Drawing.Point(0, 0); + this.pictureBoxCollection.Name = "pictureBoxCollection"; + this.pictureBoxCollection.Size = new System.Drawing.Size(700, 450); + this.pictureBoxCollection.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; + this.pictureBoxCollection.TabIndex = 0; + this.pictureBoxCollection.TabStop = false; + // + // panelTools + // + this.panelTools.BackColor = System.Drawing.SystemColors.ScrollBar; + this.panelTools.Controls.Add(this.maskedTextBoxNumber); + this.panelTools.Controls.Add(this.buttonRefreshCollection); + this.panelTools.Controls.Add(this.buttonRemoveBoat); + this.panelTools.Controls.Add(this.buttonAddBoat); + this.panelTools.Location = new System.Drawing.Point(707, 12); + this.panelTools.Name = "panelTools"; + this.panelTools.Size = new System.Drawing.Size(209, 426); + this.panelTools.TabIndex = 1; + // + // maskedTextBoxNumber + // + this.maskedTextBoxNumber.Location = new System.Drawing.Point(40, 87); + this.maskedTextBoxNumber.Name = "maskedTextBoxNumber"; + this.maskedTextBoxNumber.Size = new System.Drawing.Size(125, 27); + this.maskedTextBoxNumber.TabIndex = 3; + // + // buttonRefreshCollection + // + this.buttonRefreshCollection.Location = new System.Drawing.Point(16, 210); + this.buttonRefreshCollection.Name = "buttonRefreshCollection"; + this.buttonRefreshCollection.Size = new System.Drawing.Size(180, 34); + this.buttonRefreshCollection.TabIndex = 2; + this.buttonRefreshCollection.Text = "Обновить коллекцию"; + this.buttonRefreshCollection.UseVisualStyleBackColor = true; + this.buttonRefreshCollection.Click += new System.EventHandler(this.buttonRefreshCollection_Click); + // + // buttonRemoveBoat + // + this.buttonRemoveBoat.Location = new System.Drawing.Point(16, 159); + this.buttonRemoveBoat.Name = "buttonRemoveBoat"; + this.buttonRemoveBoat.Size = new System.Drawing.Size(180, 34); + this.buttonRemoveBoat.TabIndex = 1; + this.buttonRemoveBoat.Text = "Удалить лодку"; + this.buttonRemoveBoat.UseVisualStyleBackColor = true; + this.buttonRemoveBoat.Click += new System.EventHandler(this.buttonRemoveBoat_Click); + // + // buttonAddBoat + // + this.buttonAddBoat.Location = new System.Drawing.Point(16, 14); + this.buttonAddBoat.Name = "buttonAddBoat"; + this.buttonAddBoat.Size = new System.Drawing.Size(180, 34); + this.buttonAddBoat.TabIndex = 0; + this.buttonAddBoat.Text = "Добавить лодку"; + this.buttonAddBoat.UseVisualStyleBackColor = true; + this.buttonAddBoat.Click += new System.EventHandler(this.buttonAddBoat_Click); + // + // FormBoatCollection + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(929, 450); + this.Controls.Add(this.panelTools); + this.Controls.Add(this.pictureBoxCollection); + this.Name = "FormBoatCollection"; + this.Text = "FormBoatCollection"; + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).EndInit(); + this.panelTools.ResumeLayout(false); + this.panelTools.PerformLayout(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private PictureBox pictureBoxCollection; + private Panel panelTools; + private Button buttonRefreshCollection; + private Button buttonRemoveBoat; + private Button buttonAddBoat; + private MaskedTextBox maskedTextBoxNumber; + } +} \ No newline at end of file diff --git a/Sailboat/Sailboat/FormBoatCollection.cs b/Sailboat/Sailboat/FormBoatCollection.cs new file mode 100644 index 0000000..30dd6af --- /dev/null +++ b/Sailboat/Sailboat/FormBoatCollection.cs @@ -0,0 +1,68 @@ +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; + +using Sailboat.DrawingObjects; +using Sailboat.Generics; +using Sailboat.MovementStrategy; + + +namespace Sailboat +{ + public partial class FormBoatCollection : Form + { + private readonly BoatsGenericCollection _boats; + public FormBoatCollection() + { + InitializeComponent(); + _boats = new BoatsGenericCollection(pictureBoxCollection.Width, pictureBoxCollection.Height); + } + + private void buttonAddBoat_Click(object sender, EventArgs e) + { + FormSailboat form = new(); + if (form.ShowDialog() == DialogResult.OK) + { + if (_boats + form.SelectedBoat != -1) + { + MessageBox.Show("Объект добавлен"); + pictureBoxCollection.Image = _boats.ShowBoats(); + } + else + { + MessageBox.Show("Не удалось добавить объект"); + } + } + } + + private void buttonRemoveBoat_Click(object sender, EventArgs e) + { + if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) + { + return; + } + int pos = Convert.ToInt32(maskedTextBoxNumber.Text); + if (_boats - pos != null) + { + MessageBox.Show("Объект удален"); + pictureBoxCollection.Image = _boats.ShowBoats(); + } + else + { + MessageBox.Show("Не удалось удалить объект"); + } + + } + + private void buttonRefreshCollection_Click(object sender, EventArgs e) + { + pictureBoxCollection.Image = _boats.ShowBoats(); + } + } +} diff --git a/Sailboat/Sailboat/FormBoatCollection.resx b/Sailboat/Sailboat/FormBoatCollection.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Sailboat/Sailboat/FormBoatCollection.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/Sailboat/Sailboat/FormSailboat.Designer.cs b/Sailboat/Sailboat/FormSailboat.Designer.cs index 7c24302..e36659f 100644 --- a/Sailboat/Sailboat/FormSailboat.Designer.cs +++ b/Sailboat/Sailboat/FormSailboat.Designer.cs @@ -38,6 +38,7 @@ this.buttonCreateSailboat = new System.Windows.Forms.Button(); this.comboBoxStrategy = new System.Windows.Forms.ComboBox(); this.buttonStep = new System.Windows.Forms.Button(); + this.buttonSelectBoat = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxSailboat)).BeginInit(); this.SuspendLayout(); // @@ -144,11 +145,23 @@ this.buttonStep.UseVisualStyleBackColor = true; this.buttonStep.Click += new System.EventHandler(this.buttonStep_Click); // + // buttonSelectBoat + // + this.buttonSelectBoat.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.buttonSelectBoat.Location = new System.Drawing.Point(688, 97); + this.buttonSelectBoat.Name = "buttonSelectBoat"; + this.buttonSelectBoat.Size = new System.Drawing.Size(149, 33); + this.buttonSelectBoat.TabIndex = 9; + this.buttonSelectBoat.Text = "Выбрать лодку"; + this.buttonSelectBoat.UseVisualStyleBackColor = true; + this.buttonSelectBoat.Click += new System.EventHandler(this.buttonSelectBoat_Click); + // // FormSailboat // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(882, 453); + this.Controls.Add(this.buttonSelectBoat); this.Controls.Add(this.buttonStep); this.Controls.Add(this.comboBoxStrategy); this.Controls.Add(this.buttonCreateSailboat); @@ -178,5 +191,6 @@ private Button buttonCreateSailboat; private ComboBox comboBoxStrategy; private Button buttonStep; + private Button buttonSelectBoat; } } \ No newline at end of file diff --git a/Sailboat/Sailboat/FormSailboat.cs b/Sailboat/Sailboat/FormSailboat.cs index e6d4d05..edbfb8a 100644 --- a/Sailboat/Sailboat/FormSailboat.cs +++ b/Sailboat/Sailboat/FormSailboat.cs @@ -8,9 +8,12 @@ namespace Sailboat { private DrawingBoat? _drawingBoat; private AbstractStrategy? _abstractStrategy; + public DrawingBoat? SelectedBoat { get; private set; } public FormSailboat() { InitializeComponent(); + _abstractStrategy = null; + SelectedBoat = null; } private void Draw() { @@ -27,17 +30,38 @@ namespace Sailboat private void buttonCreateBoat_Click(object sender, EventArgs e) { Random random = new(); - _drawingBoat = new DrawingBoat(random.Next(100, 300), random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), pictureBoxSailboat.Width, pictureBoxSailboat.Height); - _drawingBoat.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)); + ColorDialog dialog = new(); + if (dialog.ShowDialog() == DialogResult.OK) + { + color = dialog.Color; + } + _drawingBoat = new DrawingBoat(random.Next(100, 300), random.Next(1000, 3000), color, pictureBoxSailboat.Width, pictureBoxSailboat.Height); + _drawingBoat.SetPosition(random.Next(10, 100), random.Next(10, 100)); Draw(); } private void buttonCreateSailboat_Click(object sender, EventArgs e) { Random random = new(); - _drawingBoat = new DrawingSailboat(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 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; + } + + Color dopColor = Color.FromArgb(random.Next(0, 256), + random.Next(0, 256), random.Next(0, 256)); + ColorDialog dialogAddColor = new(); + if (dialogAddColor.ShowDialog() == DialogResult.OK) + { + dopColor = dialogAddColor.Color; + } + + _drawingBoat = new DrawingSailboat(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)), pictureBoxSailboat.Width, pictureBoxSailboat.Height); + pictureBoxSailboat.Width, pictureBoxSailboat.Height); _drawingBoat.SetPosition(random.Next(10, 100), random.Next(10, 100)); Draw(); } @@ -84,7 +108,7 @@ namespace Sailboat { return; } - _abstractStrategy.SetData(new DrawingObjectBoat(_drawingBoat), pictureBoxSailboat.Width, + _abstractStrategy.SetData(_drawingBoat.GetMoveableObject, pictureBoxSailboat.Width, pictureBoxSailboat.Height); comboBoxStrategy.Enabled = false; } @@ -92,6 +116,7 @@ namespace Sailboat { return; } + comboBoxStrategy.Enabled = false; _abstractStrategy.MakeStep(); Draw(); if (_abstractStrategy.GetStatus() == Status.Finish) @@ -100,5 +125,11 @@ namespace Sailboat _abstractStrategy = null; } } + + private void buttonSelectBoat_Click(object sender, EventArgs e) + { + SelectedBoat = _drawingBoat; + DialogResult = DialogResult.OK; + } } } \ No newline at end of file diff --git a/Sailboat/Sailboat/Program.cs b/Sailboat/Sailboat/Program.cs index 89c8af2..fac24ad 100644 --- a/Sailboat/Sailboat/Program.cs +++ b/Sailboat/Sailboat/Program.cs @@ -11,7 +11,7 @@ namespace Sailboat // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormSailboat()); + Application.Run(new FormBoatCollection()); } } } \ No newline at end of file diff --git a/Sailboat/Sailboat/SetGeneric.cs b/Sailboat/Sailboat/SetGeneric.cs index c754be9..04a3078 100644 --- a/Sailboat/Sailboat/SetGeneric.cs +++ b/Sailboat/Sailboat/SetGeneric.cs @@ -29,10 +29,9 @@ namespace Sailboat.Generics /// /// Добавляемая лодка /// - public bool Insert(T boat) + public int Insert(T boat) { - // TODO вставка в начало набора - return true; + return Insert(boat, 0); } /// /// Добавление объекта в набор на конкретную позицию @@ -40,15 +39,36 @@ namespace Sailboat.Generics /// Добавляемая лодка /// Позиция /// - public bool Insert(T boat, int position) + public int Insert(T boat, 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] = boat; - return true; + return position; } /// /// Удаление объекта из набора с конкретной позиции @@ -57,8 +77,12 @@ namespace Sailboat.Generics /// public bool Remove(int position) { - // TODO проверка позиции - // TODO удаление объекта из массива, присвоив элементу массива значение null + if (position < 0 || position >= Count) + { + return false; + } + + _places[position] = null; return true; } /// @@ -68,7 +92,10 @@ namespace Sailboat.Generics /// public T? Get(int position) { - // TODO проверка позиции + if (position < 0 || position >= Count) + { + return null; + } return _places[position]; } -- 2.25.1 From 1242541ec7d485b470dfe2dec5a3caee88d12e31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=BE=D0=BB=D0=B8=D0=BD=D0=B0=20=D0=A7=D1=83=D0=B1?= =?UTF-8?q?=D1=8B=D0=BA=D0=B8=D0=BD=D0=B0?= Date: Tue, 24 Oct 2023 22:59:09 +0400 Subject: [PATCH 3/6] =?UTF-8?q?=D0=B2=D1=80=D0=BE=D0=B4=D0=B5=20=D0=B3?= =?UTF-8?q?=D0=BE=D1=82=D0=BE=D0=B2=D0=B0=D1=8F=20=D0=BB=D0=B0=D0=B1=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sailboat/Sailboat/BoatsGenericCollection.cs | 4 ++-- Sailboat/Sailboat/FormBoatCollection.Designer.cs | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Sailboat/Sailboat/BoatsGenericCollection.cs b/Sailboat/Sailboat/BoatsGenericCollection.cs index 3f15e67..426fc8e 100644 --- a/Sailboat/Sailboat/BoatsGenericCollection.cs +++ b/Sailboat/Sailboat/BoatsGenericCollection.cs @@ -137,8 +137,8 @@ namespace Sailboat.Generics if (boat != null) { - int inRow = _pictureWidth / _placeSizeWidth; - boat.SetPosition((inRow - 1 - (i % inRow)) * _placeSizeWidth, i / inRow * _placeSizeHeight); + int width = _pictureWidth / _placeSizeWidth; + boat.SetPosition(i % width * _placeSizeWidth, (i / (_pictureWidth / _placeSizeWidth)) * _placeSizeHeight); boat.DrawTransport(g); } } diff --git a/Sailboat/Sailboat/FormBoatCollection.Designer.cs b/Sailboat/Sailboat/FormBoatCollection.Designer.cs index 521443f..a2f0fd8 100644 --- a/Sailboat/Sailboat/FormBoatCollection.Designer.cs +++ b/Sailboat/Sailboat/FormBoatCollection.Designer.cs @@ -42,7 +42,7 @@ // this.pictureBoxCollection.Location = new System.Drawing.Point(0, 0); this.pictureBoxCollection.Name = "pictureBoxCollection"; - this.pictureBoxCollection.Size = new System.Drawing.Size(700, 450); + this.pictureBoxCollection.Size = new System.Drawing.Size(750, 450); this.pictureBoxCollection.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; this.pictureBoxCollection.TabIndex = 0; this.pictureBoxCollection.TabStop = false; @@ -54,7 +54,7 @@ this.panelTools.Controls.Add(this.buttonRefreshCollection); this.panelTools.Controls.Add(this.buttonRemoveBoat); this.panelTools.Controls.Add(this.buttonAddBoat); - this.panelTools.Location = new System.Drawing.Point(707, 12); + this.panelTools.Location = new System.Drawing.Point(756, 12); this.panelTools.Name = "panelTools"; this.panelTools.Size = new System.Drawing.Size(209, 426); this.panelTools.TabIndex = 1; @@ -100,7 +100,7 @@ // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(929, 450); + this.ClientSize = new System.Drawing.Size(969, 450); this.Controls.Add(this.panelTools); this.Controls.Add(this.pictureBoxCollection); this.Name = "FormBoatCollection"; -- 2.25.1 From 53ddca385f882769e6fa03f4c86a1a54fd180dd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=BE=D0=BB=D0=B8=D0=BD=D0=B0=20=D0=A7=D1=83=D0=B1?= =?UTF-8?q?=D1=8B=D0=BA=D0=B8=D0=BD=D0=B0?= Date: Wed, 25 Oct 2023 09:01:36 +0400 Subject: [PATCH 4/6] =?UTF-8?q?=D1=82=D0=BE=D1=87=D0=BD=D0=BE=20=D0=B3?= =?UTF-8?q?=D0=BE=D1=82=D0=BE=D0=B2=D0=B0=D1=8F=20=D0=BB=D0=B0=D0=B1=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sailboat/Sailboat/BoatsGenericCollection.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Sailboat/Sailboat/BoatsGenericCollection.cs b/Sailboat/Sailboat/BoatsGenericCollection.cs index 426fc8e..37a71b4 100644 --- a/Sailboat/Sailboat/BoatsGenericCollection.cs +++ b/Sailboat/Sailboat/BoatsGenericCollection.cs @@ -31,11 +31,11 @@ namespace Sailboat.Generics /// /// Размер занимаемого объектом места (ширина) /// - private readonly int _placeSizeWidth = 180; + private readonly int _placeSizeWidth = 160; /// /// Размер занимаемого объектом места (высота) /// - private readonly int _placeSizeHeight = 180; + private readonly int _placeSizeHeight = 160; /// /// Набор объектов /// @@ -74,7 +74,7 @@ namespace Sailboat.Generics /// /// /// - public static T? operator -(BoatsGenericCollection collect, int + public static bool operator -(BoatsGenericCollection collect, int pos) { T? obj = collect._collection.Get(pos); @@ -82,7 +82,7 @@ namespace Sailboat.Generics { collect._collection.Remove(pos); } - return obj; + return false; } /// /// Получение объекта IMoveableObject -- 2.25.1 From 605e3cf2e50175de7d29f410336b0da1ed36b611 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=BE=D0=BB=D0=B8=D0=BD=D0=B0=20=D0=A7=D1=83=D0=B1?= =?UTF-8?q?=D1=8B=D0=BA=D0=B8=D0=BD=D0=B0?= Date: Wed, 25 Oct 2023 09:43:28 +0400 Subject: [PATCH 5/6] =?UTF-8?q?=D0=B8=D1=82=D0=BE=D0=B3=D0=BE=D0=B2=D1=8B?= =?UTF-8?q?=D0=B5=20=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sailboat/Sailboat/SetGeneric.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Sailboat/Sailboat/SetGeneric.cs b/Sailboat/Sailboat/SetGeneric.cs index 04a3078..9fe38ca 100644 --- a/Sailboat/Sailboat/SetGeneric.cs +++ b/Sailboat/Sailboat/SetGeneric.cs @@ -98,6 +98,5 @@ namespace Sailboat.Generics } return _places[position]; } - } } -- 2.25.1 From 09e91db019fb7209c978965c73de23b0d715cc7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=BE=D0=BB=D0=B8=D0=BD=D0=B0=20=D0=A7=D1=83=D0=B1?= =?UTF-8?q?=D1=8B=D0=BA=D0=B8=D0=BD=D0=B0?= Date: Sat, 18 Nov 2023 14:01:08 +0400 Subject: [PATCH 6/6] =?UTF-8?q?=D0=B8=D1=82=D0=BE=D0=B3=D0=BE=D0=B2=D1=8B?= =?UTF-8?q?=D0=B5=20=D0=BA=D0=BE=D1=80=D1=80=D0=B5=D0=BA=D1=82=D0=B8=D1=80?= =?UTF-8?q?=D0=BE=D0=B2=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sailboat/Sailboat/BoatsGenericCollection.cs | 2 +- Sailboat/Sailboat/FormSailboat.cs | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Sailboat/Sailboat/BoatsGenericCollection.cs b/Sailboat/Sailboat/BoatsGenericCollection.cs index 37a71b4..2228a36 100644 --- a/Sailboat/Sailboat/BoatsGenericCollection.cs +++ b/Sailboat/Sailboat/BoatsGenericCollection.cs @@ -138,7 +138,7 @@ namespace Sailboat.Generics if (boat != null) { int width = _pictureWidth / _placeSizeWidth; - boat.SetPosition(i % width * _placeSizeWidth, (i / (_pictureWidth / _placeSizeWidth)) * _placeSizeHeight); + boat.SetPosition(i % width * _placeSizeWidth, i / width * _placeSizeHeight); boat.DrawTransport(g); } } diff --git a/Sailboat/Sailboat/FormSailboat.cs b/Sailboat/Sailboat/FormSailboat.cs index edbfb8a..bd6e458 100644 --- a/Sailboat/Sailboat/FormSailboat.cs +++ b/Sailboat/Sailboat/FormSailboat.cs @@ -52,10 +52,9 @@ namespace Sailboat Color dopColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)); - ColorDialog dialogAddColor = new(); - if (dialogAddColor.ShowDialog() == DialogResult.OK) + if (dialog.ShowDialog() == DialogResult.OK) { - dopColor = dialogAddColor.Color; + dopColor = dialog.Color; } _drawingBoat = new DrawingSailboat(random.Next(100, 300), -- 2.25.1