From c8d9b3ece7ad55a3395e6453e9fad03d3227b017 Mon Sep 17 00:00:00 2001 From: Nikita Date: Sat, 15 Feb 2025 15:47:50 +0400 Subject: [PATCH 1/9] part 1 --- .../AbstractCompany.cs | 60 ++++++ .../BoatSharingService.cs | 24 +++ .../ICollectionGenericObjects.cs | 19 ++ .../MassiveGenericObjects.cs | 53 ++++++ .../FormBoatCollection.Designer.cs | 173 ++++++++++++++++++ .../ProjectCatamaran/FormBoatCollection.cs | 150 +++++++++++++++ .../ProjectCatamaran/FormBoatCollection.resx | 120 ++++++++++++ .../FormCatamaran.Designer.cs | 32 +--- .../ProjectCatamaran/FormCatamaran.cs | 45 ++--- .../ProjectCatamaran/FormCatamaran.resx | 3 + 10 files changed, 617 insertions(+), 62 deletions(-) create mode 100644 ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/AbstractCompany.cs create mode 100644 ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/BoatSharingService.cs create mode 100644 ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/ICollectionGenericObjects.cs create mode 100644 ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/MassiveGenericObjects.cs create mode 100644 ProjectCatamaran/ProjectCatamaran/FormBoatCollection.Designer.cs create mode 100644 ProjectCatamaran/ProjectCatamaran/FormBoatCollection.cs create mode 100644 ProjectCatamaran/ProjectCatamaran/FormBoatCollection.resx diff --git a/ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/AbstractCompany.cs b/ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/AbstractCompany.cs new file mode 100644 index 0000000..8beb3a2 --- /dev/null +++ b/ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/AbstractCompany.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ProjectCatamaran.Drawnings; + +namespace ProjectCatamaran.CollectionGenericObjects; +public abstract class AbstractCompany +{ + protected readonly int _placeSizeWidth = 210; + + protected readonly int _placeSizeHeight = 80; + protected readonly int _pictureWidth; + protected readonly int _pictureHeight; + protected ICollectionGenericObjects _collection = null; + private int GetMaxCount => _pictureWidth + _pictureHeight / (_placeSizeWidth + _placeSizeHeight); + + public AbstractCompany(int picWidth,int picHeight,ICollectionGenericObjects collection) + { + _pictureWidth = picWidth; + _pictureHeight = picHeight; + _collection = collection; + _collection.SetMaxCount = GetMaxCount; + } + + public static bool operator +(AbstractCompany company, DrawningBoat boat) + { + return company._collection?.Insert(boat) ?? false; + } + + public static bool operator -(AbstractCompany company, int position) + { + return company._collection?.Remove(position) ?? false; + } + + public DrawningBoat? GetRandomObject() + { + Random rnd = new Random(); + return _collection?.Get(rnd.Next(GetMaxCount)); + } + + public Bitmap Show() + { + Bitmap bitmap = new(_pictureWidth, _pictureHeight); + Graphics graphics = Graphics.FromImage(bitmap); + DrawBackground(graphics); + SetObjectPosition(); + for (int i = 0; i < (_collection?.Count ?? 0); ++i) + { + DrawningBoat? obj = _collection?.Get(i); + obj?.DrawTransport(graphics); + } + + return bitmap; + } + protected abstract void DrawBackground(Graphics g); + protected abstract void SetObjectPosition(); +} + diff --git a/ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/BoatSharingService.cs b/ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/BoatSharingService.cs new file mode 100644 index 0000000..b5ee8f4 --- /dev/null +++ b/ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/BoatSharingService.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ProjectCatamaran.Drawnings; + +namespace ProjectCatamaran.CollectionGenericObjects; +public class BoatSharingService : AbstractCompany +{ + public BoatSharingService(int picWidth, int picHeight, ICollectionGenericObjects collection) : base(picWidth, picHeight, collection) + { + } + + protected override void DrawBackground(Graphics g) + { + throw new NotImplementedException(); + } + + protected override void SetObjectPosition() + { + throw new NotImplementedException(); + } +} diff --git a/ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/ICollectionGenericObjects.cs b/ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/ICollectionGenericObjects.cs new file mode 100644 index 0000000..dc39bc6 --- /dev/null +++ b/ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/ICollectionGenericObjects.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectCatamaran.CollectionGenericObjects; + +public interface ICollectionGenericObjects where T : class +{ + int Count { get; } + int SetMaxCount { set; } + bool Insert(T obj); + bool Insert(T obj, int position); + bool Remove(int position); + + T? Get(int position); +} + diff --git a/ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/MassiveGenericObjects.cs new file mode 100644 index 0000000..8c26b44 --- /dev/null +++ b/ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/MassiveGenericObjects.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectCatamaran.CollectionGenericObjects; + +public class MassiveGenericObjects : ICollectionGenericObjects where T : class +{ + private T?[] _collection; + public int Count => _collection.Length; + + public int SetMaxCount + { + set + { + if (value > 0) + { + _collection = new T?[value]; + } + } + } + + public MassiveGenericObjects() + { + _collection = Array.Empty(); + } + public T? Get(int position) + { + //todo + return _collection[position]; + } + + public bool Insert(T obj) + { + //todo + return false; + } + + public bool Insert(T obj, int position) + { + //todo + return false; + } + + public bool Remove(int position) + { + //todo + return true; + } +} + diff --git a/ProjectCatamaran/ProjectCatamaran/FormBoatCollection.Designer.cs b/ProjectCatamaran/ProjectCatamaran/FormBoatCollection.Designer.cs new file mode 100644 index 0000000..46b8509 --- /dev/null +++ b/ProjectCatamaran/ProjectCatamaran/FormBoatCollection.Designer.cs @@ -0,0 +1,173 @@ +namespace ProjectCatamaran +{ + 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() + { + groupBoxTools = new GroupBox(); + buttonRefresh = new Button(); + buttonGoToCheck = new Button(); + buttonRemoveBoat = new Button(); + maskedTextBoxPosition = new MaskedTextBox(); + buttonAddCatamaran = new Button(); + buttonAddBoat = new Button(); + comboBoxSelectorCompany = new ComboBox(); + pictureBox = new PictureBox(); + groupBoxTools.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit(); + SuspendLayout(); + // + // groupBoxTools + // + groupBoxTools.Controls.Add(buttonRefresh); + groupBoxTools.Controls.Add(buttonGoToCheck); + groupBoxTools.Controls.Add(buttonRemoveBoat); + groupBoxTools.Controls.Add(maskedTextBoxPosition); + groupBoxTools.Controls.Add(buttonAddCatamaran); + groupBoxTools.Controls.Add(buttonAddBoat); + groupBoxTools.Controls.Add(comboBoxSelectorCompany); + groupBoxTools.Dock = DockStyle.Right; + groupBoxTools.Location = new Point(631, 0); + groupBoxTools.Name = "groupBoxTools"; + groupBoxTools.Size = new Size(169, 450); + groupBoxTools.TabIndex = 0; + groupBoxTools.TabStop = false; + groupBoxTools.Text = "Инструменты"; + // + // buttonRefresh + // + buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonRefresh.Location = new Point(6, 381); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(157, 39); + buttonRefresh.TabIndex = 6; + buttonRefresh.Text = "Обновить"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += ButtonRefresh_Click; + // + // buttonGoToCheck + // + buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonGoToCheck.Location = new Point(6, 324); + buttonGoToCheck.Name = "buttonGoToCheck"; + buttonGoToCheck.Size = new Size(157, 39); + buttonGoToCheck.TabIndex = 5; + buttonGoToCheck.Text = "Передать на тесты"; + buttonGoToCheck.UseVisualStyleBackColor = true; + buttonGoToCheck.Click += ButtonGoToCheck_Click; + // + // buttonRemoveBoat + // + buttonRemoveBoat.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonRemoveBoat.Location = new Point(6, 279); + buttonRemoveBoat.Name = "buttonRemoveBoat"; + buttonRemoveBoat.Size = new Size(157, 39); + buttonRemoveBoat.TabIndex = 4; + buttonRemoveBoat.Text = "Удалить лодку"; + buttonRemoveBoat.UseVisualStyleBackColor = true; + buttonRemoveBoat.Click += ButtonRemoveBoat_Click; + // + // maskedTextBoxPosition + // + maskedTextBoxPosition.Location = new Point(1, 233); + maskedTextBoxPosition.Mask = "00"; + maskedTextBoxPosition.Name = "maskedTextBoxPosition"; + maskedTextBoxPosition.Size = new Size(162, 23); + maskedTextBoxPosition.TabIndex = 3; + maskedTextBoxPosition.ValidatingType = typeof(int); + // + // buttonAddCatamaran + // + buttonAddCatamaran.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonAddCatamaran.Location = new Point(6, 125); + buttonAddCatamaran.Name = "buttonAddCatamaran"; + buttonAddCatamaran.Size = new Size(157, 39); + buttonAddCatamaran.TabIndex = 2; + buttonAddCatamaran.Text = "Добавление катамарана"; + buttonAddCatamaran.UseVisualStyleBackColor = true; + buttonAddCatamaran.Click += ButtonAddCatamaran_Click; + // + // buttonAddBoat + // + buttonAddBoat.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonAddBoat.Location = new Point(6, 80); + buttonAddBoat.Name = "buttonAddBoat"; + buttonAddBoat.Size = new Size(157, 39); + buttonAddBoat.TabIndex = 1; + buttonAddBoat.Text = "Добавление лодки"; + buttonAddBoat.UseVisualStyleBackColor = true; + buttonAddBoat.Click += ButtonAddBoat_Click; + // + // comboBoxSelectorCompany + // + comboBoxSelectorCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxSelectorCompany.FormattingEnabled = true; + comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" }); + comboBoxSelectorCompany.Location = new Point(6, 22); + comboBoxSelectorCompany.Name = "comboBoxSelectorCompany"; + comboBoxSelectorCompany.Size = new Size(157, 23); + comboBoxSelectorCompany.TabIndex = 0; + comboBoxSelectorCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged; + // + // pictureBox + // + pictureBox.Dock = DockStyle.Fill; + pictureBox.Location = new Point(0, 0); + pictureBox.Name = "pictureBox"; + pictureBox.Size = new Size(631, 450); + pictureBox.TabIndex = 1; + pictureBox.TabStop = false; + // + // FormBoatCollection + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(pictureBox); + Controls.Add(groupBoxTools); + Name = "FormBoatCollection"; + Text = "Коллекция лодок"; + groupBoxTools.ResumeLayout(false); + groupBoxTools.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); + ResumeLayout(false); + } + + #endregion + + private GroupBox groupBoxTools; + private Button buttonAddCatamaran; + private Button buttonAddBoat; + private ComboBox comboBoxSelectorCompany; + private MaskedTextBox maskedTextBoxPosition; + private PictureBox pictureBox; + private Button buttonRemoveBoat; + private Button buttonRefresh; + private Button buttonGoToCheck; + } +} \ No newline at end of file diff --git a/ProjectCatamaran/ProjectCatamaran/FormBoatCollection.cs b/ProjectCatamaran/ProjectCatamaran/FormBoatCollection.cs new file mode 100644 index 0000000..b22475c --- /dev/null +++ b/ProjectCatamaran/ProjectCatamaran/FormBoatCollection.cs @@ -0,0 +1,150 @@ +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 ProjectCatamaran.CollectionGenericObjects; +using ProjectCatamaran.Drawnings; + +namespace ProjectCatamaran; +public partial class FormBoatCollection : Form +{ + private AbstractCompany? _company; + public FormBoatCollection() + { + InitializeComponent(); + } + + private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e) + { + switch (comboBoxSelectorCompany.Text) + { + case "Хранилище": + _company = new BoatSharingService(pictureBox.Width, pictureBox.Height, + new MassiveGenericObjects()); + break; + } + } + private void CreateObject(string type) + { + if (_company == null) + { + return; + } + Random random = new(); + DrawningBoat drawningBoat; + switch (type) + { + case nameof(DrawningBoat): + drawningBoat = new DrawningBoat(random.Next(100, 300), random.Next(1000, 3000), + GetColor(random)); + break; + case nameof(DrawningCatamaran): + drawningBoat = new DrawningCatamaran(random.Next(100, 300), random.Next(1000, 3000), + Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), + Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), + Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2))); + break; + default: + return; + } + + if (_company + drawningBoat) + { + MessageBox.Show(("Объект добавлен")); + pictureBox.Image = _company.Show(); + } + else + { + MessageBox.Show("Не удалось добавить объект"); + } + } + + private static Color GetColor(Random random) + { + Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)); + ColorDialog dialog = new(); + if (dialog.ShowDialog() == DialogResult.OK) + { + color = dialog.Color; + } + + return color; + } + + private void ButtonAddBoat_Click(object sender, EventArgs e) + { + CreateObject(nameof(DrawningBoat)); + } + + private void ButtonAddCatamaran_Click(object sender, EventArgs e) + { + CreateObject(nameof(DrawningCatamaran)); + + } + + private void ButtonRemoveBoat_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(maskedTextBoxPosition.Text) || _company == null) + { + return; + } + + if (MessageBox.Show("Удалить объект", "Удаление", MessageBoxButtons.YesNo, + MessageBoxIcon.Question) == DialogResult.No) + { + return; + } + + int pos = Convert.ToInt32(maskedTextBoxPosition.Text); + if (_company - pos) + { + MessageBox.Show("Объект удален"); + pictureBox.Image = _company.Show(); + } + else + { + MessageBox.Show("Не удалось удалить объект"); + } + } + + private void ButtonGoToCheck_Click(object sender, EventArgs e) + { + if (_company == null) + { + return; + } + + DrawningBoat? boat = null; + int counter = 100; + while (boat == null) + { + boat = _company.GetRandomObject(); + counter--; + if (counter <= 0) + break; + } + + if (boat == null) + return; + FormCatamaran form = new() + { + SetBoat = boat + }; + form.ShowDialog(); + } + + private void ButtonRefresh_Click(object sender, EventArgs e) + { + if (_company == null) + { + return; + } + + pictureBox.Image = _company.Show(); + } +} diff --git a/ProjectCatamaran/ProjectCatamaran/FormBoatCollection.resx b/ProjectCatamaran/ProjectCatamaran/FormBoatCollection.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectCatamaran/ProjectCatamaran/FormBoatCollection.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ProjectCatamaran/ProjectCatamaran/FormCatamaran.Designer.cs b/ProjectCatamaran/ProjectCatamaran/FormCatamaran.Designer.cs index 5c03681..6b7659f 100644 --- a/ProjectCatamaran/ProjectCatamaran/FormCatamaran.Designer.cs +++ b/ProjectCatamaran/ProjectCatamaran/FormCatamaran.Designer.cs @@ -29,14 +29,13 @@ private void InitializeComponent() { pictureBoxCatamaran = new PictureBox(); - buttonCreateCatamaran = new Button(); buttonUp = new Button(); buttonRight = new Button(); buttonLeft = new Button(); buttonDown = new Button(); - buttonCreateBoat = new Button(); comboBoxStrategy = new ComboBox(); buttonStrategyStep = new Button(); + colorDialog1 = new ColorDialog(); ((System.ComponentModel.ISupportInitialize)pictureBoxCatamaran).BeginInit(); SuspendLayout(); // @@ -45,21 +44,10 @@ pictureBoxCatamaran.Dock = DockStyle.Fill; pictureBoxCatamaran.Location = new Point(0, 0); pictureBoxCatamaran.Name = "pictureBoxCatamaran"; - pictureBoxCatamaran.Size = new Size(801, 450); + pictureBoxCatamaran.Size = new Size(800, 450); pictureBoxCatamaran.TabIndex = 0; pictureBoxCatamaran.TabStop = false; // - // buttonCreateCatamaran - // - buttonCreateCatamaran.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; - buttonCreateCatamaran.Location = new Point(12, 402); - buttonCreateCatamaran.Name = "buttonCreateCatamaran"; - buttonCreateCatamaran.Size = new Size(166, 40); - buttonCreateCatamaran.TabIndex = 1; - buttonCreateCatamaran.Text = "Создать катамаран"; - buttonCreateCatamaran.UseVisualStyleBackColor = true; - buttonCreateCatamaran.Click += ButtonCreateCatamaran_Click; - // // buttonUp // buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; @@ -108,17 +96,6 @@ buttonDown.UseVisualStyleBackColor = true; buttonDown.Click += ButtonMove_Click; // - // buttonCreateBoat - // - buttonCreateBoat.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; - buttonCreateBoat.Location = new Point(184, 402); - buttonCreateBoat.Name = "buttonCreateBoat"; - buttonCreateBoat.Size = new Size(166, 40); - buttonCreateBoat.TabIndex = 6; - buttonCreateBoat.Text = "Создать лодку"; - buttonCreateBoat.UseVisualStyleBackColor = true; - buttonCreateBoat.Click += ButtonCreateBoat_Click; - // // comboBoxStrategy // comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList; @@ -147,12 +124,10 @@ ClientSize = new Size(800, 450); Controls.Add(buttonStrategyStep); Controls.Add(comboBoxStrategy); - Controls.Add(buttonCreateBoat); Controls.Add(buttonDown); Controls.Add(buttonLeft); Controls.Add(buttonRight); Controls.Add(buttonUp); - Controls.Add(buttonCreateCatamaran); Controls.Add(pictureBoxCatamaran); Name = "FormCatamaran"; Text = "Катамаран"; @@ -163,13 +138,12 @@ #endregion private PictureBox pictureBoxCatamaran; - private Button buttonCreateCatamaran; private Button buttonUp; private Button buttonRight; private Button buttonLeft; private Button buttonDown; - private Button buttonCreateBoat; private ComboBox comboBoxStrategy; private Button buttonStrategyStep; + private ColorDialog colorDialog1; } } \ No newline at end of file diff --git a/ProjectCatamaran/ProjectCatamaran/FormCatamaran.cs b/ProjectCatamaran/ProjectCatamaran/FormCatamaran.cs index e008569..c547223 100644 --- a/ProjectCatamaran/ProjectCatamaran/FormCatamaran.cs +++ b/ProjectCatamaran/ProjectCatamaran/FormCatamaran.cs @@ -17,6 +17,18 @@ namespace ProjectCatamaran { private DrawningBoat? _drawningBoat; private AbstractStrategy? _strategy; + + public DrawningBoat SetBoat + { + set + { + _drawningBoat = value; + _drawningBoat.SetPictureSize(pictureBoxCatamaran.Width, pictureBoxCatamaran.Height); + comboBoxStrategy.Enabled = true; + _strategy = null; + Draw(); + } + } public FormCatamaran() { InitializeComponent(); @@ -64,39 +76,6 @@ namespace ProjectCatamaran } } - private void CreateObject(string type) - { - Random random = new(); - switch (type) - { - case nameof(DrawningBoat): - _drawningBoat = new DrawningBoat(random.Next(100, 300), random.Next(1000, 3000), - Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256))); - break; - case nameof(DrawningCatamaran): - _drawningBoat = new DrawningCatamaran(random.Next(100, 300), random.Next(1000, 3000), - Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), - Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), - Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2))); - break; - default: - return; - } - _drawningBoat.SetPictureSize(pictureBoxCatamaran.Width, pictureBoxCatamaran.Height); - _drawningBoat.SetPosition(random.Next(10, 100), random.Next(10, 100)); - _strategy = null; - comboBoxStrategy.Enabled = true; - Draw(); - } - private void ButtonCreateCatamaran_Click(object sender, EventArgs e) - { - CreateObject(nameof(DrawningCatamaran)); - } - - private void ButtonCreateBoat_Click(object sender, EventArgs e) - { - CreateObject(nameof(DrawningBoat)); - } /// /// Обработка нажатия кнопки "Шаг" /// diff --git a/ProjectCatamaran/ProjectCatamaran/FormCatamaran.resx b/ProjectCatamaran/ProjectCatamaran/FormCatamaran.resx index af32865..818dfae 100644 --- a/ProjectCatamaran/ProjectCatamaran/FormCatamaran.resx +++ b/ProjectCatamaran/ProjectCatamaran/FormCatamaran.resx @@ -117,4 +117,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 17, 17 + \ No newline at end of file -- 2.25.1 From 9003758c6b8aea04f467ec9bf5abdc9ddca41ebb Mon Sep 17 00:00:00 2001 From: Nikita Date: Sun, 16 Feb 2025 15:32:34 +0400 Subject: [PATCH 2/9] 2/3 done --- .../AbstractCompany.cs | 6 +- .../BoatSharingService.cs | 24 -------- .../CollectionGenericObjects/Harbour.cs | 55 +++++++++++++++++++ .../MassiveGenericObjects.cs | 51 ++++++++++++++++- .../ProjectCatamaran/FormBoatCollection.cs | 7 +-- ProjectCatamaran/ProjectCatamaran/Program.cs | 2 +- 6 files changed, 110 insertions(+), 35 deletions(-) delete mode 100644 ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/BoatSharingService.cs create mode 100644 ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/Harbour.cs diff --git a/ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/AbstractCompany.cs b/ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/AbstractCompany.cs index 8beb3a2..5a5a145 100644 --- a/ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/AbstractCompany.cs +++ b/ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/AbstractCompany.cs @@ -8,13 +8,13 @@ using ProjectCatamaran.Drawnings; namespace ProjectCatamaran.CollectionGenericObjects; public abstract class AbstractCompany { - protected readonly int _placeSizeWidth = 210; + protected readonly int _placeSizeWidth = 90; - protected readonly int _placeSizeHeight = 80; + protected readonly int _placeSizeHeight = 50; protected readonly int _pictureWidth; protected readonly int _pictureHeight; protected ICollectionGenericObjects _collection = null; - private int GetMaxCount => _pictureWidth + _pictureHeight / (_placeSizeWidth + _placeSizeHeight); + private int GetMaxCount => (_pictureWidth / _placeSizeWidth + 1) * (_pictureHeight / _placeSizeHeight / 2) - (_pictureHeight / _placeSizeHeight / 2); public AbstractCompany(int picWidth,int picHeight,ICollectionGenericObjects collection) { diff --git a/ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/BoatSharingService.cs b/ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/BoatSharingService.cs deleted file mode 100644 index b5ee8f4..0000000 --- a/ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/BoatSharingService.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using ProjectCatamaran.Drawnings; - -namespace ProjectCatamaran.CollectionGenericObjects; -public class BoatSharingService : AbstractCompany -{ - public BoatSharingService(int picWidth, int picHeight, ICollectionGenericObjects collection) : base(picWidth, picHeight, collection) - { - } - - protected override void DrawBackground(Graphics g) - { - throw new NotImplementedException(); - } - - protected override void SetObjectPosition() - { - throw new NotImplementedException(); - } -} diff --git a/ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/Harbour.cs b/ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/Harbour.cs new file mode 100644 index 0000000..26bee8e --- /dev/null +++ b/ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/Harbour.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ProjectCatamaran.Drawnings; + +namespace ProjectCatamaran.CollectionGenericObjects; +public class Harbour : AbstractCompany +{ + public Harbour(int picWidth, int picHeight, ICollectionGenericObjects collection) : base(picWidth, picHeight, collection) + { + } + + protected override void DrawBackground(Graphics g) + { + Pen pen = new Pen(Color.Black,2); + for (int i = 0; i < _pictureHeight / _placeSizeHeight / 2; i++) + { + g.DrawLine(pen, 0, _pictureHeight - 10 - (2*i* _placeSizeHeight) + , _pictureWidth , _pictureHeight - 10 - (2*i * _placeSizeHeight)); + for (int j = 0; j - 1 < _pictureWidth / _placeSizeWidth; j++) + { + g.DrawLine(pen, (j * _placeSizeWidth), _pictureHeight - 10 - (2 * i * _placeSizeHeight), + (j * _placeSizeWidth), _pictureHeight - 10 - (2 *i * _placeSizeHeight)- _placeSizeHeight); + } + } + } + + protected override void SetObjectPosition() + { + int curPosX = 0; + int curPosY = 0; + + for (int i = 0; i < (_collection?.Count ?? 0); i++) + { + + if (_collection?.Get(i) != null) + { + + _collection?.Get(i)?.SetPictureSize(_pictureWidth, _pictureHeight); + _collection?.Get(i)?.SetPosition((curPosX * _placeSizeWidth) + 15,_pictureHeight - 2 * curPosY * _placeSizeHeight - _placeSizeHeight - 5); + } + curPosX += 1; + + + if (curPosX > 6) + { + curPosX = 0; + curPosY++; + } + + } + } +} diff --git a/ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/MassiveGenericObjects.cs index 8c26b44..2e8965a 100644 --- a/ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/MassiveGenericObjects.cs +++ b/ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/MassiveGenericObjects.cs @@ -29,24 +29,69 @@ public class MassiveGenericObjects : ICollectionGenericObjects where T : c public T? Get(int position) { //todo - return _collection[position]; - } + if (position >= 0 && position < Count) + { + return _collection[position]; + } + return null; + } public bool Insert(T obj) { //todo + for (int i = 0; i < Count; i++) + { + if (_collection[i] == null) + { + _collection[i] = obj; + return true; + } + } + return false; } public bool Insert(T obj, int position) { //todo + if (!(position > 0 && position < _collection.Length)) + { + return false; + } + + if (_collection[position] == null) + _collection[position] = obj; + else + { + for (int i = position + 1; i < Count; i++) + { + if (_collection[i] == null) + { + _collection[i] = obj; + return true; + } + } + + for (int i = position - 1; i >= 0; i--) + { + if (_collection[i] == null) + { + _collection[i] = obj; + return true; + } + } + } return false; } public bool Remove(int position) { - //todo + if (!(position >= 0 && position < _collection.Length) || _collection[position] == null ) + { + return false; + } + + _collection[position] = null; return true; } } diff --git a/ProjectCatamaran/ProjectCatamaran/FormBoatCollection.cs b/ProjectCatamaran/ProjectCatamaran/FormBoatCollection.cs index b22475c..37f6cfc 100644 --- a/ProjectCatamaran/ProjectCatamaran/FormBoatCollection.cs +++ b/ProjectCatamaran/ProjectCatamaran/FormBoatCollection.cs @@ -24,7 +24,7 @@ public partial class FormBoatCollection : Form switch (comboBoxSelectorCompany.Text) { case "Хранилище": - _company = new BoatSharingService(pictureBox.Width, pictureBox.Height, + _company = new Harbour(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects()); break; } @@ -45,8 +45,7 @@ public partial class FormBoatCollection : Form break; case nameof(DrawningCatamaran): drawningBoat = new DrawningCatamaran(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)), + GetColor(random), GetColor(random), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2))); break; default: @@ -95,7 +94,7 @@ public partial class FormBoatCollection : Form } if (MessageBox.Show("Удалить объект", "Удаление", MessageBoxButtons.YesNo, - MessageBoxIcon.Question) == DialogResult.No) + MessageBoxIcon.Question) != DialogResult.Yes) { return; } diff --git a/ProjectCatamaran/ProjectCatamaran/Program.cs b/ProjectCatamaran/ProjectCatamaran/Program.cs index 4d620b5..59feea7 100644 --- a/ProjectCatamaran/ProjectCatamaran/Program.cs +++ b/ProjectCatamaran/ProjectCatamaran/Program.cs @@ -11,7 +11,7 @@ namespace ProjectCatamaran // 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 FormBoatCollection()); } } } \ No newline at end of file -- 2.25.1 From 2235a53cf3d6c1edc1ec32a122f8c02da5c2019d Mon Sep 17 00:00:00 2001 From: Nikita Date: Sat, 22 Feb 2025 21:16:29 +0400 Subject: [PATCH 3/9] little fix --- .../Drawnings/DrawningBoat.cs | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/ProjectCatamaran/ProjectCatamaran/Drawnings/DrawningBoat.cs b/ProjectCatamaran/ProjectCatamaran/Drawnings/DrawningBoat.cs index 8bcf450..22f832c 100644 --- a/ProjectCatamaran/ProjectCatamaran/Drawnings/DrawningBoat.cs +++ b/ProjectCatamaran/ProjectCatamaran/Drawnings/DrawningBoat.cs @@ -32,11 +32,11 @@ public class DrawningBoat /// /// Ширина прорисовки катамарана /// - private readonly int _drawningCatamaranWidth = 60; + private readonly int _drawningBoatWidth = 60; /// /// Высота прорисовки катамарана /// - private readonly int _drawningCatamaranHeight = 25; + private readonly int _drawningBoatHeight = 25; /// /// координата х обьекта /// @@ -48,11 +48,11 @@ public class DrawningBoat /// /// ширина обьекта /// - public int GetWidth => _drawningCatamaranWidth; + public int GetWidth => _drawningBoatWidth; /// /// высота обьекта /// - public int GetHeight => _drawningCatamaranHeight; + public int GetHeight => _drawningBoatHeight; /// /// пустой конструктор @@ -78,12 +78,12 @@ public class DrawningBoat /// /// Конструктор /// - /// Ширина катера - /// высота катера - public DrawningBoat(int drawningCatamaranWidth, int drawningCatamaranHeight) : this() + /// Ширина катера + /// высота катера + public DrawningBoat(int drawningBoatWidth, int drawningBoatHeight) : this() { - _drawningCatamaranWidth = drawningCatamaranWidth; - _drawningCatamaranHeight = drawningCatamaranHeight; + _drawningBoatWidth = drawningBoatWidth; + _drawningBoatHeight = drawningBoatHeight; } /// @@ -94,7 +94,7 @@ public class DrawningBoat /// public bool SetPictureSize(int width, int height) { - if (_drawningCatamaranHeight < height && _drawningCatamaranWidth < width) + if (_drawningBoatHeight < height && _drawningBoatWidth < width) { _pictureHeight = height; _pictureWidth = width; @@ -113,12 +113,12 @@ public class DrawningBoat { return; } - if (x > _pictureWidth - _drawningCatamaranWidth || x < 0) - _startPosX = x < 0 ? 0 : _pictureWidth - _drawningCatamaranWidth; + if (x > _pictureWidth - _drawningBoatWidth || x < 0) + _startPosX = x < 0 ? 0 : _pictureWidth - _drawningBoatWidth; else _startPosX = x; - if (y > _pictureHeight - _drawningCatamaranHeight || y < 0) - _startPosY = y < 0 ? 0 : _pictureHeight - _drawningCatamaranHeight; + if (y > _pictureHeight - _drawningBoatHeight || y < 0) + _startPosY = y < 0 ? 0 : _pictureHeight - _drawningBoatHeight; else _startPosY = y; } @@ -148,13 +148,13 @@ public class DrawningBoat } return true; case DirectionType.Right: - if (_startPosX.Value + (int)EntityBoat.Step + _drawningCatamaranWidth <= _pictureWidth) + if (_startPosX.Value + (int)EntityBoat.Step + _drawningBoatWidth <= _pictureWidth) { _startPosX += (int)EntityBoat.Step; } return true; case DirectionType.Down: - if (_startPosY.Value + (int)EntityBoat.Step + _drawningCatamaranHeight <= _pictureHeight) + if (_startPosY.Value + (int)EntityBoat.Step + _drawningBoatHeight <= _pictureHeight) { _startPosY += (int)EntityBoat.Step; } -- 2.25.1 From 14c3ee914fdffef027b95b02b06ae204c7b3c81a Mon Sep 17 00:00:00 2001 From: Nikita Date: Sat, 22 Feb 2025 21:26:35 +0400 Subject: [PATCH 4/9] some fixes --- ProjectCatamaran/ProjectCatamaran/Drawnings/DrawningBoat.cs | 2 +- .../ProjectCatamaran/MovementStrategy/MoveToBorder.cs | 4 ++-- .../ProjectCatamaran/MovementStrategy/MoveableBoat.cs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ProjectCatamaran/ProjectCatamaran/Drawnings/DrawningBoat.cs b/ProjectCatamaran/ProjectCatamaran/Drawnings/DrawningBoat.cs index 22f832c..34ae17d 100644 --- a/ProjectCatamaran/ProjectCatamaran/Drawnings/DrawningBoat.cs +++ b/ProjectCatamaran/ProjectCatamaran/Drawnings/DrawningBoat.cs @@ -36,7 +36,7 @@ public class DrawningBoat /// /// Высота прорисовки катамарана /// - private readonly int _drawningBoatHeight = 25; + private readonly int _drawningBoatHeight = 22; /// /// координата х обьекта /// diff --git a/ProjectCatamaran/ProjectCatamaran/MovementStrategy/MoveToBorder.cs b/ProjectCatamaran/ProjectCatamaran/MovementStrategy/MoveToBorder.cs index ba16109..188f4f3 100644 --- a/ProjectCatamaran/ProjectCatamaran/MovementStrategy/MoveToBorder.cs +++ b/ProjectCatamaran/ProjectCatamaran/MovementStrategy/MoveToBorder.cs @@ -15,9 +15,9 @@ public class MoveToBorder : AbstractStrategy ObjectParameters? objParams = GetObjectParameters; if (objParams == null) return; - if (objParams.RightBorder + GetStep() < FieldWidth) + if (objParams.RightBorder + GetStep() <= FieldWidth) MoveRight(); - if (objParams.DownBorder + GetStep() < FieldHeight) + if (objParams.DownBorder + GetStep() <= FieldHeight) MoveDown(); } diff --git a/ProjectCatamaran/ProjectCatamaran/MovementStrategy/MoveableBoat.cs b/ProjectCatamaran/ProjectCatamaran/MovementStrategy/MoveableBoat.cs index b7b8f69..59c7b89 100644 --- a/ProjectCatamaran/ProjectCatamaran/MovementStrategy/MoveableBoat.cs +++ b/ProjectCatamaran/ProjectCatamaran/MovementStrategy/MoveableBoat.cs @@ -12,7 +12,7 @@ namespace ProjectCatamaran.MovementStrategy /// /// Поле-объект класса DrawningBoat или его наследника /// - private DrawningBoat _boat = null; + private readonly DrawningBoat _boat = null; /// /// Конструктор /// -- 2.25.1 From 062dbc8a0cf951f99f341336aeb642e76c0f9656 Mon Sep 17 00:00:00 2001 From: Nikita Date: Sat, 22 Feb 2025 22:57:59 +0400 Subject: [PATCH 5/9] private speed and weight --- ProjectCatamaran/ProjectCatamaran/Entities/EntityBoat.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ProjectCatamaran/ProjectCatamaran/Entities/EntityBoat.cs b/ProjectCatamaran/ProjectCatamaran/Entities/EntityBoat.cs index ce7a393..0c5d341 100644 --- a/ProjectCatamaran/ProjectCatamaran/Entities/EntityBoat.cs +++ b/ProjectCatamaran/ProjectCatamaran/Entities/EntityBoat.cs @@ -14,11 +14,11 @@ public class EntityBoat /// /// Скорость /// - public int Speed { get; set; } + public int Speed { get; private set; } /// /// Вес авто /// - public double Weight { get; set; } + public double Weight { get; private set; } /// /// Основной цвет /// -- 2.25.1 From aac002fb3ad59c71004ab5589f5797abac84d9f5 Mon Sep 17 00:00:00 2001 From: Nikita Date: Mon, 24 Feb 2025 19:56:46 +0400 Subject: [PATCH 6/9] fixed logic to border --- .../ProjectCatamaran/MovementStrategy/MoveToBorder.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ProjectCatamaran/ProjectCatamaran/MovementStrategy/MoveToBorder.cs b/ProjectCatamaran/ProjectCatamaran/MovementStrategy/MoveToBorder.cs index 188f4f3..da1d690 100644 --- a/ProjectCatamaran/ProjectCatamaran/MovementStrategy/MoveToBorder.cs +++ b/ProjectCatamaran/ProjectCatamaran/MovementStrategy/MoveToBorder.cs @@ -30,8 +30,8 @@ public class MoveToBorder : AbstractStrategy ObjectParameters? objParams = GetObjectParameters; if (objParams == null) return false; - return objParams.RightBorder + GetStep() >= FieldWidth && - objParams.DownBorder + GetStep() >= FieldHeight ; + return objParams.RightBorder + GetStep() > FieldWidth && + objParams.DownBorder + GetStep() > FieldHeight ; } } -- 2.25.1 From fb452c0f70992b87b0779ac6b33ad84c3b379db7 Mon Sep 17 00:00:00 2001 From: Nikita Date: Mon, 24 Feb 2025 21:31:48 +0400 Subject: [PATCH 7/9] task 5 --- .../AbstractCompany.cs | 8 +++--- .../ICollectionGenericObjects.cs | 6 ++--- .../MassiveGenericObjects.cs | 25 ++++++++++--------- .../ProjectCatamaran/FormBoatCollection.cs | 4 +-- 4 files changed, 22 insertions(+), 21 deletions(-) diff --git a/ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/AbstractCompany.cs b/ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/AbstractCompany.cs index 5a5a145..25b7fec 100644 --- a/ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/AbstractCompany.cs +++ b/ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/AbstractCompany.cs @@ -24,14 +24,14 @@ public abstract class AbstractCompany _collection.SetMaxCount = GetMaxCount; } - public static bool operator +(AbstractCompany company, DrawningBoat boat) + public static int operator +(AbstractCompany company, DrawningBoat boat) { - return company._collection?.Insert(boat) ?? false; + return company._collection?.Insert(boat) ?? -1; } - public static bool operator -(AbstractCompany company, int position) + public static DrawningBoat? operator -(AbstractCompany company, int position) { - return company._collection?.Remove(position) ?? false; + return company._collection?.Remove(position); } public DrawningBoat? GetRandomObject() diff --git a/ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/ICollectionGenericObjects.cs b/ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/ICollectionGenericObjects.cs index dc39bc6..0134704 100644 --- a/ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/ICollectionGenericObjects.cs +++ b/ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/ICollectionGenericObjects.cs @@ -10,9 +10,9 @@ public interface ICollectionGenericObjects where T : class { int Count { get; } int SetMaxCount { set; } - bool Insert(T obj); - bool Insert(T obj, int position); - bool Remove(int position); + int Insert(T obj); + int Insert(T obj, int position); + T? Remove(int position); T? Get(int position); } diff --git a/ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/MassiveGenericObjects.cs index 2e8965a..64274ba 100644 --- a/ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/MassiveGenericObjects.cs +++ b/ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/MassiveGenericObjects.cs @@ -25,7 +25,7 @@ public class MassiveGenericObjects : ICollectionGenericObjects where T : c public MassiveGenericObjects() { _collection = Array.Empty(); - } + } public T? Get(int position) { //todo @@ -36,7 +36,7 @@ public class MassiveGenericObjects : ICollectionGenericObjects where T : c return null; } - public bool Insert(T obj) + public int Insert(T obj) { //todo for (int i = 0; i < Count; i++) @@ -44,19 +44,19 @@ public class MassiveGenericObjects : ICollectionGenericObjects where T : c if (_collection[i] == null) { _collection[i] = obj; - return true; + return i; } } - return false; + return -1; } - public bool Insert(T obj, int position) + public int Insert(T obj, int position) { //todo if (!(position > 0 && position < _collection.Length)) { - return false; + return -1; } if (_collection[position] == null) @@ -68,7 +68,7 @@ public class MassiveGenericObjects : ICollectionGenericObjects where T : c if (_collection[i] == null) { _collection[i] = obj; - return true; + return i; } } @@ -77,22 +77,23 @@ public class MassiveGenericObjects : ICollectionGenericObjects where T : c if (_collection[i] == null) { _collection[i] = obj; - return true; + return i; } } } - return false; + return -1; } - public bool Remove(int position) + public T? Remove(int position) { if (!(position >= 0 && position < _collection.Length) || _collection[position] == null ) { - return false; + return null; } + T? deletedElement = _collection[position]; _collection[position] = null; - return true; + return deletedElement; } } diff --git a/ProjectCatamaran/ProjectCatamaran/FormBoatCollection.cs b/ProjectCatamaran/ProjectCatamaran/FormBoatCollection.cs index 37f6cfc..c253d60 100644 --- a/ProjectCatamaran/ProjectCatamaran/FormBoatCollection.cs +++ b/ProjectCatamaran/ProjectCatamaran/FormBoatCollection.cs @@ -52,7 +52,7 @@ public partial class FormBoatCollection : Form return; } - if (_company + drawningBoat) + if (_company + drawningBoat != -1) { MessageBox.Show(("Объект добавлен")); pictureBox.Image = _company.Show(); @@ -100,7 +100,7 @@ public partial class FormBoatCollection : Form } int pos = Convert.ToInt32(maskedTextBoxPosition.Text); - if (_company - pos) + if (_company - pos != null) { MessageBox.Show("Объект удален"); pictureBox.Image = _company.Show(); -- 2.25.1 From 9a97f4378d84b12773066167a3ee4dbbae4a84c5 Mon Sep 17 00:00:00 2001 From: Nikita Date: Tue, 25 Feb 2025 20:59:41 +0400 Subject: [PATCH 8/9] delete ws --- .../CollectionGenericObjects/AbstractCompany.cs | 6 ------ .../ProjectCatamaran/CollectionGenericObjects/Harbour.cs | 3 --- .../CollectionGenericObjects/MassiveGenericObjects.cs | 6 +----- ProjectCatamaran/ProjectCatamaran/Drawnings/DrawningBoat.cs | 2 -- 4 files changed, 1 insertion(+), 16 deletions(-) diff --git a/ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/AbstractCompany.cs b/ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/AbstractCompany.cs index 25b7fec..bf35846 100644 --- a/ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/AbstractCompany.cs +++ b/ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/AbstractCompany.cs @@ -9,13 +9,11 @@ namespace ProjectCatamaran.CollectionGenericObjects; public abstract class AbstractCompany { protected readonly int _placeSizeWidth = 90; - protected readonly int _placeSizeHeight = 50; protected readonly int _pictureWidth; protected readonly int _pictureHeight; protected ICollectionGenericObjects _collection = null; private int GetMaxCount => (_pictureWidth / _placeSizeWidth + 1) * (_pictureHeight / _placeSizeHeight / 2) - (_pictureHeight / _placeSizeHeight / 2); - public AbstractCompany(int picWidth,int picHeight,ICollectionGenericObjects collection) { _pictureWidth = picWidth; @@ -23,23 +21,19 @@ public abstract class AbstractCompany _collection = collection; _collection.SetMaxCount = GetMaxCount; } - public static int operator +(AbstractCompany company, DrawningBoat boat) { return company._collection?.Insert(boat) ?? -1; } - public static DrawningBoat? operator -(AbstractCompany company, int position) { return company._collection?.Remove(position); } - public DrawningBoat? GetRandomObject() { Random rnd = new Random(); return _collection?.Get(rnd.Next(GetMaxCount)); } - public Bitmap Show() { Bitmap bitmap = new(_pictureWidth, _pictureHeight); diff --git a/ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/Harbour.cs b/ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/Harbour.cs index 26bee8e..06bddaa 100644 --- a/ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/Harbour.cs +++ b/ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/Harbour.cs @@ -11,7 +11,6 @@ public class Harbour : AbstractCompany public Harbour(int picWidth, int picHeight, ICollectionGenericObjects collection) : base(picWidth, picHeight, collection) { } - protected override void DrawBackground(Graphics g) { Pen pen = new Pen(Color.Black,2); @@ -26,7 +25,6 @@ public class Harbour : AbstractCompany } } } - protected override void SetObjectPosition() { int curPosX = 0; @@ -49,7 +47,6 @@ public class Harbour : AbstractCompany curPosX = 0; curPosY++; } - } } } diff --git a/ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/MassiveGenericObjects.cs index 64274ba..e69bbfd 100644 --- a/ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/MassiveGenericObjects.cs +++ b/ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/MassiveGenericObjects.cs @@ -10,7 +10,6 @@ public class MassiveGenericObjects : ICollectionGenericObjects where T : c { private T?[] _collection; public int Count => _collection.Length; - public int SetMaxCount { set @@ -21,7 +20,6 @@ public class MassiveGenericObjects : ICollectionGenericObjects where T : c } } } - public MassiveGenericObjects() { _collection = Array.Empty(); @@ -35,7 +33,7 @@ public class MassiveGenericObjects : ICollectionGenericObjects where T : c } return null; - } + } public int Insert(T obj) { //todo @@ -50,7 +48,6 @@ public class MassiveGenericObjects : ICollectionGenericObjects where T : c return -1; } - public int Insert(T obj, int position) { //todo @@ -83,7 +80,6 @@ public class MassiveGenericObjects : ICollectionGenericObjects where T : c } return -1; } - public T? Remove(int position) { if (!(position >= 0 && position < _collection.Length) || _collection[position] == null ) diff --git a/ProjectCatamaran/ProjectCatamaran/Drawnings/DrawningBoat.cs b/ProjectCatamaran/ProjectCatamaran/Drawnings/DrawningBoat.cs index bcabe4f..f9f0a7e 100644 --- a/ProjectCatamaran/ProjectCatamaran/Drawnings/DrawningBoat.cs +++ b/ProjectCatamaran/ProjectCatamaran/Drawnings/DrawningBoat.cs @@ -73,7 +73,6 @@ public class DrawningBoat public DrawningBoat(int speed, double weight, Color bodyColor) : this() { EntityBoat = new EntityBoat(speed, weight, bodyColor); - } /// /// Конструктор @@ -84,7 +83,6 @@ public class DrawningBoat { _drawningBoatWidth = drawningBoatWidth; _drawningBoatHeight = drawningBoatHeight; - } /// /// установка границ поля -- 2.25.1 From 20fa07507f5ed86a404be2d69b4034ba33202a7c Mon Sep 17 00:00:00 2001 From: Nikita Date: Tue, 25 Feb 2025 21:01:20 +0400 Subject: [PATCH 9/9] delete useless comments --- .../CollectionGenericObjects/MassiveGenericObjects.cs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/MassiveGenericObjects.cs index e69bbfd..a9c52a4 100644 --- a/ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/MassiveGenericObjects.cs +++ b/ProjectCatamaran/ProjectCatamaran/CollectionGenericObjects/MassiveGenericObjects.cs @@ -26,7 +26,6 @@ public class MassiveGenericObjects : ICollectionGenericObjects where T : c } public T? Get(int position) { - //todo if (position >= 0 && position < Count) { return _collection[position]; @@ -36,7 +35,6 @@ public class MassiveGenericObjects : ICollectionGenericObjects where T : c } public int Insert(T obj) { - //todo for (int i = 0; i < Count; i++) { if (_collection[i] == null) @@ -49,13 +47,11 @@ public class MassiveGenericObjects : ICollectionGenericObjects where T : c return -1; } public int Insert(T obj, int position) - { - //todo + { if (!(position > 0 && position < _collection.Length)) { return -1; } - if (_collection[position] == null) _collection[position] = obj; else @@ -68,7 +64,6 @@ public class MassiveGenericObjects : ICollectionGenericObjects where T : c return i; } } - for (int i = position - 1; i >= 0; i--) { if (_collection[i] == null) @@ -86,7 +81,6 @@ public class MassiveGenericObjects : ICollectionGenericObjects where T : c { return null; } - T? deletedElement = _collection[position]; _collection[position] = null; return deletedElement; -- 2.25.1