From 4f053ef311ab2eef7a4469a555a034ce3d83baca Mon Sep 17 00:00:00 2001 From: Anastasia_52 Date: Thu, 11 Apr 2024 14:40:12 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9A=D0=BE=D0=BC=D0=BF=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbstractCompany.cs | 118 +++++++++++ .../ICollectionGenericObjects.cs | 48 +++++ .../MassiveGenericObjects.cs | 113 +++++++++++ .../WarshipSharingService.cs | 62 ++++++ .../Drawnings/DrawingWarship.cs | 2 +- .../ProjectSportCar/FormLinkor.Designer.cs | 28 --- ProjectSportCar/ProjectSportCar/FormLinkor.cs | 74 +++---- .../FormWarshipCollection.Designer.cs | 172 ++++++++++++++++ .../ProjectSportCar/FormWarshipCollection.cs | 189 ++++++++++++++++++ .../FormWarshipCollection.resx | 120 +++++++++++ ProjectSportCar/ProjectSportCar/Program.cs | 2 +- 11 files changed, 849 insertions(+), 79 deletions(-) create mode 100644 ProjectSportCar/ProjectSportCar/CollectionGenericObjects/AbstractCompany.cs create mode 100644 ProjectSportCar/ProjectSportCar/CollectionGenericObjects/ICollectionGenericObjects.cs create mode 100644 ProjectSportCar/ProjectSportCar/CollectionGenericObjects/MassiveGenericObjects.cs create mode 100644 ProjectSportCar/ProjectSportCar/CollectionGenericObjects/WarshipSharingService.cs create mode 100644 ProjectSportCar/ProjectSportCar/FormWarshipCollection.Designer.cs create mode 100644 ProjectSportCar/ProjectSportCar/FormWarshipCollection.cs create mode 100644 ProjectSportCar/ProjectSportCar/FormWarshipCollection.resx diff --git a/ProjectSportCar/ProjectSportCar/CollectionGenericObjects/AbstractCompany.cs b/ProjectSportCar/ProjectSportCar/CollectionGenericObjects/AbstractCompany.cs new file mode 100644 index 0000000..d6c9fae --- /dev/null +++ b/ProjectSportCar/ProjectSportCar/CollectionGenericObjects/AbstractCompany.cs @@ -0,0 +1,118 @@ +using ProjectLinkor.Drawnings; +namespace ProjectLinkor.CollectionGenericObjects; + +/// +/// Абстракция компании, хранящий коллекцию линкора +/// +public abstract class AbstractCompany +{ + /// + /// Размер места (ширина) + /// + protected readonly int _placeSizeWidth = 240; + + /// + /// Размер места (высота) + /// + protected readonly int _placeSizeHeight = 95; + + /// + /// Ширина окна + /// + protected int _pictureWidth; + + /// + /// Высота окна + /// + protected int _pictureHeight; + + protected ICollectionGenericObjects? _collection = null; + protected static int amountOfObjects = 0; + + /// + /// Вычисление максимального количества элементов, который можно разместить в окне + /// + private int GetMaxCount => _pictureWidth * _pictureHeight / (_placeSizeWidth * _placeSizeHeight); + + public static int getAmountOfObjects() + { + return amountOfObjects; + } + + + /// + /// Конструктор + /// + /// Ширина окна + /// Высота окна + /// Коллеккция кораблей + /// + public AbstractCompany(int picWidth, int picHeight, ICollectionGenericObjects collection) + { + _pictureWidth = picWidth; + _pictureHeight = picHeight; + _collection = collection; + _collection.SetMaxCount = GetMaxCount; + } + + /// + /// Перезагрузка оператора сложения для класса + /// + /// Компания + /// Добавляемый объект + /// + public static int operator +(AbstractCompany company, DrawingWarship warship) + { + return company._collection.Insert(warship); + } + /// + /// Перезагрузка оператора удаления для класса + /// + /// Компания + /// Номер удаляемого объекта + /// + public static DrawingWarship operator -(AbstractCompany company, int position) + { + return company._collection.Remove(position); + } + + /// + /// Получение случайного объекта из коллекции + /// + /// + public DrawingWarship? 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) + { + DrawingWarship? obj = _collection?.Get(i); + obj?.DrawTransport(graphics); + } + return bitmap; + } + + /// + /// Вывод заднего фона + /// + /// + protected abstract void DrawBackground(Graphics g); + + /// + /// Расстановка объектов + /// + protected abstract void SetObjectsPosition(); +} diff --git a/ProjectSportCar/ProjectSportCar/CollectionGenericObjects/ICollectionGenericObjects.cs b/ProjectSportCar/ProjectSportCar/CollectionGenericObjects/ICollectionGenericObjects.cs new file mode 100644 index 0000000..72890aa --- /dev/null +++ b/ProjectSportCar/ProjectSportCar/CollectionGenericObjects/ICollectionGenericObjects.cs @@ -0,0 +1,48 @@ +namespace ProjectLinkor.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/ProjectSportCar/ProjectSportCar/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectSportCar/ProjectSportCar/CollectionGenericObjects/MassiveGenericObjects.cs new file mode 100644 index 0000000..32b2e3d --- /dev/null +++ b/ProjectSportCar/ProjectSportCar/CollectionGenericObjects/MassiveGenericObjects.cs @@ -0,0 +1,113 @@ +using ProjectLinkor.CollectionGenericObjects; + +namespace ProjectLinkor.CollectionGenericObjects; + +/// +/// Параметризованный набор объектов +/// +/// Параметр: ограничение - ссылочный тип +public class MassiveGenericObjects : ICollectionGenericObjects + where T : class +{ + /// + /// Массив объектов, которые храним + /// + private T?[] _collection; + + public int Count => _collection.Length; + + public int SetMaxCount + { + set + { + if (value > 0) + { + if (_collection.Length > 0) + { + Array.Resize(ref _collection, value); + } + else + { + _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/ProjectSportCar/ProjectSportCar/CollectionGenericObjects/WarshipSharingService.cs b/ProjectSportCar/ProjectSportCar/CollectionGenericObjects/WarshipSharingService.cs new file mode 100644 index 0000000..3d2795f --- /dev/null +++ b/ProjectSportCar/ProjectSportCar/CollectionGenericObjects/WarshipSharingService.cs @@ -0,0 +1,62 @@ +using ProjectLinkor.Drawnings; +namespace ProjectLinkor.CollectionGenericObjects; + +/// +/// Реализация абстрактной компании - доки +/// +public class WarshipSharingService : AbstractCompany +{ + /// + /// Конструктор + /// + /// + /// + /// + public WarshipSharingService(int picWidth, int picHeight, ICollectionGenericObjects collection) : base(picWidth, picHeight, collection) + { + } + + protected override void DrawBackground(Graphics g) + { + Pen pen = new(Color.DarkSlateBlue, 4); + for (int i = 0; i <= _pictureWidth / _placeSizeWidth; i++) + { + for (int j = 0; j <= _pictureHeight / _placeSizeHeight; j++) + { + g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight); + } + g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight); + } + } + + //установка объектов + protected override void SetObjectsPosition() + { + int width = _pictureWidth / _placeSizeWidth; + int height = _pictureHeight / _placeSizeHeight; + + int posWidth = 0; + int posHeight = 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 * posWidth + 4, posHeight * _placeSizeHeight + 4); + } + + if (posWidth < width) + posWidth++; + else + { + posWidth = 0; + posHeight--; + } + if (posHeight > height) + { + return; + } + } + } +} diff --git a/ProjectSportCar/ProjectSportCar/Drawnings/DrawingWarship.cs b/ProjectSportCar/ProjectSportCar/Drawnings/DrawingWarship.cs index c218fe6..b74ebf5 100644 --- a/ProjectSportCar/ProjectSportCar/Drawnings/DrawingWarship.cs +++ b/ProjectSportCar/ProjectSportCar/Drawnings/DrawingWarship.cs @@ -139,7 +139,7 @@ public class DrawingWarship /// Координата X /// Координата Y - public void SetPosition(int x, int y, int width, int height) + public void SetPosition(int x, int y) { if (!_pictureWidth.HasValue || !_pictureHeight.HasValue) { diff --git a/ProjectSportCar/ProjectSportCar/FormLinkor.Designer.cs b/ProjectSportCar/ProjectSportCar/FormLinkor.Designer.cs index 641a10d..e75c3a5 100644 --- a/ProjectSportCar/ProjectSportCar/FormLinkor.Designer.cs +++ b/ProjectSportCar/ProjectSportCar/FormLinkor.Designer.cs @@ -29,12 +29,10 @@ private void InitializeComponent() { pictureBoxLinkor = new PictureBox(); - buttonCreate = new Button(); buttonLeft = new Button(); buttonRight = new Button(); buttonUp = new Button(); buttonDown = new Button(); - buttonWarship = new Button(); comboBoxStrategy = new ComboBox(); buttonStrategyStep = new Button(); ((System.ComponentModel.ISupportInitialize)pictureBoxLinkor).BeginInit(); @@ -49,17 +47,6 @@ pictureBoxLinkor.TabIndex = 0; pictureBoxLinkor.TabStop = false; // - // buttonCreate - // - buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonCreate.Location = new Point(12, 483); - buttonCreate.Name = "buttonCreate"; - buttonCreate.Size = new Size(191, 29); - buttonCreate.TabIndex = 1; - buttonCreate.Text = "Создать Линкор"; - buttonCreate.UseVisualStyleBackColor = true; - buttonCreate.Click += ButtonCreate_Click; - // // buttonLeft // buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; @@ -108,17 +95,6 @@ buttonDown.UseVisualStyleBackColor = true; buttonDown.Click += ButtonMove_Click; // - // buttonWarship - // - buttonWarship.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonWarship.Location = new Point(209, 483); - buttonWarship.Name = "buttonWarship"; - buttonWarship.Size = new Size(216, 29); - buttonWarship.TabIndex = 6; - buttonWarship.Text = "Создать Военный корабль"; - buttonWarship.UseVisualStyleBackColor = true; - buttonWarship.Click += ButtonWarship_Click; - // // comboBoxStrategy // comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList; @@ -146,12 +122,10 @@ ClientSize = new Size(931, 524); Controls.Add(buttonStrategyStep); Controls.Add(comboBoxStrategy); - Controls.Add(buttonWarship); Controls.Add(buttonDown); Controls.Add(buttonUp); Controls.Add(buttonRight); Controls.Add(buttonLeft); - Controls.Add(buttonCreate); Controls.Add(pictureBoxLinkor); Name = "FormLinkor"; Text = "Линкор"; @@ -162,12 +136,10 @@ #endregion private PictureBox pictureBoxLinkor; - private Button buttonCreate; private Button buttonLeft; private Button buttonRight; private Button buttonUp; private Button buttonDown; - private Button buttonWarship; private ComboBox comboBoxStrategy; private Button buttonStrategyStep; } diff --git a/ProjectSportCar/ProjectSportCar/FormLinkor.cs b/ProjectSportCar/ProjectSportCar/FormLinkor.cs index aa70efa..3690714 100644 --- a/ProjectSportCar/ProjectSportCar/FormLinkor.cs +++ b/ProjectSportCar/ProjectSportCar/FormLinkor.cs @@ -5,13 +5,28 @@ namespace ProjectLinkor; public partial class FormLinkor : Form { - private DrawingWarship? _drawningWarship; + private DrawingWarship? _drawingWarship; /// /// Стратегия перемещения /// private AbstractStrategy? _strategy; + /// + /// Получение объекта + /// + public DrawingWarship SetWarship + { + set + { + _drawingWarship = value; + _drawingWarship.SetPictureSize(pictureBoxLinkor.Width, pictureBoxLinkor.Height); + comboBoxStrategy.Enabled = true; + _strategy = null; + Draw(); + } + } + /// /// Конструктор формы /// @@ -24,56 +39,17 @@ public partial class FormLinkor : Form private void Draw() { - if (_drawningWarship == null) + if (_drawingWarship == null) { return; } Bitmap bmp = new(pictureBoxLinkor.Width, pictureBoxLinkor.Height); Graphics gr = Graphics.FromImage(bmp); - _drawningWarship.DrawTransport(gr); + _drawingWarship.DrawTransport(gr); pictureBoxLinkor.Image = bmp; } - private void CreateObject(string type) - { - Random random = new(); - switch (type) - { - case nameof(DrawingWarship): - _drawningWarship = new DrawingWarship(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(DrawningLinkor): - _drawningWarship = new DrawningLinkor(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; - } - _drawningWarship.SetPictureSize(pictureBoxLinkor.Width, pictureBoxLinkor.Height); - _drawningWarship.SetPosition(random.Next(10, 100), random.Next(10, 100), pictureBoxLinkor.Width, pictureBoxLinkor.Height); - _strategy = null; - comboBoxStrategy.Enabled = true; - Draw(); - } - - /// - /// обработка нажатия кнопки "создать линкор" - /// - /// - /// - private void ButtonCreate_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningLinkor)); - - /// - /// обработка нажатия кнопки "создать военный корабль" - /// - /// - /// - private void ButtonWarship_Click(object sender, EventArgs e) => CreateObject(nameof(DrawingWarship)); - /// /// кнопки вверх/вниз/влево/вправо /// @@ -81,7 +57,7 @@ public partial class FormLinkor : Form /// private void ButtonMove_Click(object sender, EventArgs e) { - if (_drawningWarship == null) + if (_drawingWarship == null) { return; } @@ -91,16 +67,16 @@ public partial class FormLinkor : Form switch (name) { case "buttonUp": - result = _drawningWarship.MoveTransport(DirectionType.Up); + result = _drawingWarship.MoveTransport(DirectionType.Up); break; case "buttonDown": - result = _drawningWarship.MoveTransport(DirectionType.Down); + result = _drawingWarship.MoveTransport(DirectionType.Down); break; case "buttonLeft": - result = _drawningWarship.MoveTransport(DirectionType.Left); + result = _drawingWarship.MoveTransport(DirectionType.Left); break; case "buttonRight": - result = _drawningWarship.MoveTransport(DirectionType.Right); + result = _drawingWarship.MoveTransport(DirectionType.Right); break; } if (result) @@ -111,7 +87,7 @@ public partial class FormLinkor : Form private void ButtonStrategyStep_Click(object sender, EventArgs e) { - if (_drawningWarship == null) + if (_drawingWarship == null) { return; } @@ -130,7 +106,7 @@ public partial class FormLinkor : Form { return; } - _strategy.SetData(new MoveableWarship(_drawningWarship), + _strategy.SetData(new MoveableWarship(_drawingWarship), pictureBoxLinkor.Width, pictureBoxLinkor.Height); } diff --git a/ProjectSportCar/ProjectSportCar/FormWarshipCollection.Designer.cs b/ProjectSportCar/ProjectSportCar/FormWarshipCollection.Designer.cs new file mode 100644 index 0000000..489eabc --- /dev/null +++ b/ProjectSportCar/ProjectSportCar/FormWarshipCollection.Designer.cs @@ -0,0 +1,172 @@ +namespace ProjectLinkor +{ + partial class FormWarshipCollection + { + /// + /// 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(); + maskedTextBox1 = new MaskedTextBox(); + buttonRefresh = new Button(); + buttonGoToCheck = new Button(); + buttonRemoveWarship = new Button(); + buttonAddBattleship = new Button(); + buttonAddWarship = new Button(); + comboBoxSelectionCompany = new ComboBox(); + pictureBox = new PictureBox(); + groupBoxTools.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit(); + SuspendLayout(); + // + // groupBoxTools + // + groupBoxTools.Controls.Add(maskedTextBox1); + groupBoxTools.Controls.Add(buttonRefresh); + groupBoxTools.Controls.Add(buttonGoToCheck); + groupBoxTools.Controls.Add(buttonRemoveWarship); + groupBoxTools.Controls.Add(buttonAddBattleship); + groupBoxTools.Controls.Add(buttonAddWarship); + groupBoxTools.Controls.Add(comboBoxSelectionCompany); + groupBoxTools.Dock = DockStyle.Right; + groupBoxTools.Location = new Point(916, 0); + groupBoxTools.Name = "groupBoxTools"; + groupBoxTools.Size = new Size(292, 620); + groupBoxTools.TabIndex = 0; + groupBoxTools.TabStop = false; + groupBoxTools.Text = "Инструменты"; + // + // maskedTextBox1 + // + maskedTextBox1.Anchor = AnchorStyles.Left | AnchorStyles.Right; + maskedTextBox1.Location = new Point(12, 269); + maskedTextBox1.Mask = "00"; + maskedTextBox1.Name = "maskedTextBox1"; + maskedTextBox1.Size = new Size(274, 27); + maskedTextBox1.TabIndex = 7; + // + // buttonRefresh + // + buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonRefresh.Location = new Point(12, 477); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(274, 42); + 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(12, 381); + buttonGoToCheck.Name = "buttonGoToCheck"; + buttonGoToCheck.Size = new Size(274, 42); + buttonGoToCheck.TabIndex = 5; + buttonGoToCheck.Text = "Передать на тесты"; + buttonGoToCheck.UseVisualStyleBackColor = true; + buttonGoToCheck.Click += ButtonGoToCheck_Click; + // + // buttonRemoveWarship + // + buttonRemoveWarship.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonRemoveWarship.Location = new Point(12, 283); + buttonRemoveWarship.Name = "buttonRemoveWarship"; + buttonRemoveWarship.Size = new Size(274, 42); + buttonRemoveWarship.TabIndex = 4; + buttonRemoveWarship.Text = "Удалить корабль"; + buttonRemoveWarship.UseVisualStyleBackColor = true; + buttonRemoveWarship.Click += ButtonRemoveWarship_Click_1; + // + // buttonAddBattleship + // + buttonAddBattleship.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonAddBattleship.Location = new Point(12, 141); + buttonAddBattleship.Name = "buttonAddBattleship"; + buttonAddBattleship.Size = new Size(274, 42); + buttonAddBattleship.TabIndex = 2; + buttonAddBattleship.Text = "Добавление линкора"; + buttonAddBattleship.UseVisualStyleBackColor = true; + buttonAddBattleship.Click += ButtonAddLinkor_Click; + // + // buttonAddWarship + // + buttonAddWarship.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonAddWarship.Location = new Point(12, 95); + buttonAddWarship.Name = "buttonAddWarship"; + buttonAddWarship.Size = new Size(274, 40); + buttonAddWarship.TabIndex = 1; + buttonAddWarship.Text = "Добавление военного корабля"; + buttonAddWarship.UseVisualStyleBackColor = true; + buttonAddWarship.Click += ButtonAddWarship_Click; + // + // comboBoxSelectionCompany + // + comboBoxSelectionCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + comboBoxSelectionCompany.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxSelectionCompany.FormattingEnabled = true; + comboBoxSelectionCompany.Items.AddRange(new object[] { "Хранилище" }); + comboBoxSelectionCompany.Location = new Point(12, 26); + comboBoxSelectionCompany.Name = "comboBoxSelectionCompany"; + comboBoxSelectionCompany.Size = new Size(274, 28); + comboBoxSelectionCompany.TabIndex = 0; + comboBoxSelectionCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged; + // + // pictureBox + // + pictureBox.Dock = DockStyle.Fill; + pictureBox.Location = new Point(0, 0); + pictureBox.Name = "pictureBox"; + pictureBox.Size = new Size(916, 620); + pictureBox.TabIndex = 1; + pictureBox.TabStop = false; + // + // FormWarshipCollection + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1208, 620); + Controls.Add(pictureBox); + Controls.Add(groupBoxTools); + Name = "FormWarshipCollection"; + Text = "Коллекция кораблей"; + groupBoxTools.ResumeLayout(false); + groupBoxTools.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); + ResumeLayout(false); + } + #endregion + + private GroupBox groupBoxTools; + private ComboBox comboBoxSelectionCompany; + private Button buttonAddBattleship; + private Button buttonAddWarship; + private Button buttonRemoveWarship; + private PictureBox pictureBox; + private Button buttonRefresh; + private Button buttonGoToCheck; + private MaskedTextBox maskedTextBox1; + } +} \ No newline at end of file diff --git a/ProjectSportCar/ProjectSportCar/FormWarshipCollection.cs b/ProjectSportCar/ProjectSportCar/FormWarshipCollection.cs new file mode 100644 index 0000000..81ca521 --- /dev/null +++ b/ProjectSportCar/ProjectSportCar/FormWarshipCollection.cs @@ -0,0 +1,189 @@ +using ProjectLinkor.CollectionGenericObjects; +using ProjectLinkor.Drawnings; + +namespace ProjectLinkor; + +/// +/// Форма работы с компанией и ее коллекцией +/// +public partial class FormWarshipCollection : Form +{ + /// + /// Компания + /// + private AbstractCompany? _company = null; + + /// + /// Конструктор + /// + public FormWarshipCollection() + { + InitializeComponent(); + } + + /// + /// Выбор компании + /// + /// + /// + private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e) + { + switch (comboBoxSelectionCompany.Text) + { + case "Хранилище": + _company = new WarshipSharingService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects()); + break; + } + } + + /// + /// Создание объекта + /// + /// + private void CreateObject(string type) + { + if (_company == null) + { + return; + } + Random random = new(); + DrawingWarship drawingWarship; + switch (type) + { + case nameof(DrawingWarship): + drawingWarship = new DrawingWarship(random.Next(100, 300), random.Next(1000, 3000), GetColor(random)); + break; + case nameof(DrawningLinkor): + drawingWarship = new DrawningLinkor(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 + drawingWarship != -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(); + if (dialog.ShowDialog() == DialogResult.OK) + { + color = dialog.Color; + } + return color; + } + + /// + /// Передача на тесты + /// + /// + /// + private void ButtonGoToCheck_Click(object sender, EventArgs e) + { + if (_company == null) + { + return; + } + DrawingWarship? warship = null; + int counter = 100; + while (warship == null) + { + warship = _company.GetRandomObject(); + counter--; + if (counter < -0) + { + break; + } + } + if (warship == null) + { + return; + } + FormLinkor form = new() + { + SetWarship = warship + }; + form.ShowDialog(); + + } + + /// + /// Добавление линкора + /// + /// + /// + private void ButtonAddLinkor_Click(object sender, EventArgs e) + { + CreateObject(nameof(DrawningLinkor)); + } + + /// + /// Добавление военного корабля + /// + /// + /// + private void ButtonAddWarship_Click(object sender, EventArgs e) + { + CreateObject(nameof(DrawingWarship)); + } + + /// + /// Удаление объекта + /// + /// + /// + private void ButtonRemoveWarship_Click_1(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(maskedTextBox1.Text) || _company == null) + { + return; + } + + if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) + { + return; + } + + int pos = Convert.ToInt32(maskedTextBox1.Text); + if (_company - pos != null) + { + MessageBox.Show("Объект удален"); + pictureBox.Image = _company.Show(); + } + else + { + MessageBox.Show("Не удалось удалить объект"); + } + } + + /// + /// Обновление + /// + /// + /// + private void ButtonRefresh_Click(object sender, EventArgs e) + { + if (_company == null) + { + return; + } + pictureBox.Image = _company.Show(); + } +} \ No newline at end of file diff --git a/ProjectSportCar/ProjectSportCar/FormWarshipCollection.resx b/ProjectSportCar/ProjectSportCar/FormWarshipCollection.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectSportCar/ProjectSportCar/FormWarshipCollection.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/ProjectSportCar/ProjectSportCar/Program.cs b/ProjectSportCar/ProjectSportCar/Program.cs index 47c425a..fa8cf6d 100644 --- a/ProjectSportCar/ProjectSportCar/Program.cs +++ b/ProjectSportCar/ProjectSportCar/Program.cs @@ -11,7 +11,7 @@ namespace ProjectLinkor // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormLinkor()); + Application.Run(new FormWarshipCollection()); } } } \ No newline at end of file -- 2.25.1