PIbd-11 ShtyrkinE.D. LabWork03 Simple #3

Closed
Shtyrkin_Egor wants to merge 3 commits from LabWork03_AircraftCarrier_Simple into LabWork02_AircraftCarrier_Simple
10 changed files with 828 additions and 84 deletions

View File

@ -0,0 +1,121 @@
using ProjectAircraftCarrier.Drawnings;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectAircraftCarrier.CollectionGenericObjects;
/// <summary>
/// Абстракция компании, хранящей коллекцию автомобилей
/// </summary>
public abstract class AbstractCompany
{
/// <summary>
/// Размер места (ширина)
/// </summary>
protected readonly int _placeSizeWidth = 180;
/// <summary>
/// Размер места (высота)
/// </summary>
protected readonly int _placeSizeHeight = 70;
/// <summary>
/// Ширина окна
/// </summary>
protected readonly int _pictureWidth;
/// <summary>
/// Высота окна
/// </summary>
protected readonly int _pictureHeight;
/// <summary>
/// Коллекция автомобилей
/// </summary>
protected ICollectionGenericObjects<DrawningWarship>? _collection = null;
/// <summary>
/// Вычисление максимального количества элементов, которых можно разместить в окне
/// </summary>
private int GetMaxCount => _pictureWidth * _pictureHeight / (_placeSizeWidth * _placeSizeHeight);
/// <summary>
/// Конструктор
/// </summary>
/// <param name="picWidth">Ширина окна</param>
/// <param name="picHeight">Высота окна</param>
/// <param name="collection">Коллекция автомобилей</param>
public AbstractCompany(int picWidth, int picHeight, ICollectionGenericObjects<DrawningWarship> collection)
{
_pictureWidth = picWidth;
_pictureHeight = picHeight;
_collection = collection;
_collection.SetMaxCount = GetMaxCount;
}
/// <summary>
/// Перегрузка оператора сложения для класса
/// </summary>
/// <param name="company">Компания</param>
/// <param name="warship">Добавляемый объект</param>
/// <returns></returns>
public static int operator +(AbstractCompany company, DrawningWarship warship)
{
return company._collection.Insert(warship);
}
/// <summary>
/// Перегрузка оператора удаления для класса
/// </summary>
/// <param name="company">Компания</param>
/// <param name="position">Номер удаляемого объекта</param>
/// <returns></returns>
public static DrawningWarship operator -(AbstractCompany company, int position)
{
return company._collection.Remove(position);
}
/// <summary>
/// Получение случайного объекта из коллекции
/// </summary>
/// <returns></returns>
public DrawningWarship? GetRandomObject()
{
Random rnd = new();
return _collection?.Get(rnd.Next(GetMaxCount));
}
/// <summary>
/// Вывод всей коллекции
/// </summary>
/// <returns></returns>
public Bitmap? Show()
{
Bitmap bitmap = new(_pictureWidth, _pictureHeight);
Graphics graphics = Graphics.FromImage(bitmap);
DrawBackground(graphics);
SetObjectPosition();
for (int i = 0; i < (_collection?.Count ?? 0); ++i)
{
DrawningWarship? obj = _collection?.Get(i);
obj?.DrawTransport(graphics);
}
return bitmap;
}
/// <summary>
/// Вывод заднего фона
/// </summary>
/// <param name="g"></param>
protected abstract void DrawBackground(Graphics g);
/// <summary>
/// Расстановка объектов
/// </summary>
protected abstract void SetObjectPosition();
}

View File

@ -0,0 +1,54 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectAircraftCarrier.CollectionGenericObjects;
/// <summary>
/// Интерфейс описания действий для набора хранимых объектов
/// </summary>
/// <typeparam name="T">Параметр: ограничение - ссылочный тип</typeparam>
public interface ICollectionGenericObjects<T>
where T : class
{
/// <summary>
/// Количество объектов в коллекции
/// </summary>
int Count { get; }
/// <summary>
/// Установка максимального количества элементов
/// </summary>
int SetMaxCount { set; }
/// <summary>
/// Добавление объекта в коллекцию
/// </summary>
/// <param name="obj">Добавляемый объект</param>
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
int Insert(T obj);
/// <summary>
/// Добавление объекта в коллекцию на конкретную позицию
/// </summary>
/// <param name="obj">Добавляемый объект</param>
/// <param name="position">Позиция</param>
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
int Insert(T obj, int position);
/// <summary>
/// Удаление объекта из коллекции с конкретной позиции
/// </summary>
/// <param name="position">Позиция</param>
/// <returns>true - удаление прошло удачно, false - удаление не удалось</returns>
T Remove(int position);
/// <summary>
/// Получение объекта по позиции
/// </summary>
/// <param name="position">Позиция</param>
/// <returns>Объект</returns>
T? Get(int position);
}

View File

@ -0,0 +1,96 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectAircraftCarrier.CollectionGenericObjects;
/// <summary>
/// Параметризованный набор объектов
/// </summary>
/// <typeparam name="T">Параметр: ограничение - ссылочный тип</typeparam>
public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
where T : class
{
/// <summary>
/// Массив объектов, которые храним
/// </summary>
private T?[] _collection;
public int Count => _collection.Length;
public int SetMaxCount { set { if (value > 0) { _collection = new T?[value]; } } }
/// <summary>
/// Конструктор
/// </summary>
public MassiveGenericObjects()
{
_collection = Array.Empty<T?>();
}
public T? Get(int position)
{
// TODO проверка позиции
if (position >= _collection.Length || position < 0)
{
return null;
}
return _collection[position];
}
public int Insert(T obj)
{
// TODO вставка в свободное место набора
return Insert(obj, 0);
}
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;
}
}

View File

@ -0,0 +1,62 @@
using ProjectAircraftCarrier.Drawnings;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectAircraftCarrier.CollectionGenericObjects;
public class WarshipDockService : AbstractCompany
{
public WarshipDockService(int picWidth, int picHeight, ICollectionGenericObjects<DrawningWarship> collection) : base(picWidth, picHeight, collection)
{
}
protected override void DrawBackground(Graphics g)
{
//рисуем доки
int width = _pictureWidth / _placeSizeWidth;
int height = _pictureHeight / _placeSizeHeight;
Pen pen = new(Color.Black, 3);
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 / 2, j * _placeSizeHeight);
}
g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
}
}
protected override void SetObjectPosition()
{
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 + 5, posHeight * _placeSizeHeight + 10);
}
if (posWidth < width - 1)
{
posWidth++;
}
else
{
posWidth = 0;
posHeight--;
}
if (posHeight > height)
{
return;
}
}
}
}

View File

@ -29,12 +29,10 @@
private void InitializeComponent()
{
pictureBoxAircraftCarrier = new PictureBox();
buttonCreateAircraftCarrier = new Button();
buttonRight = new Button();
buttonUp = new Button();
buttonDown = new Button();
buttonLeft = new Button();
buttonCreateWarship = new Button();
comboBoxStrategy = new ComboBox();
buttonStrategyStep = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxAircraftCarrier).BeginInit();
@ -44,31 +42,22 @@
//
pictureBoxAircraftCarrier.Dock = DockStyle.Fill;
pictureBoxAircraftCarrier.Location = new Point(0, 0);
pictureBoxAircraftCarrier.Margin = new Padding(3, 4, 3, 4);
pictureBoxAircraftCarrier.Name = "pictureBoxAircraftCarrier";
pictureBoxAircraftCarrier.Size = new Size(803, 471);
pictureBoxAircraftCarrier.Size = new Size(918, 628);
pictureBoxAircraftCarrier.SizeMode = PictureBoxSizeMode.AutoSize;
pictureBoxAircraftCarrier.TabIndex = 0;
pictureBoxAircraftCarrier.TabStop = false;
//
// buttonCreateAircraftCarrier
//
buttonCreateAircraftCarrier.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonCreateAircraftCarrier.Location = new Point(12, 436);
buttonCreateAircraftCarrier.Name = "buttonCreateAircraftCarrier";
buttonCreateAircraftCarrier.Size = new Size(164, 23);
buttonCreateAircraftCarrier.TabIndex = 1;
buttonCreateAircraftCarrier.Text = "Создать авианосец";
buttonCreateAircraftCarrier.UseVisualStyleBackColor = true;
buttonCreateAircraftCarrier.Click += ButtonCreateAircraftCarrier_Click;
//
// buttonRight
//
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonRight.BackgroundImage = Properties.Resources.arrowRight;
buttonRight.BackgroundImageLayout = ImageLayout.Zoom;
buttonRight.Location = new Point(766, 439);
buttonRight.Location = new Point(875, 585);
buttonRight.Margin = new Padding(3, 4, 3, 4);
buttonRight.Name = "buttonRight";
buttonRight.Size = new Size(26, 22);
buttonRight.Size = new Size(30, 29);
buttonRight.TabIndex = 2;
buttonRight.UseVisualStyleBackColor = true;
buttonRight.Click += ButtonMove_Click;
@ -78,9 +67,10 @@
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonUp.BackgroundImage = Properties.Resources.arrowUp;
buttonUp.BackgroundImageLayout = ImageLayout.Zoom;
buttonUp.Location = new Point(735, 410);
buttonUp.Location = new Point(840, 547);
buttonUp.Margin = new Padding(3, 4, 3, 4);
buttonUp.Name = "buttonUp";
buttonUp.Size = new Size(26, 22);
buttonUp.Size = new Size(30, 29);
buttonUp.TabIndex = 3;
buttonUp.UseVisualStyleBackColor = true;
buttonUp.Click += ButtonMove_Click;
@ -90,9 +80,10 @@
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonDown.BackgroundImage = Properties.Resources.arrowDown;
buttonDown.BackgroundImageLayout = ImageLayout.Zoom;
buttonDown.Location = new Point(735, 439);
buttonDown.Location = new Point(840, 585);
buttonDown.Margin = new Padding(3, 4, 3, 4);
buttonDown.Name = "buttonDown";
buttonDown.Size = new Size(26, 22);
buttonDown.Size = new Size(30, 29);
buttonDown.TabIndex = 4;
buttonDown.UseVisualStyleBackColor = true;
buttonDown.Click += ButtonMove_Click;
@ -102,39 +93,31 @@
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonLeft.BackgroundImage = Properties.Resources.arrowLeft;
buttonLeft.BackgroundImageLayout = ImageLayout.Zoom;
buttonLeft.Location = new Point(704, 439);
buttonLeft.Location = new Point(805, 585);
buttonLeft.Margin = new Padding(3, 4, 3, 4);
buttonLeft.Name = "buttonLeft";
buttonLeft.Size = new Size(26, 22);
buttonLeft.Size = new Size(30, 29);
buttonLeft.TabIndex = 5;
buttonLeft.UseVisualStyleBackColor = true;
buttonLeft.Click += ButtonMove_Click;
//
// buttonCreateWarship
//
buttonCreateWarship.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonCreateWarship.Location = new Point(182, 436);
buttonCreateWarship.Name = "buttonCreateWarship";
buttonCreateWarship.Size = new Size(182, 23);
buttonCreateWarship.TabIndex = 6;
buttonCreateWarship.Text = "Создать военный корабль";
buttonCreateWarship.UseVisualStyleBackColor = true;
buttonCreateWarship.Click += ButtonCreateWarship_Click;
//
// comboBoxStrategy
//
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxStrategy.FormattingEnabled = true;
comboBoxStrategy.Items.AddRange(new object[] { "К центру", "К краю" });
comboBoxStrategy.Location = new Point(670, 12);
comboBoxStrategy.Location = new Point(766, 16);
comboBoxStrategy.Margin = new Padding(3, 4, 3, 4);
comboBoxStrategy.Name = "comboBoxStrategy";
comboBoxStrategy.Size = new Size(121, 23);
comboBoxStrategy.Size = new Size(138, 28);
comboBoxStrategy.TabIndex = 7;
//
// buttonStrategyStep
//
buttonStrategyStep.Location = new Point(716, 41);
buttonStrategyStep.Location = new Point(818, 55);
buttonStrategyStep.Margin = new Padding(3, 4, 3, 4);
buttonStrategyStep.Name = "buttonStrategyStep";
buttonStrategyStep.Size = new Size(75, 23);
buttonStrategyStep.Size = new Size(86, 31);
buttonStrategyStep.TabIndex = 8;
buttonStrategyStep.Text = "Шаг";
buttonStrategyStep.UseVisualStyleBackColor = true;
@ -142,18 +125,17 @@
//
// FormAircraftCarrier
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(803, 471);
ClientSize = new Size(918, 628);
Controls.Add(buttonStrategyStep);
Controls.Add(comboBoxStrategy);
Controls.Add(buttonCreateWarship);
Controls.Add(buttonLeft);
Controls.Add(buttonDown);
Controls.Add(buttonUp);
Controls.Add(buttonRight);
Controls.Add(buttonCreateAircraftCarrier);
Controls.Add(pictureBoxAircraftCarrier);
Margin = new Padding(3, 4, 3, 4);
Name = "FormAircraftCarrier";
StartPosition = FormStartPosition.CenterScreen;
Text = "Авианосец";
@ -165,12 +147,10 @@
#endregion
private PictureBox pictureBoxAircraftCarrier;
private Button buttonCreateAircraftCarrier;
private Button buttonRight;
private Button buttonUp;
private Button buttonDown;
private Button buttonLeft;
private Button buttonCreateWarship;
private ComboBox comboBoxStrategy;
private Button buttonStrategyStep;
}

View File

@ -27,6 +27,18 @@ public partial class FormAircraftCarrier : Form
/// </summary>
private AbstractStrategy? _strategy;
public DrawningWarship SetWarship
{
set
{
_drawningWarship = value;
_drawningWarship.SetPictureSize(pictureBoxAircraftCarrier.Width, pictureBoxAircraftCarrier.Height);
comboBoxStrategy.Enabled = true;
_strategy = null;
Draw();
}
}
/// <summary>
/// Конструктор формы
/// </summary>
@ -52,46 +64,6 @@ public partial class FormAircraftCarrier : Form
pictureBoxAircraftCarrier.Image = bmp;
}
private void CreateObject(string type)
{
Random random = new();
switch (type)
{
case nameof(DrawningWarship):
_drawningWarship = new DrawningWarship(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(DrawningAircraftCarrier):
_drawningWarship = new DrawningAircraftCarrier(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;
}
_drawningWarship.SetPictureSize(pictureBoxAircraftCarrier.Width, pictureBoxAircraftCarrier.Height);
_drawningWarship.SetPosition(random.Next(10, 100), random.Next(10, 100));
_strategy = null;
comboBoxStrategy.Enabled = true;
Draw();
}
/// <summary>
/// Обработка нажатия кнопки "Создать авианосец"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonCreateAircraftCarrier_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningAircraftCarrier));
/// <summary>
/// Обработка нажатия кнопки "Создать военный корабль"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonCreateWarship_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningWarship));
/// <summary>
/// Перемещение объекта по форме (нажатие кнопок навигации)
/// </summary>

View File

@ -0,0 +1,173 @@
namespace ProjectAircraftCarrier
{
partial class FormWarshipCollection
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
groupBoxTools = new GroupBox();
buttonRefresh = new Button();
buttonGoToCheck = new Button();
buttonRemoveWarship = new Button();
maskedTextBox = new MaskedTextBox();
buttonAddAircraftCarrier = new Button();
buttonAddWarship = new Button();
comboBoxSelectorCompany = new ComboBox();
pictureBox = new PictureBox();
groupBoxTools.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
SuspendLayout();
//
// groupBoxTools
//
groupBoxTools.Controls.Add(buttonRefresh);
groupBoxTools.Controls.Add(buttonGoToCheck);
groupBoxTools.Controls.Add(buttonRemoveWarship);
groupBoxTools.Controls.Add(maskedTextBox);
groupBoxTools.Controls.Add(buttonAddAircraftCarrier);
groupBoxTools.Controls.Add(buttonAddWarship);
groupBoxTools.Controls.Add(comboBoxSelectorCompany);
groupBoxTools.Dock = DockStyle.Right;
groupBoxTools.Location = new Point(905, 0);
groupBoxTools.Name = "groupBoxTools";
groupBoxTools.Size = new Size(205, 682);
groupBoxTools.TabIndex = 0;
groupBoxTools.TabStop = false;
groupBoxTools.Text = "Инструменты";
//
// buttonRefresh
//
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonRefresh.Location = new Point(6, 549);
buttonRefresh.Name = "buttonRefresh";
buttonRefresh.Size = new Size(193, 52);
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(6, 414);
buttonGoToCheck.Name = "buttonGoToCheck";
buttonGoToCheck.Size = new Size(193, 52);
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(6, 300);
buttonRemoveWarship.Name = "buttonRemoveWarship";
buttonRemoveWarship.Size = new Size(193, 52);
buttonRemoveWarship.TabIndex = 4;
buttonRemoveWarship.Text = "Удалить \r\nвоенный корабль";
buttonRemoveWarship.UseVisualStyleBackColor = true;
buttonRemoveWarship.Click += ButtonRemoveWarship_Click;
//
// maskedTextBox
//
maskedTextBox.Location = new Point(6, 267);
maskedTextBox.Mask = "00";
maskedTextBox.Name = "maskedTextBox";
maskedTextBox.Size = new Size(193, 27);
maskedTextBox.TabIndex = 3;
maskedTextBox.ValidatingType = typeof(int);
//
// buttonAddAircraftCarrier
//
buttonAddAircraftCarrier.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonAddAircraftCarrier.Location = new Point(6, 180);
buttonAddAircraftCarrier.Name = "buttonAddAircraftCarrier";
buttonAddAircraftCarrier.Size = new Size(193, 52);
buttonAddAircraftCarrier.TabIndex = 2;
buttonAddAircraftCarrier.Text = "Добавление\r\nавианосца";
buttonAddAircraftCarrier.UseVisualStyleBackColor = true;
buttonAddAircraftCarrier.Click += ButtonAddAircraftCarrier_Click;
//
// buttonAddWarship
//
buttonAddWarship.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonAddWarship.Location = new Point(6, 122);
buttonAddWarship.Name = "buttonAddWarship";
buttonAddWarship.Size = new Size(193, 52);
buttonAddWarship.TabIndex = 1;
buttonAddWarship.Text = "Добавление\r\nвоенного корабля";
buttonAddWarship.UseVisualStyleBackColor = true;
buttonAddWarship.Click += ButtonAddWarship_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(6, 26);
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
comboBoxSelectorCompany.Size = new Size(193, 28);
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(905, 682);
pictureBox.TabIndex = 1;
pictureBox.TabStop = false;
//
// FormWarshipCollection
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1110, 682);
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 comboBoxSelectorCompany;
private Button buttonAddWarship;
private MaskedTextBox maskedTextBox;
private Button buttonAddAircraftCarrier;
private PictureBox pictureBox;
private Button buttonRemoveWarship;
private Button buttonRefresh;
private Button buttonGoToCheck;
}
}

View File

@ -0,0 +1,166 @@
using ProjectAircraftCarrier.CollectionGenericObjects;
using ProjectAircraftCarrier.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 ProjectAircraftCarrier;
/// <summary>
/// Форма работы с компанией и её коллекцией
/// </summary>
public partial class FormWarshipCollection : Form
{
/// <summary>
/// Компания
/// </summary>
private AbstractCompany? _company = null;
/// <summary>
/// Конструктор
/// </summary>
public FormWarshipCollection()
{
InitializeComponent();
}
/// <summary>
/// Выбор компании
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
{
switch (comboBoxSelectorCompany.Text)
{
case "Хранилище":
_company = new WarshipDockService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects<DrawningWarship>());
break;
}
}
/// <summary>
/// Создание объекта класса-перемещение
/// </summary>
/// <param name="type">Тип создаваемого объекта</param>
private void CreateObject(string type)
{
if (_company == null)
{
return;
}
Random random = new();
DrawningWarship drawningWarship;
switch (type)
{
case nameof(DrawningWarship):
drawningWarship = new DrawningWarship(random.Next(100, 300), random.Next(1000, 3000), GetColor(random));
break;
case nameof(DrawningAircraftCarrier):
drawningWarship = new DrawningAircraftCarrier(random.Next(100, 300), random.Next(1000, 3000),
GetColor(random), GetColor(random),
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
break;
default:
return;
}
if (_company + drawningWarship != -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 ButtonAddWarship_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningWarship));
private void ButtonAddAircraftCarrier_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningAircraftCarrier));
private void ButtonRemoveWarship_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == null)
{
return;
}
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
int pos = Convert.ToInt32(maskedTextBox.Text);
if (_company - pos != null)
{
MessageBox.Show("Объект удалён");
pictureBox.Image = _company.Show();
}
else
{
MessageBox.Show("Не удалось удалить объект");
}
}
private void ButtonGoToCheck_Click(object sender, EventArgs e)
{
if (_company == null)
{
return;
}
DrawningWarship? warship = null;
int counter = 100;
while (warship == null)
{
warship = _company.GetRandomObject();
counter--;
if (counter <= 0)
{
break;
}
}
if (warship == null)
{
return;
}
FormAircraftCarrier form = new()
{
SetWarship = warship
};
form.ShowDialog();
}
private void ButtonRefresh_Click(object sender, EventArgs e)
{
if (_company == null)
{
return;
}
pictureBox.Image = _company.Show();
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -11,7 +11,7 @@ namespace ProjectAircraftCarrier
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.Run(new FormAircraftCarrier());
Application.Run(new FormWarshipCollection());
}
}
}