From 074c42f00fe51abbead7066235ee7838262b8e3a Mon Sep 17 00:00:00 2001
From: AlyonaFr <149268946+AlyonaFr@users.noreply.github.com>
Date: Fri, 22 Mar 2024 14:22:17 +0400
Subject: [PATCH 1/4] =?UTF-8?q?=D0=9A=D0=BE=D0=BB=D0=B5=D0=BA=D1=86=D0=B8?=
=?UTF-8?q?=D0=B8=20=D0=BE=D0=B1=D1=8A=D0=B5=D0=BA=D1=82=D0=BE=D0=B2?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../ICollectionGenericObjects.cs | 55 +++++++++
.../MassiveGenericObjects.cs | 114 ++++++++++++++++++
2 files changed, 169 insertions(+)
create mode 100644 ProjectCatamaran/ProjectCatamaran/CollectiongGenericObjects/ICollectionGenericObjects.cs
create mode 100644 ProjectCatamaran/ProjectCatamaran/CollectiongGenericObjects/MassiveGenericObjects.cs
diff --git a/ProjectCatamaran/ProjectCatamaran/CollectiongGenericObjects/ICollectionGenericObjects.cs b/ProjectCatamaran/ProjectCatamaran/CollectiongGenericObjects/ICollectionGenericObjects.cs
new file mode 100644
index 0000000..4d4562e
--- /dev/null
+++ b/ProjectCatamaran/ProjectCatamaran/CollectiongGenericObjects/ICollectionGenericObjects.cs
@@ -0,0 +1,55 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectCatamaran.CollectiongGenericObjects;
+
+///
+/// Интерфейс описания действий для набора хранимых объектов
+///
+///
+public interface ICollectionGenericObjects
+ where T : class
+{
+ ///
+ /// Количество объектов в коллекции
+ ///
+ int Count { get; }
+
+ ///
+ /// Установка максимального количества элементов
+ ///
+ int SetMaxCount { set; }
+
+ ///
+ /// Добавление объекта в коллекцию
+ ///
+ /// Добавляемый объект
+ /// true - вставка прошла удачно, false - вставка не удалась
+ int Insert(T obj);
+
+ ///
+ /// Добавление объекта в коллекцию на конкретную позицию
+ ///
+ /// Добавляемый объект
+ /// Позиция
+ /// true - вставка прошла удачно, false - вставка не удалась
+ int Insert(T obj, int position);
+
+ ///
+ /// Удаление объекта из коллекции с конкретной позиции
+ ///
+ /// Позиция
+ /// true - удаление прошло удачно, false - удаление не удалось
+ T? Remove(int position);
+
+ ///
+ /// Получение объекта по позиции
+ ///
+ /// Позиция
+ /// Объект
+ T? Get(int position);
+
+}
diff --git a/ProjectCatamaran/ProjectCatamaran/CollectiongGenericObjects/MassiveGenericObjects.cs b/ProjectCatamaran/ProjectCatamaran/CollectiongGenericObjects/MassiveGenericObjects.cs
new file mode 100644
index 0000000..9a6f02b
--- /dev/null
+++ b/ProjectCatamaran/ProjectCatamaran/CollectiongGenericObjects/MassiveGenericObjects.cs
@@ -0,0 +1,114 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectCatamaran.CollectiongGenericObjects;
+
+///
+/// Параметризованный набор объектов
+///
+///
+ 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)
+ {
+
+ if (position >= _collection.Length || position < 0)
+ {
+ return null;
+ }
+ return _collection[position];
+ }
+
+ ///
+ /// вставка в свободное место набора
+ ///
+ ///
+ ///
+ public int Insert(T obj)
+ {
+ int index = 0;
+ while (index < _collection.Length)
+ {
+ if (_collection[index] == null)
+ {
+ _collection[index] = obj;
+ return index;
+ }
+ index++;
+ }
+ return -1;
+ }
+
+ ///
+ /// проверка позиции
+ ///
+ ///
+ ///
+ ///
+ public int Insert(T obj, int position)
+ {
+ if (position >= _collection.Length || position < 0)
+ { return -1; }
+
+ if (_collection[position] == null)
+ {
+ _collection[position] = obj;
+ return position;
+ }
+ int index;
+
+ for (index = position + 1; index < _collection.Length; ++index)
+ {
+ if (_collection[index] == null)
+ {
+ _collection[position] = obj;
+ return position;
+ }
+ }
+
+ for (index = position - 1; index >= 0; --index)
+ {
+ if (_collection[index] == null)
+ {
+ _collection[position] = obj;
+ return position;
+ }
+ }
+ return -1;
+ }
+
+ public T? Remove(int position)
+ {
+ if (position >= _collection.Length || position < 0)
+ {
+ return null;
+ }
+ T drawningBoat = _collection[position];
+ _collection[position] = null;
+ return drawningBoat;
+ }
+}
--
2.25.1
From e3e989c41973d029311596bfd144b8ffd19365c0 Mon Sep 17 00:00:00 2001
From: AlyonaFr <149268946+AlyonaFr@users.noreply.github.com>
Date: Fri, 22 Mar 2024 17:15:07 +0400
Subject: [PATCH 2/4] =?UTF-8?q?=D0=9A=D0=BE=D0=BC=D0=BF=D0=B0=D0=BD=D0=B8?=
=?UTF-8?q?=D1=8F?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.gitignore | 1 +
.../ProjectCatamaran/Resources/Program.cs | 17 -----------------
2 files changed, 1 insertion(+), 17 deletions(-)
delete mode 100644 ProjectCatamaran/ProjectCatamaran/Resources/Program.cs
diff --git a/.gitignore b/.gitignore
index ca1c7a3..22a16f0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -398,3 +398,4 @@ FodyWeavers.xsd
# JetBrains Rider
*.sln.iml
+/ProjectCatamaran/ProjectCatamaran/Resources/Program.cs
diff --git a/ProjectCatamaran/ProjectCatamaran/Resources/Program.cs b/ProjectCatamaran/ProjectCatamaran/Resources/Program.cs
deleted file mode 100644
index 89a0c0b..0000000
--- a/ProjectCatamaran/ProjectCatamaran/Resources/Program.cs
+++ /dev/null
@@ -1,17 +0,0 @@
-namespace ProjectCatamaran.Resources
-{
- internal static class Program
- {
- ///
- /// The main entry point for the application.
- ///
- [STAThread]
- static void Main()
- {
- // To customize application configuration such as set high DPI settings or default font,
- // see https://aka.ms/applicationconfiguration.
- ApplicationConfiguration.Initialize();
- Application.Run(new FormCatamaran());
- }
- }
-}
\ No newline at end of file
--
2.25.1
From 1af20534c691032d72cd374f585ac6ab85690ecc Mon Sep 17 00:00:00 2001
From: AlyonaFr <149268946+AlyonaFr@users.noreply.github.com>
Date: Fri, 22 Mar 2024 17:15:15 +0400
Subject: [PATCH 3/4] =?UTF-8?q?=D0=9A=D0=BE=D0=BC=D0=BF=D0=B0=D0=BD=D0=B8?=
=?UTF-8?q?=D1=8F?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../AbstractCompany.cs | 104 ++++++++++
.../BoatSharingService.cs | 70 +++++++
.../FormBoatCollection.Designer.cs | 174 ++++++++++++++++
.../ProjectCatamaran/FormBoatCollection.cs | 190 ++++++++++++++++++
.../ProjectCatamaran/FormBoatCollection.resx | 120 +++++++++++
.../FormCatamaran.Designer.cs | 28 ---
.../ProjectCatamaran/FormCatamaran.cs | 60 ++----
ProjectCatamaran/ProjectCatamaran/Program.cs | 17 ++
8 files changed, 690 insertions(+), 73 deletions(-)
create mode 100644 ProjectCatamaran/ProjectCatamaran/CollectiongGenericObjects/AbstractCompany.cs
create mode 100644 ProjectCatamaran/ProjectCatamaran/CollectiongGenericObjects/BoatSharingService.cs
create mode 100644 ProjectCatamaran/ProjectCatamaran/FormBoatCollection.Designer.cs
create mode 100644 ProjectCatamaran/ProjectCatamaran/FormBoatCollection.cs
create mode 100644 ProjectCatamaran/ProjectCatamaran/FormBoatCollection.resx
create mode 100644 ProjectCatamaran/ProjectCatamaran/Program.cs
diff --git a/ProjectCatamaran/ProjectCatamaran/CollectiongGenericObjects/AbstractCompany.cs b/ProjectCatamaran/ProjectCatamaran/CollectiongGenericObjects/AbstractCompany.cs
new file mode 100644
index 0000000..3387242
--- /dev/null
+++ b/ProjectCatamaran/ProjectCatamaran/CollectiongGenericObjects/AbstractCompany.cs
@@ -0,0 +1,104 @@
+using ProjectCatamaran.Drawnings;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectCatamaran.CollectiongGenericObjects;
+
+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 int operator +(AbstractCompany company, DrawningBoat boat)
+ {
+ return company._collection?.Insert(boat) ?? 0;
+ }
+ ///
+ /// Перегрузка оператора удаления для класса
+ ///
+ /// Компания
+ /// Номер удаляемого объекта
+ ///
+ public static DrawningBoat operator -(AbstractCompany company, int position)
+ {
+ return company._collection?.Remove(position);
+ }
+ ///
+ /// Получение случайного объекта из коллекции
+ ///
+ ///
+ public DrawningBoat? GetRandomObject()
+ {
+ Random rnd = new();
+ return _collection?.Get(rnd.Next(GetMaxCount));
+ }
+ ///
+ /// Вывод всей коллекции
+ ///
+ ///
+ public Bitmap? Show()
+ {
+ Bitmap bitmap = new(_pictureWidth, _pictureHeight);
+ Graphics graphics = Graphics.FromImage(bitmap);
+ DrawBackgound(graphics);
+ SetObjectsPosition();
+ for (int i = 0; i < (_collection?.Count ?? 0); ++i)
+ {
+ DrawningBoat? obj = _collection?.Get(i);
+ obj?.DrawTransport(graphics);
+ }
+ return bitmap;
+ }
+ ///
+ /// Вывод заднего фона
+ ///
+ ///
+ protected abstract void DrawBackgound(Graphics g);
+ ///
+ /// Расстановка объектов
+ ///
+ protected abstract void SetObjectsPosition();
+}
diff --git a/ProjectCatamaran/ProjectCatamaran/CollectiongGenericObjects/BoatSharingService.cs b/ProjectCatamaran/ProjectCatamaran/CollectiongGenericObjects/BoatSharingService.cs
new file mode 100644
index 0000000..96723c5
--- /dev/null
+++ b/ProjectCatamaran/ProjectCatamaran/CollectiongGenericObjects/BoatSharingService.cs
@@ -0,0 +1,70 @@
+using ProjectCatamaran.Drawnings;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectCatamaran.CollectiongGenericObjects;
+
+///
+/// Реализация абстрактной компании - каршеринг
+///
+public class BoatSharingService : AbstractCompany
+{
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public BoatSharingService(int picWidth, int picHeight, ICollectionGenericObjects collection) : base(picWidth, picHeight, collection)
+ {
+ }
+
+ protected override void DrawBackgound(Graphics g)
+ {
+ int width = _pictureWidth / _placeSizeWidth;
+ int height = _pictureHeight / _placeSizeHeight;
+ Pen pen = new(Color.Black, 2);
+ for (int i = 0; i < width; i++)
+ {
+ for (int j = 0; j < height + 1; ++j)
+ {
+ g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth - 20, j * _placeSizeHeight);
+ g.DrawLine(pen, i * _placeSizeWidth + _placeSizeWidth - 20, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth - 20, j * _placeSizeHeight + _placeSizeHeight);
+ }
+ }
+ }
+
+ protected override void SetObjectsPosition()
+ {
+ int width = _pictureWidth / _placeSizeWidth;
+ int height = _pictureHeight / _placeSizeHeight;
+
+ int curWidth = 0;
+ int curHeight = 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(_placeSizeWidth * curWidth + 30, curHeight * _placeSizeHeight);
+ }
+
+ if (curWidth < width - 1)
+ curWidth++;
+ else
+ {
+ curWidth = 0;
+ curHeight++;
+ }
+
+ if (curHeight >= height)
+ {
+ return;
+ }
+ }
+ }
+}
diff --git a/ProjectCatamaran/ProjectCatamaran/FormBoatCollection.Designer.cs b/ProjectCatamaran/ProjectCatamaran/FormBoatCollection.Designer.cs
new file mode 100644
index 0000000..b96b5d1
--- /dev/null
+++ b/ProjectCatamaran/ProjectCatamaran/FormBoatCollection.Designer.cs
@@ -0,0 +1,174 @@
+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();
+ pictureBoxBoat = new PictureBox();
+ groupBoxTools.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)pictureBoxBoat).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(728, 0);
+ groupBoxTools.Name = "groupBoxTools";
+ groupBoxTools.Size = new Size(279, 633);
+ groupBoxTools.TabIndex = 0;
+ groupBoxTools.TabStop = false;
+ groupBoxTools.Text = "Инструменты";
+ //
+ // buttonRefresh
+ //
+ buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonRefresh.Location = new Point(16, 522);
+ buttonRefresh.Name = "buttonRefresh";
+ buttonRefresh.Size = new Size(250, 51);
+ 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(16, 408);
+ buttonGoToCheck.Name = "buttonGoToCheck";
+ buttonGoToCheck.Size = new Size(250, 51);
+ 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(16, 301);
+ buttonRemoveBoat.Name = "buttonRemoveBoat";
+ buttonRemoveBoat.Size = new Size(250, 51);
+ buttonRemoveBoat.TabIndex = 4;
+ buttonRemoveBoat.Text = "Удалить лодку";
+ buttonRemoveBoat.UseVisualStyleBackColor = true;
+ buttonRemoveBoat.Click += ButtonRemoveBoat_Click;
+ //
+ // maskedTextBoxPosition
+ //
+ maskedTextBoxPosition.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ maskedTextBoxPosition.Location = new Point(16, 258);
+ maskedTextBoxPosition.Mask = "00";
+ maskedTextBoxPosition.Name = "maskedTextBoxPosition";
+ maskedTextBoxPosition.Size = new Size(250, 27);
+ maskedTextBoxPosition.TabIndex = 3;
+ maskedTextBoxPosition.ValidatingType = typeof(int);
+ //
+ // buttonAddCatamaran
+ //
+ buttonAddCatamaran.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonAddCatamaran.Location = new Point(16, 174);
+ buttonAddCatamaran.Name = "buttonAddCatamaran";
+ buttonAddCatamaran.Size = new Size(250, 51);
+ 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(16, 117);
+ buttonAddBoat.Name = "buttonAddBoat";
+ buttonAddBoat.Size = new Size(250, 51);
+ 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(16, 30);
+ comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
+ comboBoxSelectorCompany.Size = new Size(250, 28);
+ comboBoxSelectorCompany.TabIndex = 0;
+ comboBoxSelectorCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged;
+ //
+ // pictureBoxBoat
+ //
+ pictureBoxBoat.Dock = DockStyle.Fill;
+ pictureBoxBoat.Location = new Point(0, 0);
+ pictureBoxBoat.Name = "pictureBoxBoat";
+ pictureBoxBoat.Size = new Size(728, 633);
+ pictureBoxBoat.TabIndex = 1;
+ pictureBoxBoat.TabStop = false;
+ //
+ // FormBoatCollection
+ //
+ AutoScaleDimensions = new SizeF(8F, 20F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(1007, 633);
+ Controls.Add(pictureBoxBoat);
+ Controls.Add(groupBoxTools);
+ Name = "FormBoatCollection";
+ Text = "Коллекция лодок";
+ groupBoxTools.ResumeLayout(false);
+ groupBoxTools.PerformLayout();
+ ((System.ComponentModel.ISupportInitialize)pictureBoxBoat).EndInit();
+ ResumeLayout(false);
+ }
+
+ #endregion
+
+ private GroupBox groupBoxTools;
+ private Button buttonAddCatamaran;
+ private Button buttonAddBoat;
+ private ComboBox comboBoxSelectorCompany;
+ private Button buttonRefresh;
+ private Button buttonGoToCheck;
+ private Button buttonRemoveBoat;
+ private MaskedTextBox maskedTextBoxPosition;
+ private PictureBox pictureBoxBoat;
+ }
+}
\ No newline at end of file
diff --git a/ProjectCatamaran/ProjectCatamaran/FormBoatCollection.cs b/ProjectCatamaran/ProjectCatamaran/FormBoatCollection.cs
new file mode 100644
index 0000000..888131c
--- /dev/null
+++ b/ProjectCatamaran/ProjectCatamaran/FormBoatCollection.cs
@@ -0,0 +1,190 @@
+using ProjectCatamaran.CollectiongGenericObjects;
+using ProjectCatamaran.Drawnings;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace ProjectCatamaran;
+
+///
+/// Форма работы с компанией и ее коллекцией
+///
+public partial class FormBoatCollection : Form
+{
+ ///
+ /// Компания
+ ///
+ private AbstractCompany? _company = null;
+
+ public FormBoatCollection()
+ {
+ InitializeComponent();
+ }
+
+ ///
+ /// Выбор компании
+ ///
+ ///
+ ///
+ private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ switch (comboBoxSelectorCompany.Text)
+ {
+ case "Хранилище":
+ _company = new BoatSharingService(pictureBoxBoat.Width,
+ pictureBoxBoat.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), GetColor(random), GetColor(random),
+ Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
+ break;
+ default:
+ return;
+ }
+ if (_company + drawningBoat != -1)
+ {
+ MessageBox.Show("объект добавлен");
+ pictureBoxBoat.Image = _company.Show();
+ }
+ else
+ {
+ MessageBox.Show("не удалось добавить объект");
+ }
+ }
+
+ ///
+ /// Получение цвета
+ ///
+ ///
+ ///
+ private 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.Yes)
+ {
+ return;
+ }
+ int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
+ if (_company - pos != null)
+ {
+ MessageBox.Show("объект удален");
+ pictureBoxBoat.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;
+ }
+
+ pictureBoxBoat.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 bc91fa0..a058366 100644
--- a/ProjectCatamaran/ProjectCatamaran/FormCatamaran.Designer.cs
+++ b/ProjectCatamaran/ProjectCatamaran/FormCatamaran.Designer.cs
@@ -29,12 +29,10 @@
private void InitializeComponent()
{
pictureBoxCatamaran = new PictureBox();
- buttonCreateCatamaran = new Button();
buttonUp = new Button();
buttonLeft = new Button();
buttonDown = new Button();
buttonRight = new Button();
- buttonCreatBoat = new Button();
comboBoxStrategy = new ComboBox();
buttonStrategyStep = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxCatamaran).BeginInit();
@@ -49,17 +47,6 @@
pictureBoxCatamaran.TabIndex = 0;
pictureBoxCatamaran.TabStop = false;
//
- // buttonCreateCatamaran
- //
- buttonCreateCatamaran.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
- buttonCreateCatamaran.Location = new Point(12, 409);
- buttonCreateCatamaran.Name = "buttonCreateCatamaran";
- buttonCreateCatamaran.Size = new Size(203, 29);
- buttonCreateCatamaran.TabIndex = 1;
- buttonCreateCatamaran.Text = "Создать катамаран";
- buttonCreateCatamaran.UseVisualStyleBackColor = true;
- buttonCreateCatamaran.Click += ButtonCreateCatamaran_Click;
- //
// buttonUp
//
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
@@ -110,17 +97,6 @@
buttonRight.UseVisualStyleBackColor = false;
buttonRight.Click += ButtonMove_Click;
//
- // buttonCreatBoat
- //
- buttonCreatBoat.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
- buttonCreatBoat.Location = new Point(233, 409);
- buttonCreatBoat.Name = "buttonCreatBoat";
- buttonCreatBoat.Size = new Size(203, 29);
- buttonCreatBoat.TabIndex = 6;
- buttonCreatBoat.Text = "Создать лодку";
- buttonCreatBoat.UseVisualStyleBackColor = true;
- buttonCreatBoat.Click += ButtonCreatBoat_Click;
- //
// comboBoxStrategy
//
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
@@ -148,12 +124,10 @@
ClientSize = new Size(800, 450);
Controls.Add(buttonStrategyStep);
Controls.Add(comboBoxStrategy);
- Controls.Add(buttonCreatBoat);
Controls.Add(buttonRight);
Controls.Add(buttonDown);
Controls.Add(buttonLeft);
Controls.Add(buttonUp);
- Controls.Add(buttonCreateCatamaran);
Controls.Add(pictureBoxCatamaran);
Name = "FormCatamaran";
Text = "Катамаран";
@@ -164,12 +138,10 @@
#endregion
private PictureBox pictureBoxCatamaran;
- private Button buttonCreateCatamaran;
private Button buttonUp;
private Button buttonLeft;
private Button buttonDown;
private Button buttonRight;
- private Button buttonCreatBoat;
private ComboBox comboBoxStrategy;
private Button buttonStrategyStep;
}
diff --git a/ProjectCatamaran/ProjectCatamaran/FormCatamaran.cs b/ProjectCatamaran/ProjectCatamaran/FormCatamaran.cs
index 8b7a425..c746878 100644
--- a/ProjectCatamaran/ProjectCatamaran/FormCatamaran.cs
+++ b/ProjectCatamaran/ProjectCatamaran/FormCatamaran.cs
@@ -24,6 +24,21 @@ namespace ProjectCatamaran
///
private AbstractStrategy? _strategy;
+ ///
+ /// Получение объекта
+ ///
+ public DrawningBoat SetBoat
+ {
+ set
+ {
+ _drawningBoat = value;
+ _drawningBoat.SetPictureSize(pictureBoxCatamaran.Width, pictureBoxCatamaran.Height);
+ comboBoxStrategy.Enabled = true;
+ _strategy = null;
+ Draw();
+ }
+ }
+
///
/// Конструктор формы
@@ -34,51 +49,6 @@ namespace ProjectCatamaran
_strategy = null;
}
- ///
- /// Создание объекта класса-перемещения
- ///
- ///
- 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)), 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 ButtonCreatBoat_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningBoat));
///
/// Метод прорисовки катамарана
diff --git a/ProjectCatamaran/ProjectCatamaran/Program.cs b/ProjectCatamaran/ProjectCatamaran/Program.cs
new file mode 100644
index 0000000..59feea7
--- /dev/null
+++ b/ProjectCatamaran/ProjectCatamaran/Program.cs
@@ -0,0 +1,17 @@
+namespace ProjectCatamaran
+{
+ internal static class Program
+ {
+ ///
+ /// The main entry point for the application.
+ ///
+ [STAThread]
+ static void Main()
+ {
+ // To customize application configuration such as set high DPI settings or default font,
+ // see https://aka.ms/applicationconfiguration.
+ ApplicationConfiguration.Initialize();
+ Application.Run(new FormBoatCollection());
+ }
+ }
+}
\ No newline at end of file
--
2.25.1
From bc5127d41017e7f072acb410e7402d482b6f0037 Mon Sep 17 00:00:00 2001
From: AlyonaFr <149268946+AlyonaFr@users.noreply.github.com>
Date: Wed, 3 Apr 2024 22:10:52 +0400
Subject: [PATCH 4/4] LabWork03
---
...SharingService.cs => BoatHarborService.cs} | 23 +++++++++----------
.../FormBoatCollection.Designer.cs | 8 +++----
.../ProjectCatamaran/FormBoatCollection.cs | 10 ++++----
3 files changed, 21 insertions(+), 20 deletions(-)
rename ProjectCatamaran/ProjectCatamaran/CollectiongGenericObjects/{BoatSharingService.cs => BoatHarborService.cs} (66%)
diff --git a/ProjectCatamaran/ProjectCatamaran/CollectiongGenericObjects/BoatSharingService.cs b/ProjectCatamaran/ProjectCatamaran/CollectiongGenericObjects/BoatHarborService.cs
similarity index 66%
rename from ProjectCatamaran/ProjectCatamaran/CollectiongGenericObjects/BoatSharingService.cs
rename to ProjectCatamaran/ProjectCatamaran/CollectiongGenericObjects/BoatHarborService.cs
index 96723c5..b443156 100644
--- a/ProjectCatamaran/ProjectCatamaran/CollectiongGenericObjects/BoatSharingService.cs
+++ b/ProjectCatamaran/ProjectCatamaran/CollectiongGenericObjects/BoatHarborService.cs
@@ -10,7 +10,7 @@ namespace ProjectCatamaran.CollectiongGenericObjects;
///
/// Реализация абстрактной компании - каршеринг
///
-public class BoatSharingService : AbstractCompany
+public class BoatHarborService : AbstractCompany
{
///
///
@@ -18,7 +18,7 @@ public class BoatSharingService : AbstractCompany
///
///
///
- public BoatSharingService(int picWidth, int picHeight, ICollectionGenericObjects collection) : base(picWidth, picHeight, collection)
+ public BoatHarborService(int picWidth, int picHeight, ICollectionGenericObjects collection) : base(picWidth, picHeight, collection)
{
}
@@ -26,14 +26,14 @@ public class BoatSharingService : AbstractCompany
{
int width = _pictureWidth / _placeSizeWidth;
int height = _pictureHeight / _placeSizeHeight;
- Pen pen = new(Color.Black, 2);
- for (int i = 0; i < width; i++)
+ Pen pen = new(Color.Black, 4);
+ for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
{
- for (int j = 0; j < height + 1; ++j)
+ for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
{
- g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth - 20, j * _placeSizeHeight);
- g.DrawLine(pen, i * _placeSizeWidth + _placeSizeWidth - 20, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth - 20, j * _placeSizeHeight + _placeSizeHeight);
+ g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight + 5, i * _placeSizeWidth + _placeSizeWidth - 90, j * _placeSizeHeight + 5);
}
+ g.DrawLine(pen, i * _placeSizeWidth,0, i * _placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight + 5);
}
}
@@ -43,14 +43,14 @@ public class BoatSharingService : AbstractCompany
int height = _pictureHeight / _placeSizeHeight;
int curWidth = 0;
- int curHeight = 0;
+ int curHeight = height - 1;
for (int i = 0; i < (_collection?.Count ?? 0); i++)
{
if (_collection.Get(i) != null)
{
_collection.Get(i).SetPictureSize(_pictureWidth, _pictureHeight);
- _collection.Get(i).SetPosition(_placeSizeWidth * curWidth + 30, curHeight * _placeSizeHeight);
+ _collection.Get(i).SetPosition(_placeSizeWidth * curWidth + 10, curHeight * _placeSizeHeight + 5);
}
if (curWidth < width - 1)
@@ -58,10 +58,9 @@ public class BoatSharingService : AbstractCompany
else
{
curWidth = 0;
- curHeight++;
+ curHeight--;
}
-
- if (curHeight >= height)
+ if (curHeight < 0)
{
return;
}
diff --git a/ProjectCatamaran/ProjectCatamaran/FormBoatCollection.Designer.cs b/ProjectCatamaran/ProjectCatamaran/FormBoatCollection.Designer.cs
index b96b5d1..9e0b36c 100644
--- a/ProjectCatamaran/ProjectCatamaran/FormBoatCollection.Designer.cs
+++ b/ProjectCatamaran/ProjectCatamaran/FormBoatCollection.Designer.cs
@@ -51,9 +51,9 @@
groupBoxTools.Controls.Add(buttonAddBoat);
groupBoxTools.Controls.Add(comboBoxSelectorCompany);
groupBoxTools.Dock = DockStyle.Right;
- groupBoxTools.Location = new Point(728, 0);
+ groupBoxTools.Location = new Point(849, 0);
groupBoxTools.Name = "groupBoxTools";
- groupBoxTools.Size = new Size(279, 633);
+ groupBoxTools.Size = new Size(279, 629);
groupBoxTools.TabIndex = 0;
groupBoxTools.TabStop = false;
groupBoxTools.Text = "Инструменты";
@@ -140,7 +140,7 @@
pictureBoxBoat.Dock = DockStyle.Fill;
pictureBoxBoat.Location = new Point(0, 0);
pictureBoxBoat.Name = "pictureBoxBoat";
- pictureBoxBoat.Size = new Size(728, 633);
+ pictureBoxBoat.Size = new Size(849, 629);
pictureBoxBoat.TabIndex = 1;
pictureBoxBoat.TabStop = false;
//
@@ -148,7 +148,7 @@
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
- ClientSize = new Size(1007, 633);
+ ClientSize = new Size(1128, 629);
Controls.Add(pictureBoxBoat);
Controls.Add(groupBoxTools);
Name = "FormBoatCollection";
diff --git a/ProjectCatamaran/ProjectCatamaran/FormBoatCollection.cs b/ProjectCatamaran/ProjectCatamaran/FormBoatCollection.cs
index 888131c..e185b94 100644
--- a/ProjectCatamaran/ProjectCatamaran/FormBoatCollection.cs
+++ b/ProjectCatamaran/ProjectCatamaran/FormBoatCollection.cs
@@ -37,7 +37,7 @@ public partial class FormBoatCollection : Form
switch (comboBoxSelectorCompany.Text)
{
case "Хранилище":
- _company = new BoatSharingService(pictureBoxBoat.Width,
+ _company = new BoatHarborService(pictureBoxBoat.Width,
pictureBoxBoat.Height, new MassiveGenericObjects());
break;
}
@@ -123,19 +123,21 @@ public partial class FormBoatCollection : Form
{
return;
}
- if (MessageBox.Show("удалить объект?", "удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
+
+ if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
{
return;
}
+
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
if (_company - pos != null)
{
- MessageBox.Show("объект удален");
+ MessageBox.Show("Объект удален");
pictureBoxBoat.Image = _company.Show();
}
else
{
- MessageBox.Show("не удалось удалить объект");
+ MessageBox.Show("Не удалось удалить объект");
}
}
--
2.25.1