From 9003758c6b8aea04f467ec9bf5abdc9ddca41ebb Mon Sep 17 00:00:00 2001 From: Nikita Date: Sun, 16 Feb 2025 15:32:34 +0400 Subject: [PATCH] 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