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/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/BoatHarborService.cs b/ProjectCatamaran/ProjectCatamaran/CollectiongGenericObjects/BoatHarborService.cs new file mode 100644 index 0000000..b443156 --- /dev/null +++ b/ProjectCatamaran/ProjectCatamaran/CollectiongGenericObjects/BoatHarborService.cs @@ -0,0 +1,69 @@ +using ProjectCatamaran.Drawnings; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectCatamaran.CollectiongGenericObjects; + +/// +/// Реализация абстрактной компании - каршеринг +/// +public class BoatHarborService : AbstractCompany +{ + /// + /// + /// + /// + /// + /// + public BoatHarborService(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, 4); + for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++) + { + for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j) + { + 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); + } + } + + protected override void SetObjectsPosition() + { + int width = _pictureWidth / _placeSizeWidth; + int height = _pictureHeight / _placeSizeHeight; + + int curWidth = 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 + 10, curHeight * _placeSizeHeight + 5); + } + + if (curWidth < width - 1) + curWidth++; + else + { + curWidth = 0; + curHeight--; + } + if (curHeight < 0) + { + return; + } + } + } +} 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; + } +} diff --git a/ProjectCatamaran/ProjectCatamaran/FormBoatCollection.Designer.cs b/ProjectCatamaran/ProjectCatamaran/FormBoatCollection.Designer.cs new file mode 100644 index 0000000..9e0b36c --- /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(849, 0); + groupBoxTools.Name = "groupBoxTools"; + groupBoxTools.Size = new Size(279, 629); + 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(849, 629); + pictureBoxBoat.TabIndex = 1; + pictureBoxBoat.TabStop = false; + // + // FormBoatCollection + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1128, 629); + 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..e185b94 --- /dev/null +++ b/ProjectCatamaran/ProjectCatamaran/FormBoatCollection.cs @@ -0,0 +1,192 @@ +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 BoatHarborService(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/Resources/Program.cs b/ProjectCatamaran/ProjectCatamaran/Program.cs similarity index 82% rename from ProjectCatamaran/ProjectCatamaran/Resources/Program.cs rename to ProjectCatamaran/ProjectCatamaran/Program.cs index 89a0c0b..59feea7 100644 --- a/ProjectCatamaran/ProjectCatamaran/Resources/Program.cs +++ b/ProjectCatamaran/ProjectCatamaran/Program.cs @@ -1,4 +1,4 @@ -namespace ProjectCatamaran.Resources +namespace ProjectCatamaran { internal static class Program { @@ -11,7 +11,7 @@ namespace ProjectCatamaran.Resources // 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