From e3253aeb745ebf9af34c1881ef48a3243b1a622a Mon Sep 17 00:00:00 2001 From: Petek1234 <149153720+Petek1234@users.noreply.github.com> Date: Tue, 2 Apr 2024 18:32:31 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BB=D0=B0=D0=B1=D0=B0=203=20=D1=81=20=D0=BD?= =?UTF-8?q?=D0=B0=D1=80=D0=B5=D0=BA=D0=B0=D0=BD=D0=B8=D1=8F=D0=BC=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbstractCompany.cs | 121 ++++++++++++ .../CollectionGenericObjects/BoatHarbor.cs | 55 ++++++ .../ICollectionGenericObjects.cs | 54 ++++++ .../MassiveGenericObjects.cs | 88 +++++++++ laba 0/laba 0/Drawnings/DirectionType.cs | 2 +- laba 0/laba 0/Drawnings/DrawningB.cs | 4 +- laba 0/laba 0/Drawnings/DrawningBoat.cs | 4 +- laba 0/laba 0/Entities/EntityB.cs | 2 +- laba 0/laba 0/Entities/EntityBoat.cs | 2 +- laba 0/laba 0/FormBoat.Designer.cs | 30 +-- laba 0/laba 0/FormBoat.cs | 68 ++----- laba 0/laba 0/FormBoatCollection.Designer.cs | 173 ++++++++++++++++++ laba 0/laba 0/FormBoatCollection.cs | 161 ++++++++++++++++ laba 0/laba 0/FormBoatCollection.resx | 120 ++++++++++++ laba 0/laba 0/MotorBoat.csproj | 2 +- .../MovementStrategy/AbstractStrategy.cs | 2 +- .../MovementStrategy/IMoveableObject.cs | 2 +- .../laba 0/MovementStrategy/MoveToBorder.cs | 2 +- .../laba 0/MovementStrategy/MoveToCenter.cs | 2 +- laba 0/laba 0/MovementStrategy/MoveableB.cs | 4 +- .../MovementStrategy/MovementDirection.cs | 2 +- .../MovementStrategy/ObjectParameters.cs | 2 +- .../laba 0/MovementStrategy/StrategyStatus.cs | 2 +- laba 0/laba 0/Program.cs | 4 +- .../laba 0/Properties/Resources.Designer.cs | 4 +- 25 files changed, 809 insertions(+), 103 deletions(-) create mode 100644 laba 0/laba 0/CollectionGenericObjects/AbstractCompany.cs create mode 100644 laba 0/laba 0/CollectionGenericObjects/BoatHarbor.cs create mode 100644 laba 0/laba 0/CollectionGenericObjects/ICollectionGenericObjects.cs create mode 100644 laba 0/laba 0/CollectionGenericObjects/MassiveGenericObjects.cs create mode 100644 laba 0/laba 0/FormBoatCollection.Designer.cs create mode 100644 laba 0/laba 0/FormBoatCollection.cs create mode 100644 laba 0/laba 0/FormBoatCollection.resx diff --git a/laba 0/laba 0/CollectionGenericObjects/AbstractCompany.cs b/laba 0/laba 0/CollectionGenericObjects/AbstractCompany.cs new file mode 100644 index 0000000..8d04bfe --- /dev/null +++ b/laba 0/laba 0/CollectionGenericObjects/AbstractCompany.cs @@ -0,0 +1,121 @@ +using MotorBoat.Drawning; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MotorBoat.CollectionGenericObjects; + +/// +/// Абстракция компании, хранящий коллекцию автомобилей +/// +public abstract class AbstractCompany +{ + /// + /// Размер места (ширина) + /// + protected readonly int _placeSizeWidth = 150; + + /// + /// Размер места (высота) + /// + protected readonly int _placeSizeHeight = 70; + + /// + /// Ширина окна + /// + 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, DrawningB B) + { + return company._collection?.Insert(B) ?? false; + } + + /// + /// Перегрузка оператора удаления для класса + /// + /// Компания + /// Номер удаляемого объекта + /// + public static bool operator -(AbstractCompany company, int position) + { + return company._collection?.Remove(position) ?? false; + } + + /// + /// Получение случайного объекта из коллекции + /// + /// + public DrawningB? GetRandomObject() + { + Random rnd = new(); + return _collection?.Get(rnd.Next(GetMaxCount)); + } + + /// + /// Вывод всей коллекции + /// + /// + public Bitmap? Show() + { + Bitmap bitmap = new(_pictureWidth, _pictureHeight); + Graphics graphics = Graphics.FromImage(bitmap); + DrawBackground(graphics); + SetObjectsPosition(); + for (int i = 0; i < (_collection?.Count ?? 0); ++i) + { + DrawningB? obj = _collection?.Get(i); + obj?.DrawTransport(graphics); + } + return bitmap; + } + + /// + /// Вывод заднего фона + /// + /// + protected abstract void DrawBackground(Graphics g); + + /// + /// Расстановка объектов + /// + protected abstract void SetObjectsPosition(); +} + \ No newline at end of file diff --git a/laba 0/laba 0/CollectionGenericObjects/BoatHarbor.cs b/laba 0/laba 0/CollectionGenericObjects/BoatHarbor.cs new file mode 100644 index 0000000..8d38026 --- /dev/null +++ b/laba 0/laba 0/CollectionGenericObjects/BoatHarbor.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using MotorBoat.Drawning; + +namespace MotorBoat.CollectionGenericObjects; + +public class BoatHarbor : AbstractCompany +{ + public BoatHarbor(int picWidth, int picHeight, ICollectionGenericObjects collection) : base(picWidth, picHeight, collection) + { + } + + Pen black = new Pen(Color.Black); + + protected override void DrawBackground(Graphics g) + { + for (int i = _pictureHeight - 1; i >= 0; i -= _placeSizeHeight) + { + g.DrawLine(black, _pictureWidth - ((int)(_pictureWidth / _placeSizeWidth) * _placeSizeWidth), i, _pictureWidth, i); + + for (int j = _pictureWidth - 1; j >= 0; j -= _placeSizeWidth) + { + g.DrawLine(black, j, i, j, i - _placeSizeHeight + 20); + } + } + } + + protected override void SetObjectsPosition() + { + { + int posX = -1; + int posY = 0; + for (int i = 0; i < _collection?.Count; i++) + { + if (_collection.Get(i) != null) + { + _collection?.Get(i)?.SetPictureSize(_pictureWidth, _pictureHeight); + _collection?.Get(i)?.SetPosition(posX * _placeSizeWidth +200, posY * _placeSizeHeight + 15); + } + + posX++; + if (posX >= _pictureWidth / _placeSizeWidth - 1) + { + posY++; + posX = -1; + } + if (posY >= _pictureHeight / _placeSizeHeight-1) { return; } + } + + } + } +} diff --git a/laba 0/laba 0/CollectionGenericObjects/ICollectionGenericObjects.cs b/laba 0/laba 0/CollectionGenericObjects/ICollectionGenericObjects.cs new file mode 100644 index 0000000..5a9ed66 --- /dev/null +++ b/laba 0/laba 0/CollectionGenericObjects/ICollectionGenericObjects.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MotorBoat.CollectionGenericObjects; + +/// +/// Интерфейс описания действий для набора хранимых объектов +/// +/// Параметр: ограничение - ссылочный тип +public interface ICollectionGenericObjects + where T : class +{ + /// + /// Количество объектов в коллекции + /// + int Count { get; } + + /// + /// Установка максимального количества элементов + /// + int SetMaxCount { set; } + + /// + /// Добавление объекта в коллекцию + /// + /// Добавляемый объект + /// true - вставка прошла удачно, false - вставка неудалась + bool Insert(T obj); + + /// + /// Добавление объекта в коллекцию на конкретную позицию + /// + /// Добавляемый объект + /// Позиция + /// true - вставка прошла удачно, false - вставка неудалась + bool Insert(T obj, int position); + + /// + /// Удаление объекта из коллекции с конкретной позиции + /// + /// Позиция + /// true - удаление прошло удачно, false - удаление не удалось + bool Remove(int position); + + /// + /// Получение объекта по позиции + /// + /// Позиция + /// Объект + T? Get(int position); +} diff --git a/laba 0/laba 0/CollectionGenericObjects/MassiveGenericObjects.cs b/laba 0/laba 0/CollectionGenericObjects/MassiveGenericObjects.cs new file mode 100644 index 0000000..3be0baf --- /dev/null +++ b/laba 0/laba 0/CollectionGenericObjects/MassiveGenericObjects.cs @@ -0,0 +1,88 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MotorBoat.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) + { + if (position < 0 || position >= _collection.Length) return null; + return _collection[position]; + } + + public bool Insert(T obj) + { + for (int i = 0; i < _collection.Length; i++) + { + if (_collection[i] == null) + { + _collection[i] = obj; + return true; + } + } + return false; + } + + public bool Insert(T obj, int position) + { + + if (position < 0 || position >= _collection.Length) { return false; } + + if (_collection[position] == null) + { + _collection[position] = obj; + return true; + } + else + { + for (int i = position + 1; i < _collection.Length; 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) + { + if (position < 0 || position >= _collection.Length) { return false; } + + _collection[position] = null; + return true; + } +} diff --git a/laba 0/laba 0/Drawnings/DirectionType.cs b/laba 0/laba 0/Drawnings/DirectionType.cs index 7191c03..13a05cd 100644 --- a/laba 0/laba 0/Drawnings/DirectionType.cs +++ b/laba 0/laba 0/Drawnings/DirectionType.cs @@ -1,4 +1,4 @@ -namespace laba_0.Drawning; +namespace MotorBoat.Drawning; /// /// направление перемещения diff --git a/laba 0/laba 0/Drawnings/DrawningB.cs b/laba 0/laba 0/Drawnings/DrawningB.cs index 91dd165..f0c1b9b 100644 --- a/laba 0/laba 0/Drawnings/DrawningB.cs +++ b/laba 0/laba 0/Drawnings/DrawningB.cs @@ -3,9 +3,9 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -using laba_0.Entities; +using MotorBoat.Entities; -namespace laba_0.Drawning; +namespace MotorBoat.Drawning; public class DrawningB { diff --git a/laba 0/laba 0/Drawnings/DrawningBoat.cs b/laba 0/laba 0/Drawnings/DrawningBoat.cs index 2d6346b..03dcbac 100644 --- a/laba 0/laba 0/Drawnings/DrawningBoat.cs +++ b/laba 0/laba 0/Drawnings/DrawningBoat.cs @@ -1,6 +1,6 @@ -using laba_0.Entities; +using MotorBoat.Entities; -namespace laba_0.Drawning; +namespace MotorBoat.Drawning; /// /// класс, отвечающий за прорисовку и перемещение объекта-сущности diff --git a/laba 0/laba 0/Entities/EntityB.cs b/laba 0/laba 0/Entities/EntityB.cs index 441580e..cbdca33 100644 --- a/laba 0/laba 0/Entities/EntityB.cs +++ b/laba 0/laba 0/Entities/EntityB.cs @@ -1,4 +1,4 @@ -namespace laba_0.Entities; +namespace MotorBoat.Entities; /// /// Класс-сущность "Катер" diff --git a/laba 0/laba 0/Entities/EntityBoat.cs b/laba 0/laba 0/Entities/EntityBoat.cs index 12d10ba..00cde20 100644 --- a/laba 0/laba 0/Entities/EntityBoat.cs +++ b/laba 0/laba 0/Entities/EntityBoat.cs @@ -1,4 +1,4 @@ -namespace laba_0.Entities; +namespace MotorBoat.Entities; /// /// Класс-сущность "Катер" diff --git a/laba 0/laba 0/FormBoat.Designer.cs b/laba 0/laba 0/FormBoat.Designer.cs index 8ca6ab1..3d3678a 100644 --- a/laba 0/laba 0/FormBoat.Designer.cs +++ b/laba 0/laba 0/FormBoat.Designer.cs @@ -1,4 +1,4 @@ -namespace laba_0; +namespace MotorBoat; partial class FormBoat { @@ -30,12 +30,10 @@ partial class FormBoat { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormBoat)); pictureBoxBoat = new PictureBox(); - buttonCreateBoat = new Button(); buttonRight = new Button(); buttonDown = new Button(); buttonUp = new Button(); buttonLeft = new Button(); - ButtonCreateB = new Button(); comboBoxStrategy = new ComboBox(); buttonStrategyStep = new Button(); ((System.ComponentModel.ISupportInitialize)pictureBoxBoat).BeginInit(); @@ -53,17 +51,6 @@ partial class FormBoat pictureBoxBoat.TabStop = false; pictureBoxBoat.Click += ButtonMove_Click; // - // buttonCreateBoat - // - buttonCreateBoat.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonCreateBoat.Location = new Point(12, 327); - buttonCreateBoat.Name = "buttonCreateBoat"; - buttonCreateBoat.Size = new Size(153, 23); - buttonCreateBoat.TabIndex = 1; - buttonCreateBoat.Text = "Создать катер"; - buttonCreateBoat.UseVisualStyleBackColor = true; - buttonCreateBoat.Click += ButtonCreateBoat_Click; - // // buttonRight // buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; @@ -112,17 +99,6 @@ partial class FormBoat buttonLeft.UseVisualStyleBackColor = true; buttonLeft.Click += ButtonMove_Click; // - // ButtonCreateB - // - ButtonCreateB.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - ButtonCreateB.Location = new Point(171, 327); - ButtonCreateB.Name = "ButtonCreateB"; - ButtonCreateB.Size = new Size(147, 23); - ButtonCreateB.TabIndex = 6; - ButtonCreateB.Text = "Создать простой катер"; - ButtonCreateB.UseVisualStyleBackColor = true; - ButtonCreateB.Click += ButtonCreateB_Click; - // // comboBoxStrategy // comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList; @@ -150,12 +126,10 @@ partial class FormBoat ClientSize = new Size(640, 359); Controls.Add(buttonStrategyStep); Controls.Add(comboBoxStrategy); - Controls.Add(ButtonCreateB); Controls.Add(buttonRight); Controls.Add(buttonDown); Controls.Add(buttonLeft); Controls.Add(buttonUp); - Controls.Add(buttonCreateBoat); Controls.Add(pictureBoxBoat); Name = "FormBoat"; Text = "FormBoat"; @@ -167,12 +141,10 @@ partial class FormBoat #endregion private PictureBox pictureBoxBoat; - private Button buttonCreateBoat; private Button buttonRight; private Button buttonDown; private Button buttonUp; private Button buttonLeft; - private Button ButtonCreateB; private ComboBox comboBoxStrategy; private Button buttonStrategyStep; } \ No newline at end of file diff --git a/laba 0/laba 0/FormBoat.cs b/laba 0/laba 0/FormBoat.cs index c3e1ed6..0b70569 100644 --- a/laba 0/laba 0/FormBoat.cs +++ b/laba 0/laba 0/FormBoat.cs @@ -7,10 +7,10 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; -using laba_0.Drawning; -using laba_0.MovementStrategy; +using MotorBoat.Drawning; +using MotorBoat.MovementStrategy; -namespace laba_0; +namespace MotorBoat; public partial class FormBoat : Form { @@ -24,6 +24,18 @@ public partial class FormBoat : Form /// private AbstractStrategy? _strategy; + public DrawningB SetB + { + set + { + _drawningB = value; + _drawningB.SetPictureSize(pictureBoxBoat.Width, pictureBoxBoat.Height); + comboBoxStrategy.Enabled = true; + _strategy = null; + Draw(); + } + } + /// /// конструктор формы /// @@ -49,56 +61,6 @@ public partial class FormBoat : Form pictureBoxBoat.Image = bmp; } - /// - /// Создание объекта класса-перемещения - /// - /// Тип создаваемого объекта - private void CreateObject(string type) - { - Random random = new(); - switch (type) - { - case nameof(DrawningB): - _drawningB = new DrawningB(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(DrawningBoat): - _drawningB = new DrawningBoat(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; - } - _drawningB.SetPictureSize(pictureBoxBoat.Width, pictureBoxBoat.Height); - _drawningB.SetPosition(random.Next(10, 100), random.Next(10, 100)); - _strategy = null; - comboBoxStrategy.Enabled = true; - Draw(); - } - - /// - /// Обработка создания кнопки "создать катер" - /// - /// - /// - private void ButtonCreateBoat_Click(object sender, EventArgs e) - { - CreateObject(nameof(DrawningBoat)); - } - - /// - /// Обработка создания кнопки "создать простой катер" - /// - /// - /// - private void ButtonCreateB_Click(object sender, EventArgs e) - { - CreateObject(nameof(DrawningB)); - } - - /// /// Перемещение объекта по форме (нажатие кнопок навигации) /// diff --git a/laba 0/laba 0/FormBoatCollection.Designer.cs b/laba 0/laba 0/FormBoatCollection.Designer.cs new file mode 100644 index 0000000..4687a51 --- /dev/null +++ b/laba 0/laba 0/FormBoatCollection.Designer.cs @@ -0,0 +1,173 @@ +namespace MotorBoat +{ + 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(); + maskedTextBox = new MaskedTextBox(); + buttonAddMotorBoat = 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(maskedTextBox); + groupBoxTools.Controls.Add(buttonAddMotorBoat); + groupBoxTools.Controls.Add(buttonAddBoat); + groupBoxTools.Controls.Add(comboBoxSelectorCompany); + groupBoxTools.Dock = DockStyle.Right; + groupBoxTools.Location = new Point(489, 0); + groupBoxTools.Name = "groupBoxTools"; + groupBoxTools.Size = new Size(194, 411); + groupBoxTools.TabIndex = 0; + groupBoxTools.TabStop = false; + groupBoxTools.Text = "Инструменты"; + // + // buttonRefresh + // + buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonRefresh.Location = new Point(3, 320); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(185, 27); + 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(3, 260); + buttonGoToCheck.Name = "buttonGoToCheck"; + buttonGoToCheck.Size = new Size(185, 27); + 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(3, 206); + buttonRemoveBoat.Name = "buttonRemoveBoat"; + buttonRemoveBoat.Size = new Size(185, 27); + buttonRemoveBoat.TabIndex = 4; + buttonRemoveBoat.Text = "Удалить катер\r\n "; + buttonRemoveBoat.UseVisualStyleBackColor = true; + buttonRemoveBoat.Click += buttonRemoveBoat_Click; + // + // maskedTextBox + // + maskedTextBox.Location = new Point(3, 177); + maskedTextBox.Mask = "00"; + maskedTextBox.Name = "maskedTextBox"; + maskedTextBox.Size = new Size(185, 23); + maskedTextBox.TabIndex = 3; + maskedTextBox.ValidatingType = typeof(int); + // + // buttonAddMotorBoat + // + buttonAddMotorBoat.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonAddMotorBoat.Location = new Point(3, 113); + buttonAddMotorBoat.Name = "buttonAddMotorBoat"; + buttonAddMotorBoat.Size = new Size(185, 38); + buttonAddMotorBoat.TabIndex = 2; + buttonAddMotorBoat.Text = "Добавление моторного катера"; + buttonAddMotorBoat.UseVisualStyleBackColor = true; + buttonAddMotorBoat.Click += buttonAddMotorBoat_Click; + // + // buttonAddBoat + // + buttonAddBoat.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonAddBoat.Location = new Point(3, 69); + buttonAddBoat.Name = "buttonAddBoat"; + buttonAddBoat.Size = new Size(185, 38); + buttonAddBoat.TabIndex = 1; + buttonAddBoat.Text = "Добавление катера"; + buttonAddBoat.UseVisualStyleBackColor = true; + buttonAddBoat.Click += buttonBoat_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(3, 22); + comboBoxSelectorCompany.Name = "comboBoxSelectorCompany"; + comboBoxSelectorCompany.Size = new Size(185, 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(489, 411); + pictureBox.TabIndex = 1; + pictureBox.TabStop = false; + // + // FormBoatCollection + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(683, 411); + 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 ComboBox comboBoxSelectorCompany; + private Button buttonAddMotorBoat; + private Button buttonAddBoat; + private PictureBox pictureBox; + private Button buttonRemoveBoat; + private MaskedTextBox maskedTextBox; + private Button buttonRefresh; + private Button buttonGoToCheck; + } +} \ No newline at end of file diff --git a/laba 0/laba 0/FormBoatCollection.cs b/laba 0/laba 0/FormBoatCollection.cs new file mode 100644 index 0000000..1974650 --- /dev/null +++ b/laba 0/laba 0/FormBoatCollection.cs @@ -0,0 +1,161 @@ +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 MotorBoat.CollectionGenericObjects; +using MotorBoat.Drawning; + +namespace MotorBoat; + +/// +/// Форма работы с компанией и ее коллекцией +/// +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 BoatHarbor(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects()); + break; + } + } + + /// + /// Создание объекта класса-перемещения + /// + /// + private void CreateObject(string type) + { + if (_company == null) return; + + Random random = new(); + DrawningB drawningB; + switch (type) + { + case nameof(DrawningB): + drawningB = new DrawningB(random.Next(100, 300), random.Next(1000, 3000), GetColor(random)); + drawningB.SetPictureSize(pictureBox.Width, pictureBox.Height); + break; + case nameof(DrawningBoat): + drawningB = new DrawningBoat(random.Next(100, 300), random.Next(1000, 3000), + GetColor(random), GetColor(random), + Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2))); + drawningB.SetPictureSize(pictureBox.Width, pictureBox.Height); + break; + default: + return; + } + + if (_company + drawningB) + { + MessageBox.Show("Объект добавлен"); + pictureBox.Image = _company.Show(); + } + else + { + MessageBox.Show("Объект не удалось добавить"); + } + } + + /// + /// Получение цвета + /// + /// + /// + private static Color GetColor(Random rnd) + { + Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)); + ColorDialog dialog = new(); + if (dialog.ShowDialog() == DialogResult.OK) + { + color = dialog.Color; + } + + return color; + } + + private void buttonBoat_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningB)); + + private void buttonAddMotorBoat_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningBoat)); + + private void buttonRemoveBoat_Click(object sender, EventArgs e) + { + if (_company == null || string.IsNullOrEmpty(maskedTextBox.Text)) return; + + if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) return; + + int pos = Convert.ToInt32(maskedTextBox.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; + } + + DrawningB? B = null; + int counter = 100; + while (B == null) + { + B = _company.GetRandomObject(); + counter--; + if (counter <= 0) + { + break; + } + } + + if (B == null) + { + return; + } + + FormBoat form = new() + { + SetB = B + }; + form.ShowDialog(); + } + + private void buttonRefresh_Click(object sender, EventArgs e) + { + if (_company == null) return; + + pictureBox.Image = _company.Show(); + } +} diff --git a/laba 0/laba 0/FormBoatCollection.resx b/laba 0/laba 0/FormBoatCollection.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/laba 0/laba 0/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/laba 0/laba 0/MotorBoat.csproj b/laba 0/laba 0/MotorBoat.csproj index 877be94..1a83870 100644 --- a/laba 0/laba 0/MotorBoat.csproj +++ b/laba 0/laba 0/MotorBoat.csproj @@ -3,7 +3,7 @@ WinExe net6.0-windows - laba_0 + MotorBoat enable true enable diff --git a/laba 0/laba 0/MovementStrategy/AbstractStrategy.cs b/laba 0/laba 0/MovementStrategy/AbstractStrategy.cs index c506cd5..2095d96 100644 --- a/laba 0/laba 0/MovementStrategy/AbstractStrategy.cs +++ b/laba 0/laba 0/MovementStrategy/AbstractStrategy.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace laba_0.MovementStrategy; +namespace MotorBoat.MovementStrategy; /// /// Класс-стратегия перемещения объекта diff --git a/laba 0/laba 0/MovementStrategy/IMoveableObject.cs b/laba 0/laba 0/MovementStrategy/IMoveableObject.cs index 1b7da3e..47c1ce6 100644 --- a/laba 0/laba 0/MovementStrategy/IMoveableObject.cs +++ b/laba 0/laba 0/MovementStrategy/IMoveableObject.cs @@ -1,4 +1,4 @@ -namespace laba_0.MovementStrategy; +namespace MotorBoat.MovementStrategy; /// /// Интерфейс для работы с перемещаемым объектом diff --git a/laba 0/laba 0/MovementStrategy/MoveToBorder.cs b/laba 0/laba 0/MovementStrategy/MoveToBorder.cs index 9a23dab..e93a749 100644 --- a/laba 0/laba 0/MovementStrategy/MoveToBorder.cs +++ b/laba 0/laba 0/MovementStrategy/MoveToBorder.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace laba_0.MovementStrategy; +namespace MotorBoat.MovementStrategy; public class MoveToBorder : AbstractStrategy { diff --git a/laba 0/laba 0/MovementStrategy/MoveToCenter.cs b/laba 0/laba 0/MovementStrategy/MoveToCenter.cs index c7ce55a..0cb58dc 100644 --- a/laba 0/laba 0/MovementStrategy/MoveToCenter.cs +++ b/laba 0/laba 0/MovementStrategy/MoveToCenter.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace laba_0.MovementStrategy; +namespace MotorBoat.MovementStrategy; public class MoveToCenter : AbstractStrategy { diff --git a/laba 0/laba 0/MovementStrategy/MoveableB.cs b/laba 0/laba 0/MovementStrategy/MoveableB.cs index 09b2a59..b420a31 100644 --- a/laba 0/laba 0/MovementStrategy/MoveableB.cs +++ b/laba 0/laba 0/MovementStrategy/MoveableB.cs @@ -3,9 +3,9 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -using laba_0.Drawning; +using MotorBoat.Drawning; -namespace laba_0.MovementStrategy; +namespace MotorBoat.MovementStrategy; /// /// Класс-реализация IMoveableObject с использованием DrawningB diff --git a/laba 0/laba 0/MovementStrategy/MovementDirection.cs b/laba 0/laba 0/MovementStrategy/MovementDirection.cs index ab71386..770f732 100644 --- a/laba 0/laba 0/MovementStrategy/MovementDirection.cs +++ b/laba 0/laba 0/MovementStrategy/MovementDirection.cs @@ -1,4 +1,4 @@ -namespace laba_0.MovementStrategy; +namespace MotorBoat.MovementStrategy; public enum MovementDirection { diff --git a/laba 0/laba 0/MovementStrategy/ObjectParameters.cs b/laba 0/laba 0/MovementStrategy/ObjectParameters.cs index ac4790a..c0eb61e 100644 --- a/laba 0/laba 0/MovementStrategy/ObjectParameters.cs +++ b/laba 0/laba 0/MovementStrategy/ObjectParameters.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace laba_0.MovementStrategy; +namespace MotorBoat.MovementStrategy; public class ObjectParameters { diff --git a/laba 0/laba 0/MovementStrategy/StrategyStatus.cs b/laba 0/laba 0/MovementStrategy/StrategyStatus.cs index 9275cc7..86f7b18 100644 --- a/laba 0/laba 0/MovementStrategy/StrategyStatus.cs +++ b/laba 0/laba 0/MovementStrategy/StrategyStatus.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace laba_0.MovementStrategy; +namespace MotorBoat.MovementStrategy; public enum StrategyStatus { diff --git a/laba 0/laba 0/Program.cs b/laba 0/laba 0/Program.cs index 029f326..8145421 100644 --- a/laba 0/laba 0/Program.cs +++ b/laba 0/laba 0/Program.cs @@ -1,4 +1,4 @@ -namespace laba_0 +namespace MotorBoat { internal static class Program { @@ -11,7 +11,7 @@ namespace laba_0 // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormBoat()); + Application.Run(new FormBoatCollection()); } } } \ No newline at end of file diff --git a/laba 0/laba 0/Properties/Resources.Designer.cs b/laba 0/laba 0/Properties/Resources.Designer.cs index 736661d..5b28a61 100644 --- a/laba 0/laba 0/Properties/Resources.Designer.cs +++ b/laba 0/laba 0/Properties/Resources.Designer.cs @@ -8,7 +8,7 @@ // //------------------------------------------------------------------------------ -namespace laba_0.Properties { +namespace MotorBoat.Properties { using System; @@ -39,7 +39,7 @@ namespace laba_0.Properties { internal static global::System.Resources.ResourceManager ResourceManager { get { if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("laba_0.Properties.Resources", typeof(Resources).Assembly); + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("MotorBoat.Properties.Resources", typeof(Resources).Assembly); resourceMan = temp; } return resourceMan;