From 7a26e24c82eb71430578c623b897ae5fded28f2b Mon Sep 17 00:00:00 2001 From: Anastasia-Sin Date: Thu, 21 Mar 2024 10:52:11 +0400 Subject: [PATCH] done lab 3 --- .../AbstractCompany.cs | 115 ++++++++++++ .../CruiserDockingService.cs | 65 +++++++ .../ICollectionGenericObjects.cs | 45 +++++ .../MassiveGenericObjects.cs | 97 ++++++++++ ProjectCruiser/FormCruiser.Designer.cs | 28 --- ProjectCruiser/FormCruiser.cs | 79 +++----- .../FormCruisersCollection.Designer.cs | 173 ++++++++++++++++++ ProjectCruiser/FormCruisersCollection.cs | 169 +++++++++++++++++ ProjectCruiser/FormCruisersCollection.resx | 120 ++++++++++++ ProjectCruiser/Program.cs | 7 +- 10 files changed, 809 insertions(+), 89 deletions(-) create mode 100644 ProjectCruiser/CollectionGenericObjects/AbstractCompany.cs create mode 100644 ProjectCruiser/CollectionGenericObjects/CruiserDockingService.cs create mode 100644 ProjectCruiser/CollectionGenericObjects/ICollectionGenericObjects.cs create mode 100644 ProjectCruiser/CollectionGenericObjects/MassiveGenericObjects.cs create mode 100644 ProjectCruiser/FormCruisersCollection.Designer.cs create mode 100644 ProjectCruiser/FormCruisersCollection.cs create mode 100644 ProjectCruiser/FormCruisersCollection.resx diff --git a/ProjectCruiser/CollectionGenericObjects/AbstractCompany.cs b/ProjectCruiser/CollectionGenericObjects/AbstractCompany.cs new file mode 100644 index 0000000..6ccac33 --- /dev/null +++ b/ProjectCruiser/CollectionGenericObjects/AbstractCompany.cs @@ -0,0 +1,115 @@ +using ProjectCruiser.Drawnings; + +namespace ProjectCruiser.CollectionGenericObjects +{ + /// + /// Абстракция компании, хранящий коллекцию автомобилей + /// + public abstract class AbstractCompany + { + /// + /// Размер места (ширина) + /// + protected readonly int _placeSizeWidth = 180; + + /// + /// Размер места (высота) + /// + 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 int operator +(AbstractCompany company, DrawningCruiser сruiser) + { + return company._collection.Insert(сruiser); + } + + /// + /// Перегрузка оператора удаления для класса + /// + /// Компания + /// Номер удаляемого объекта + /// + public static DrawningCruiser operator -(AbstractCompany company, int position) + { + return company._collection?.Remove(position); + } + + /// + /// Получение случайного объекта из коллекции + /// + /// + public DrawningCruiser? 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) + { + DrawningCruiser? obj = _collection?.Get(i); + obj?.DrawTransport(graphics); + } + return bitmap; + } + /// + /// Вывод заднего фона + /// + /// + protected abstract void DrawBackgound(Graphics g); + + /// + /// Расстановка объектов + /// + protected abstract void SetObjectsPosition(); + } +} diff --git a/ProjectCruiser/CollectionGenericObjects/CruiserDockingService.cs b/ProjectCruiser/CollectionGenericObjects/CruiserDockingService.cs new file mode 100644 index 0000000..abf63a4 --- /dev/null +++ b/ProjectCruiser/CollectionGenericObjects/CruiserDockingService.cs @@ -0,0 +1,65 @@ +using ProjectCruiser.Drawnings; + +namespace ProjectCruiser.CollectionGenericObjects +{ + /// + /// Реализация абстрактной компании - каршеринг + /// + public class CruiserDockingService : AbstractCompany + { + /// + /// Конструктор + /// + /// + /// + /// + public CruiserDockingService(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 + 10, curHeight * _placeSizeHeight + 10); + } + + if (curWidth < width - 1) + curWidth++; + else + { + curWidth = 0; + curHeight ++; + } + + if (curHeight >= height) + { + return; + } + } + } + } +} diff --git a/ProjectCruiser/CollectionGenericObjects/ICollectionGenericObjects.cs b/ProjectCruiser/CollectionGenericObjects/ICollectionGenericObjects.cs new file mode 100644 index 0000000..d2dcef6 --- /dev/null +++ b/ProjectCruiser/CollectionGenericObjects/ICollectionGenericObjects.cs @@ -0,0 +1,45 @@ +namespace ProjectCruiser.CollectionGenericObjects +{ + /// + /// Интерфейс описания действий для набора хранимых объектов + /// + /// Параметр: ограничение - ссылочный тип + 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/ProjectCruiser/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectCruiser/CollectionGenericObjects/MassiveGenericObjects.cs new file mode 100644 index 0000000..f67c2be --- /dev/null +++ b/ProjectCruiser/CollectionGenericObjects/MassiveGenericObjects.cs @@ -0,0 +1,97 @@ +using ProjectCruiser.Drawnings; + +namespace ProjectCruiser.CollectionGenericObjects +{ + /// + /// Параметризованный набор объектов + /// + /// Параметр: ограничение - ссылочный тип + public class MassiveGenericObjects : ICollectionGenericObjects + where T : class + { + /// + /// Массив объектов, которые храним + /// + private T?[] _collection; + public int Count => _collection.Length; + public int SetMaxCount { set { if (value > 0) { _collection = new T?[value]; } } } + + /// + /// Конструктор + /// + public MassiveGenericObjects() + { + _collection = Array.Empty(); + } + public T? Get(int position) + { + // TODO проверка позиции + if (position >= _collection.Length || position < 0) + { + return null; + } + return _collection[position]; + } + public int Insert(T obj) + { + // TODO вставка в свободное место набора + 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) + { + // TODO проверка позиции + // TODO проверка, что элемент массива по этой позиции пустой, если нет, то + // ищется свободное место после этой позиции и идет вставка туда + // если нет после, ищем до + // TODO вставка + 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) + { + // TODO проверка позиции + // TODO удаление объекта из массива, присвоив элементу массива значение null + if (position >= _collection.Length || position < 0) + { return null; } + T drawningCruiser = _collection[position]; + _collection[position] = null; + return drawningCruiser; + } + } +} diff --git a/ProjectCruiser/FormCruiser.Designer.cs b/ProjectCruiser/FormCruiser.Designer.cs index 652e1eb..af134a6 100644 --- a/ProjectCruiser/FormCruiser.Designer.cs +++ b/ProjectCruiser/FormCruiser.Designer.cs @@ -30,13 +30,11 @@ { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormCruiser)); pictureBoxCruiser = new PictureBox(); - button1 = new Button(); buttonUp = new Button(); buttonDown = new Button(); buttonRight = new Button(); buttonLeft = new Button(); comboBoxStrategy = new ComboBox(); - buttonCretaeCruiser = new Button(); buttonStrategyStep = new Button(); ((System.ComponentModel.ISupportInitialize)pictureBoxCruiser).BeginInit(); SuspendLayout(); @@ -51,17 +49,6 @@ pictureBoxCruiser.TabIndex = 0; pictureBoxCruiser.TabStop = false; // - // button1 - // - button1.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - button1.Location = new Point(12, 409); - button1.Name = "button1"; - button1.Size = new Size(213, 29); - button1.TabIndex = 1; - button1.Text = "создать военный крейсер"; - button1.UseVisualStyleBackColor = true; - button1.Click += ButtonCreateCruiser_Click; - // // buttonUp // buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; @@ -121,17 +108,6 @@ comboBoxStrategy.Size = new Size(151, 28); comboBoxStrategy.TabIndex = 6; // - // buttonCretaeCruiser - // - buttonCretaeCruiser.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonCretaeCruiser.Location = new Point(240, 410); - buttonCretaeCruiser.Name = "buttonCretaeCruiser"; - buttonCretaeCruiser.Size = new Size(213, 29); - buttonCretaeCruiser.TabIndex = 7; - buttonCretaeCruiser.Text = "создать крейсер"; - buttonCretaeCruiser.UseVisualStyleBackColor = true; - buttonCretaeCruiser.Click += buttonCretaeCruiser_Click; - // // buttonStrategyStep // buttonStrategyStep.Location = new Point(694, 46); @@ -148,13 +124,11 @@ AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(800, 450); Controls.Add(buttonStrategyStep); - Controls.Add(buttonCretaeCruiser); Controls.Add(comboBoxStrategy); Controls.Add(buttonLeft); Controls.Add(buttonRight); Controls.Add(buttonDown); Controls.Add(buttonUp); - Controls.Add(button1); Controls.Add(pictureBoxCruiser); Name = "FormCruiser"; Text = "FormCruiser"; @@ -167,13 +141,11 @@ #endregion private PictureBox pictureBoxCruiser; - private Button button1; private Button buttonUp; private Button buttonDown; private Button buttonRight; private Button buttonLeft; private ComboBox comboBoxStrategy; - private Button buttonCretaeCruiser; private Button buttonStrategyStep; } } \ No newline at end of file diff --git a/ProjectCruiser/FormCruiser.cs b/ProjectCruiser/FormCruiser.cs index 2696789..544737c 100644 --- a/ProjectCruiser/FormCruiser.cs +++ b/ProjectCruiser/FormCruiser.cs @@ -15,6 +15,25 @@ namespace ProjectCruiser /// private AbstractStrategy? _strategy; + /// + /// Получение объекта + /// + public DrawningCruiser SetCruiser + { + set + { + _drawningCruiser = value; + _drawningCruiser.SetPictureSize(pictureBoxCruiser.Width, + pictureBoxCruiser.Height); + comboBoxStrategy.Enabled = true; + _strategy = null; + Draw(); + } + } + + /// + /// Конструктор формы + /// public FormCruiser() { InitializeComponent(); @@ -37,57 +56,6 @@ namespace ProjectCruiser pictureBoxCruiser.Image = bmp; } - /// - /// Создание объекта класса-перемещения - /// - /// Тип создаваемого объекта - private void CreateObject(string type) - { - Random random = new(); - switch (type) - { - case nameof(DrawningCruiser): - _drawningCruiser = new DrawningCruiser(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(DrawningMilitaryCruiser): - _drawningCruiser = new DrawningMilitaryCruiser(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; - } - _drawningCruiser.SetPictureSize(pictureBoxCruiser.Width, - pictureBoxCruiser.Height); - _drawningCruiser.SetPosition(random.Next(10, 100), random.Next(10, 100)); - _strategy = null; - comboBoxStrategy.Enabled = true; - Draw(); - } - - /// - /// Обработка нажатия кнопки "Создать военный крейсер" - /// - /// - /// - private void ButtonCreateCruiser_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningMilitaryCruiser)); - - /// - /// Обработка нажатия кнопки "Создать крейсер" - /// - /// - /// - private void buttonCretaeCruiser_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningCruiser)); - - /// /// Перемещение объекта по форме (нажатие кнопок навигации) /// @@ -104,16 +72,13 @@ namespace ProjectCruiser switch (name) { case "buttonUp": - result = - _drawningCruiser.MoveTransport(DirectionType.Up); + result = _drawningCruiser.MoveTransport(DirectionType.Up); break; case "buttonDown": - result = - _drawningCruiser.MoveTransport(DirectionType.Down); + result = _drawningCruiser.MoveTransport(DirectionType.Down); break; case "buttonLeft": - result = - _drawningCruiser.MoveTransport(DirectionType.Left); + result = _drawningCruiser.MoveTransport(DirectionType.Left); break; case "buttonRight": result = diff --git a/ProjectCruiser/FormCruisersCollection.Designer.cs b/ProjectCruiser/FormCruisersCollection.Designer.cs new file mode 100644 index 0000000..afd6bed --- /dev/null +++ b/ProjectCruiser/FormCruisersCollection.Designer.cs @@ -0,0 +1,173 @@ +namespace ProjectCruiser +{ + partial class FormCruisersCollection + { + /// + /// 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(); + maskedTextBoxPosision = new MaskedTextBox(); + buttonRefresh = new Button(); + buttonGetToTest = new Button(); + ButtonRemoveCruiser = new Button(); + ButtonAddMilitaryCruiser = new Button(); + ButtonAddCruiser = new Button(); + comboBoxSelectorCompany = new ComboBox(); + pictureBoxCruiser = new PictureBox(); + groupBoxTools.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBoxCruiser).BeginInit(); + SuspendLayout(); + // + // groupBoxTools + // + groupBoxTools.Controls.Add(maskedTextBoxPosision); + groupBoxTools.Controls.Add(buttonRefresh); + groupBoxTools.Controls.Add(buttonGetToTest); + groupBoxTools.Controls.Add(ButtonRemoveCruiser); + groupBoxTools.Controls.Add(ButtonAddMilitaryCruiser); + groupBoxTools.Controls.Add(ButtonAddCruiser); + groupBoxTools.Controls.Add(comboBoxSelectorCompany); + groupBoxTools.Dock = DockStyle.Right; + groupBoxTools.Location = new Point(596, 0); + groupBoxTools.Name = "groupBoxTools"; + groupBoxTools.Size = new Size(222, 574); + groupBoxTools.TabIndex = 0; + groupBoxTools.TabStop = false; + groupBoxTools.Text = "инструменты"; + // + // maskedTextBoxPosision + // + maskedTextBoxPosision.Location = new Point(20, 229); + maskedTextBoxPosision.Mask = "00"; + maskedTextBoxPosision.Name = "maskedTextBoxPosision"; + maskedTextBoxPosision.Size = new Size(186, 27); + maskedTextBoxPosision.TabIndex = 2; + maskedTextBoxPosision.ValidatingType = typeof(int); + // + // buttonRefresh + // + buttonRefresh.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonRefresh.Location = new Point(20, 479); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(186, 40); + buttonRefresh.TabIndex = 5; + buttonRefresh.Text = "обновить"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += ButtonRefresh_Click; + // + // buttonGetToTest + // + buttonGetToTest.Anchor = AnchorStyles.Right; + buttonGetToTest.Location = new Point(20, 366); + buttonGetToTest.Name = "buttonGetToTest"; + buttonGetToTest.Size = new Size(186, 40); + buttonGetToTest.TabIndex = 4; + buttonGetToTest.Text = "передать на тесты"; + buttonGetToTest.UseVisualStyleBackColor = true; + buttonGetToTest.Click += ButtonGetToTest_Click; + // + // ButtonRemoveCruiser + // + ButtonRemoveCruiser.Anchor = AnchorStyles.Right; + ButtonRemoveCruiser.Location = new Point(20, 271); + ButtonRemoveCruiser.Name = "ButtonRemoveCruiser"; + ButtonRemoveCruiser.Size = new Size(186, 40); + ButtonRemoveCruiser.TabIndex = 3; + ButtonRemoveCruiser.Text = "удалить крейсер"; + ButtonRemoveCruiser.UseVisualStyleBackColor = true; + ButtonRemoveCruiser.Click += ButtonRemoveCruiser_Click; + // + // ButtonAddMilitaryCruiser + // + ButtonAddMilitaryCruiser.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + ButtonAddMilitaryCruiser.Location = new Point(20, 152); + ButtonAddMilitaryCruiser.Name = "ButtonAddMilitaryCruiser"; + ButtonAddMilitaryCruiser.Size = new Size(186, 50); + ButtonAddMilitaryCruiser.TabIndex = 2; + ButtonAddMilitaryCruiser.Text = "добваление военного крейсера"; + ButtonAddMilitaryCruiser.UseVisualStyleBackColor = true; + ButtonAddMilitaryCruiser.Click += ButtonAddMilitaryCruiser_Click; + // + // ButtonAddCruiser + // + ButtonAddCruiser.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + ButtonAddCruiser.BackgroundImageLayout = ImageLayout.Center; + ButtonAddCruiser.Location = new Point(20, 106); + ButtonAddCruiser.Name = "ButtonAddCruiser"; + ButtonAddCruiser.Size = new Size(186, 40); + ButtonAddCruiser.TabIndex = 1; + ButtonAddCruiser.Text = "добваление крейсера"; + ButtonAddCruiser.UseVisualStyleBackColor = true; + ButtonAddCruiser.Click += ButtonAddCruiser_Click; + // + // comboBoxSelectorCompany + // + comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxSelectorCompany.FormattingEnabled = true; + comboBoxSelectorCompany.Items.AddRange(new object[] { "хранилище" }); + comboBoxSelectorCompany.Location = new Point(20, 26); + comboBoxSelectorCompany.Name = "comboBoxSelectorCompany"; + comboBoxSelectorCompany.Size = new Size(186, 28); + comboBoxSelectorCompany.TabIndex = 0; + comboBoxSelectorCompany.SelectedIndexChanged += comboBoxSelectorCompany_SelectedIndexChanged_1; + // + // pictureBoxCruiser + // + pictureBoxCruiser.Dock = DockStyle.Fill; + pictureBoxCruiser.Location = new Point(0, 0); + pictureBoxCruiser.Name = "pictureBoxCruiser"; + pictureBoxCruiser.Size = new Size(596, 574); + pictureBoxCruiser.TabIndex = 1; + pictureBoxCruiser.TabStop = false; + // + // FormCruisersCollection + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(818, 574); + Controls.Add(pictureBoxCruiser); + Controls.Add(groupBoxTools); + Name = "FormCruisersCollection"; + Text = "FormCruisersCollection"; + groupBoxTools.ResumeLayout(false); + groupBoxTools.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBoxCruiser).EndInit(); + ResumeLayout(false); + } + + #endregion + + private GroupBox groupBoxTools; + private ComboBox comboBoxSelectorCompany; + private Button ButtonAddMilitaryCruiser; + private Button ButtonAddCruiser; + private Button ButtonRemoveCruiser; + private Button buttonRefresh; + private Button buttonGetToTest; + private PictureBox pictureBoxCruiser; + private MaskedTextBox maskedTextBoxPosision; + } +} \ No newline at end of file diff --git a/ProjectCruiser/FormCruisersCollection.cs b/ProjectCruiser/FormCruisersCollection.cs new file mode 100644 index 0000000..73e80a0 --- /dev/null +++ b/ProjectCruiser/FormCruisersCollection.cs @@ -0,0 +1,169 @@ +using ProjectCruiser.CollectionGenericObjects; +using ProjectCruiser.Drawnings; + +namespace ProjectCruiser +{ + public partial class FormCruisersCollection : Form + { + /// + /// Компания + /// + private AbstractCompany? _company = null; + /// + /// Конструктор + /// + public FormCruisersCollection() + { + InitializeComponent(); + } + + /// + /// + /// + /// + /// + private void comboBoxSelectorCompany_SelectedIndexChanged_1(object sender, EventArgs e) + { + switch (comboBoxSelectorCompany.Text) + { + case "хранилище": + _company = new CruiserDockingService(pictureBoxCruiser.Width, + pictureBoxCruiser.Height, new MassiveGenericObjects()); + break; + } + } + + /// + /// Создание объекта класса-перемещения + /// + /// Тип создаваемого объекта + private void CreateObject(string type) + { + if (_company == null) + { + return; + } + Random random = new(); + DrawningCruiser drawningCruiser; + switch (type) + { + case nameof(DrawningCruiser): + drawningCruiser = new DrawningCruiser(random.Next(100, 300), random.Next(1000, 3000), GetColor(random)); + break; + case nameof(DrawningMilitaryCruiser): + drawningCruiser = new DrawningMilitaryCruiser(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 + drawningCruiser != -1) + { + MessageBox.Show("объект добавлен"); + pictureBoxCruiser.Image = _company.Show(); + } + else + { + MessageBox.Show("не удалось добавить объект"); + } + } + + /// + /// Получение цвета + /// + /// Генератор случайных чисел + /// + private static Color GetColor(Random random) + { + Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, + 256), random.Next(0, 256)); + ColorDialog dialog = new(); + if (dialog.ShowDialog() == DialogResult.OK) + { + color = dialog.Color; + } + return color; + } + + //private void ButtonAddCruiser_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningCruiser)); + + //private void ButtonAddMilitaryCruiser_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningMilitaryCruiser)); + private void ButtonAddCruiser_Click(object sender, EventArgs e) + { + CreateObject(nameof(DrawningCruiser)); + } + + private void ButtonAddMilitaryCruiser_Click(object sender, EventArgs e) + { + CreateObject(nameof(DrawningMilitaryCruiser)); + } + + private void ButtonRemoveCruiser_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(maskedTextBoxPosision.Text) || _company == null) + { + return; + } + if (MessageBox.Show("удалить объект?", "удаление", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) + { + return; + } + int pos = Convert.ToInt32(maskedTextBoxPosision.Text); + if (_company - pos != null) + { + MessageBox.Show("объект удален"); + pictureBoxCruiser.Image = _company.Show(); + } + else + { + MessageBox.Show("не удалось удалить объект"); + } + } + + private void ButtonGetToTest_Click(object sender, EventArgs e) + { + if (_company == null) + { + return; + } + + DrawningCruiser? cruiser = null; + int counter = 100; + while (cruiser == null) + { + cruiser = _company.GetRandomObject(); + counter--; + if (counter <= 0) + { + break; + } + } + if (cruiser == null) + { + return; + } + FormCruiser form = new() + { + SetCruiser = cruiser + }; + form.ShowDialog(); + + } + + private void ButtonRefresh_Click(object sender, EventArgs e) + { + if (_company == null) + { + return; + } + + pictureBoxCruiser.Image = _company.Show(); + } + + + } +} diff --git a/ProjectCruiser/FormCruisersCollection.resx b/ProjectCruiser/FormCruisersCollection.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectCruiser/FormCruisersCollection.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/ProjectCruiser/Program.cs b/ProjectCruiser/Program.cs index 4e00cd8..812529b 100644 --- a/ProjectCruiser/Program.cs +++ b/ProjectCruiser/Program.cs @@ -3,15 +3,14 @@ namespace ProjectCruiser internal static class Program { /// - /// The main entry point for the application. + /// 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. + // To customize application configuration such as set high DPI settings or default font, see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormCruiser()); + Application.Run(new FormCruisersCollection()); } } } \ No newline at end of file