diff --git a/ProjectContainerShip/ProjectContainerShip/CollectionGenericObjects/AbstractCompany.cs b/ProjectContainerShip/ProjectContainerShip/CollectionGenericObjects/AbstractCompany.cs new file mode 100644 index 0000000..4a88d53 --- /dev/null +++ b/ProjectContainerShip/ProjectContainerShip/CollectionGenericObjects/AbstractCompany.cs @@ -0,0 +1,113 @@ +using ProjectContainerShip.Drawings; +namespace ProjectContainerShip.CollectionGenericObjects; + + /// + /// Абстракция компании, хранящий коллекцию кораблей + /// + public abstract class AbstractCompany + { + /// + /// Размер места (ширина) + /// + protected readonly int _placeSizeWidth = 240; + + /// + /// Размер места (высота) + /// + 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 pictureWidth, int pictureHeight, ICollectionGenericObjects collection) + { + _pictureWidth = pictureWidth; + _pictureHeight = pictureHeight; + _collection = collection; + _collection.SetMaxCount = GetMaxCount; + } + + /// + /// Перегрузка оператора сложения для класса + /// + /// Компания + /// Добавляемый объект + /// + public static int operator +(AbstractCompany company, DrawningShip ship) + { + return company._collection?.Insert(ship) ?? -1; + } + + /// + /// Перегрузка оператора удаления для класса + /// + /// Компания + /// Номер удаляемого объекта + /// + public static DrawningShip operator -(AbstractCompany company, int position) + { + return company._collection?.Remove(position) ?? null; + } + + /// + /// Получение случайного объекта из коллекции + /// + /// + public DrawningShip? 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) + { + DrawningShip? obj = _collection?.Get(i); + obj?.DrawTransport(graphics); + } + return bitmap; + } + + /// + /// Вывод заднего фона + /// + /// + protected abstract void DrawBackgound(Graphics g); + + /// + /// Расстановка объектов + /// + protected abstract void SetObjectsPosition(); + } diff --git a/ProjectContainerShip/ProjectContainerShip/CollectionGenericObjects/ICollectionGenericObjects.cs b/ProjectContainerShip/ProjectContainerShip/CollectionGenericObjects/ICollectionGenericObjects.cs new file mode 100644 index 0000000..86652f3 --- /dev/null +++ b/ProjectContainerShip/ProjectContainerShip/CollectionGenericObjects/ICollectionGenericObjects.cs @@ -0,0 +1,52 @@ +namespace ProjectContainerShip.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); + } +} + +namespace ProjectContainerShip.CollectionGenericObjects +{ + internal interface ICollectionGenericObjects + { + } +} diff --git a/ProjectContainerShip/ProjectContainerShip/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectContainerShip/ProjectContainerShip/CollectionGenericObjects/MassiveGenericObjects.cs new file mode 100644 index 0000000..477b828 --- /dev/null +++ b/ProjectContainerShip/ProjectContainerShip/CollectionGenericObjects/MassiveGenericObjects.cs @@ -0,0 +1,97 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectContainerShip.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 = position + 1; + while (index < _collection.Length) + { + if (_collection[index] == null) + { + _collection[index] = obj; + return index; + } + ++index; + } + index = position - 1; + while (index >= 0) + { + if (_collection[index] == null) + { + _collection[index] = obj; + return index; + } + --index; + } + return -1; + } + public T Remove(int position) + { + // TODO проверка позиции + // TODO удаление объекта из массива, присвоив элементу массива значение null + + if (position >= _collection.Length || position < 0) { + return null; + } + + T obj = _collection[position]; + _collection[position] = null; + return obj; + } + } +} diff --git a/ProjectContainerShip/ProjectContainerShip/CollectionGenericObjects/ShipSharingService.cs b/ProjectContainerShip/ProjectContainerShip/CollectionGenericObjects/ShipSharingService.cs new file mode 100644 index 0000000..8f41e1e --- /dev/null +++ b/ProjectContainerShip/ProjectContainerShip/CollectionGenericObjects/ShipSharingService.cs @@ -0,0 +1,20 @@ +using ProjectContainerShip.Drawings; + +namespace ProjectContainerShip.CollectionGenericObjects; + +public class ShipSharingService : AbstractCompany +{ + public ShipSharingService(int pictureWidth, int pictureHeight, ICollectionGenericObjects collection) : base(pictureWidth, pictureHeight, collection) + { + } + + protected override void DrawBackgound(Graphics g) + { + throw new NotImplementedException(); + } + + protected override void SetObjectsPosition() + { + throw new NotImplementedException(); + } +} diff --git a/ProjectContainerShip/ProjectContainerShip/FormContainerShip.Designer.cs b/ProjectContainerShip/ProjectContainerShip/FormContainerShip.Designer.cs index 6008ea5..3f50a29 100644 --- a/ProjectContainerShip/ProjectContainerShip/FormContainerShip.Designer.cs +++ b/ProjectContainerShip/ProjectContainerShip/FormContainerShip.Designer.cs @@ -30,12 +30,10 @@ namespace ProjectContainerShip private void InitializeComponent() { pictureBoxContainerShip = new PictureBox(); - buttonCreateContainerShip = new Button(); buttonLeft = new Button(); buttonRight = new Button(); buttonDown = new Button(); buttonUp = new Button(); - buttonCreateShip = new Button(); comboBoxStrategy = new ComboBox(); buttonStrategyStep = new Button(); ((System.ComponentModel.ISupportInitialize)pictureBoxContainerShip).BeginInit(); @@ -51,17 +49,6 @@ namespace ProjectContainerShip pictureBoxContainerShip.TabStop = false; pictureBoxContainerShip.Click += pictureBoxContainerShip_Click; // - // buttonCreateContainerShip - // - buttonCreateContainerShip.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonCreateContainerShip.Location = new Point(12, 457); - buttonCreateContainerShip.Name = "buttonCreateContainerShip"; - buttonCreateContainerShip.Size = new Size(316, 46); - buttonCreateContainerShip.TabIndex = 1; - buttonCreateContainerShip.Text = "Создать контейнеровоз"; - buttonCreateContainerShip.UseVisualStyleBackColor = true; - buttonCreateContainerShip.Click += ButtonCreateContainerShip_Click; - // // buttonLeft // buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; @@ -110,17 +97,6 @@ namespace ProjectContainerShip buttonUp.UseVisualStyleBackColor = true; buttonUp.Click += ButtonMove_Click; // - // buttonCreateShip - // - buttonCreateShip.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonCreateShip.Location = new Point(358, 457); - buttonCreateShip.Name = "buttonCreateShip"; - buttonCreateShip.Size = new Size(316, 46); - buttonCreateShip.TabIndex = 6; - buttonCreateShip.Text = "Создать корабль"; - buttonCreateShip.UseVisualStyleBackColor = true; - buttonCreateShip.Click += ButtonCreateShip_Click; - // // comboBoxStrategy // comboBoxStrategy.Anchor = AnchorStyles.Top | AnchorStyles.Right; @@ -150,12 +126,10 @@ namespace ProjectContainerShip ClientSize = new Size(1256, 529); Controls.Add(buttonStrategyStep); Controls.Add(comboBoxStrategy); - Controls.Add(buttonCreateShip); Controls.Add(buttonUp); Controls.Add(buttonDown); Controls.Add(buttonRight); Controls.Add(buttonLeft); - Controls.Add(buttonCreateContainerShip); Controls.Add(pictureBoxContainerShip); Name = "FormContainerShip"; Text = "Контейнеровоз"; @@ -173,12 +147,10 @@ namespace ProjectContainerShip #endregion private PictureBox pictureBoxContainerShip; - private Button buttonCreateContainerShip; private Button buttonLeft; private Button buttonRight; private Button buttonDown; private Button buttonUp; - private Button buttonCreateShip; private ComboBox comboBoxStrategy; private Button buttonStrategyStep; } diff --git a/ProjectContainerShip/ProjectContainerShip/FormContainerShip.cs b/ProjectContainerShip/ProjectContainerShip/FormContainerShip.cs index 061b003..17899b7 100644 --- a/ProjectContainerShip/ProjectContainerShip/FormContainerShip.cs +++ b/ProjectContainerShip/ProjectContainerShip/FormContainerShip.cs @@ -19,6 +19,18 @@ public partial class FormContainerShip : Form /// private AbstractStrategy? _strategy; + public DrawningShip SetShip + { + set + { + _drawningShip = value; + _drawningShip.SetPictureSize(pictureBoxContainerShip.Width, pictureBoxContainerShip.Height); + comboBoxStrategy.Enabled = true; + _strategy = null; + Draw(); + } + } + /// /// Конструктор формы /// @@ -44,46 +56,6 @@ public partial class FormContainerShip : Form pictureBoxContainerShip.Image = bmp; } - private void CreateObject(string type) - { - Random random = new(); - switch (type) - { - case nameof(DrawningShip): - _drawningShip = new DrawningShip(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(DrawningContainerShip): - _drawningShip = new DrawningContainerShip(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; - } - - _drawningShip.SetPictureSize(pictureBoxContainerShip.Width, pictureBoxContainerShip.Height); - _drawningShip.SetPosition(random.Next(10, 100), random.Next(10, 100)); - _strategy = null; - comboBoxStrategy.Enabled = true; - Draw(); - } - - /// - /// Обработка нажатия кнопки "Создать контейнеровоз" - /// - /// - /// - private void ButtonCreateContainerShip_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningContainerShip)); - - /// - /// Обработка нажатия кнопки "Создать корабль" - /// - /// - /// - private void ButtonCreateShip_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningShip)); - /// /// Перемещение объекта по форме (нажатие кнопок навигации) /// diff --git a/ProjectContainerShip/ProjectContainerShip/FormShipCollection.Designer.cs b/ProjectContainerShip/ProjectContainerShip/FormShipCollection.Designer.cs new file mode 100644 index 0000000..8f0ae53 --- /dev/null +++ b/ProjectContainerShip/ProjectContainerShip/FormShipCollection.Designer.cs @@ -0,0 +1,174 @@ +namespace ProjectContainerShip +{ + partial class FormShipCollection + { + /// + /// 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(); + buttonAddContainerShip = new Button(); + buttonRefresh = new Button(); + buttonGoToCheck = new Button(); + buttonRemoveShip = new Button(); + maskedTextBox = new MaskedTextBox(); + buttonAddShip = new Button(); + comboBoxSelectorCompany = new ComboBox(); + pictureBox = new PictureBox(); + groupBoxTools.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit(); + SuspendLayout(); + // + // groupBoxTools + // + groupBoxTools.Controls.Add(buttonAddContainerShip); + groupBoxTools.Controls.Add(buttonRefresh); + groupBoxTools.Controls.Add(buttonGoToCheck); + groupBoxTools.Controls.Add(buttonRemoveShip); + groupBoxTools.Controls.Add(maskedTextBox); + groupBoxTools.Controls.Add(buttonAddShip); + groupBoxTools.Controls.Add(comboBoxSelectorCompany); + groupBoxTools.Dock = DockStyle.Right; + groupBoxTools.ForeColor = Color.Black; + groupBoxTools.Location = new Point(1601, 0); + groupBoxTools.Name = "groupBoxTools"; + groupBoxTools.Size = new Size(388, 1112); + groupBoxTools.TabIndex = 0; + groupBoxTools.TabStop = false; + groupBoxTools.Text = "Инструменты"; + // + // buttonAddContainerShip + // + buttonAddContainerShip.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonAddContainerShip.Location = new Point(15, 247); + buttonAddContainerShip.Name = "buttonAddContainerShip"; + buttonAddContainerShip.Size = new Size(367, 77); + buttonAddContainerShip.TabIndex = 7; + buttonAddContainerShip.Text = "Добавление контейнеровоза"; + buttonAddContainerShip.UseVisualStyleBackColor = true; + buttonAddContainerShip.Click += ButtonAddContainerShip_Click; + // + // buttonRefresh + // + buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonRefresh.Location = new Point(15, 887); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(367, 77); + 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(15, 641); + buttonGoToCheck.Name = "buttonGoToCheck"; + buttonGoToCheck.Size = new Size(367, 77); + buttonGoToCheck.TabIndex = 5; + buttonGoToCheck.Text = "Передать на тесты"; + buttonGoToCheck.UseVisualStyleBackColor = true; + buttonGoToCheck.Click += ButtonGoToCheck_Click; + // + // buttonRemoveShip + // + buttonRemoveShip.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonRemoveShip.Location = new Point(15, 473); + buttonRemoveShip.Name = "buttonRemoveShip"; + buttonRemoveShip.Size = new Size(367, 77); + buttonRemoveShip.TabIndex = 4; + buttonRemoveShip.Text = "Удалить корабль"; + buttonRemoveShip.UseVisualStyleBackColor = true; + buttonRemoveShip.Click += ButtonRemoveShip_Click; + // + // maskedTextBox + // + maskedTextBox.Location = new Point(15, 416); + maskedTextBox.Mask = "00"; + maskedTextBox.Name = "maskedTextBox"; + maskedTextBox.Size = new Size(367, 39); + maskedTextBox.TabIndex = 3; + maskedTextBox.ValidatingType = typeof(int); + // + // buttonAddShip + // + buttonAddShip.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonAddShip.Location = new Point(15, 164); + buttonAddShip.Name = "buttonAddShip"; + buttonAddShip.Size = new Size(367, 77); + buttonAddShip.TabIndex = 1; + buttonAddShip.Text = "Добавление корабля"; + buttonAddShip.UseVisualStyleBackColor = true; + buttonAddShip.Click += ButtonAddShip_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(15, 47); + comboBoxSelectorCompany.Name = "comboBoxSelectorCompany"; + comboBoxSelectorCompany.Size = new Size(367, 40); + 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(1601, 1112); + pictureBox.TabIndex = 1; + pictureBox.TabStop = false; + // + // FormShipCollection + // + AutoScaleDimensions = new SizeF(13F, 32F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1989, 1112); + Controls.Add(pictureBox); + Controls.Add(groupBoxTools); + Name = "FormShipCollection"; + Text = "Коллекция кораблей"; + groupBoxTools.ResumeLayout(false); + groupBoxTools.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); + ResumeLayout(false); + } + + #endregion + + private GroupBox groupBoxTools; + private ComboBox comboBoxSelectorCompany; + private Button buttonAddShip; + private Button buttonGoToCheck; + private Button buttonRemoveShip; + private MaskedTextBox maskedTextBox; + private PictureBox pictureBox; + private Button buttonRefresh; + private Button buttonAddContainerShip; + } +} \ No newline at end of file diff --git a/ProjectContainerShip/ProjectContainerShip/FormShipCollection.cs b/ProjectContainerShip/ProjectContainerShip/FormShipCollection.cs new file mode 100644 index 0000000..06a3498 --- /dev/null +++ b/ProjectContainerShip/ProjectContainerShip/FormShipCollection.cs @@ -0,0 +1,189 @@ +using ProjectContainerShip.CollectionGenericObjects; +using ProjectContainerShip.Drawings; +namespace ProjectContainerShip; + +/// +/// Форма работы с компанией и ее коллекцией +/// +public partial class FormShipCollection : Form +{ + /// + /// Компания + /// + private AbstractCompany? _company = null; + + /// + /// Конструктор + /// + public FormShipCollection() + { + InitializeComponent(); + } + + /// + /// Выбор компании + /// + /// + /// + private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e) + { + switch (comboBoxSelectorCompany.Text) + { + case "Хранилище": + _company = new ShipSharingService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects()); + break; + } + } + + /// + /// Создание объекта класса-перемещения + /// + /// + private void CreateObject(string type) + { + if (_company == null) + { + return; + } + + Random random = new(); + DrawningShip drawningShip; + switch (type) + { + case nameof(DrawningShip): + drawningShip = new DrawningShip(random.Next(100, 300), random.Next(1000, 3000), GetColor(random)); + break; + case nameof(DrawningContainerShip): + drawningShip = new DrawningContainerShip(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; + } + + if (_company + drawningShip != -1) + { + MessageBox.Show("Объект добавлен"); + pictureBox.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 ColorDialog(); + + if (dialog.ShowDialog() == DialogResult.OK) + { + color = dialog.Color; + } + + return color; + } + + /// + /// Добавление корабля + /// + /// + /// + private void ButtonAddShip_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningShip)); + + /// + /// Добавление контейнеровоза + /// + /// + /// + private void ButtonAddContainerShip_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningContainerShip)); + + /// + /// Удаление объекта + /// + /// + /// + private void ButtonRemoveShip_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == null) + { + return; + } + + if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) + { + return; + } + + int position = Convert.ToInt32(maskedTextBox.Text); + + if (_company - position != null) + { + MessageBox.Show("Объект удален"); + pictureBox.Image = _company.Show(); + } + else + { + MessageBox.Show("Не удалось удалить объект"); + } + } + + /// + /// Передача на тесты + /// + /// + /// + private void ButtonGoToCheck_Click(object sender, EventArgs e) + { + if (_company == null) + { + return; + } + + DrawningShip? ship = null; + int counter = 100; + while (ship == null) + { + ship = _company.GetRandomObject(); + counter--; + if (counter <= 0) + { + break; + } + } + + if (ship == null) + { + return; + } + + FormContainerShip form = new () + { + SetShip = ship + }; + form.ShowDialog(); + } + + /// + /// Обновление + /// + /// + /// + private void ButtonRefresh_Click(object sender, EventArgs e) + { + if (_company == null) + { + return; + } + + pictureBox.Image = _company.Show(); + } +} diff --git a/ProjectContainerShip/ProjectContainerShip/FormShipCollection.resx b/ProjectContainerShip/ProjectContainerShip/FormShipCollection.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectContainerShip/ProjectContainerShip/FormShipCollection.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/ProjectContainerShip/ProjectContainerShip/Program.cs b/ProjectContainerShip/ProjectContainerShip/Program.cs index 426af01..4f76f20 100644 --- a/ProjectContainerShip/ProjectContainerShip/Program.cs +++ b/ProjectContainerShip/ProjectContainerShip/Program.cs @@ -11,7 +11,7 @@ namespace ProjectContainerShip // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormContainerShip()); + Application.Run(new FormShipCollection()); } } } \ No newline at end of file