LabWork04 #6

Merged
sheym merged 10 commits from LabWork04 into LabWork05 2024-04-12 12:47:40 +04:00
10 changed files with 736 additions and 87 deletions
Showing only changes of commit e1c1cd865e - Show all commits

View File

@ -0,0 +1,116 @@
using ProjectAircraftCarrier_.Drawnings;
namespace ProjectAircraftCarrier_.CollectionGenericObjects;
/// <summary>
/// Абстракция компании, хранящий коллекцию автомобилей
/// </summary>
public abstract class AbstractCompany
{
/// <summary>
/// Размер места (ширина)
/// </summary>
protected readonly int _placeSizeWidth = 300;
/// <summary>
/// Размер места (высота)
/// </summary>
protected readonly int _placeSizeHeight = 80;
/// <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 bool operator +(AbstractCompany company, DrawningWarship warship)
{
return company._collection?.Insert(warship) ?? false;
}
/// <summary>
/// Перегрузка оператора удаления для класса
/// </summary>
/// <param name="company">Компания</param>
/// <param name="position">Номер удаляемого объекта</param>
/// <returns></returns>
public static bool operator -(AbstractCompany company, int position)
{
return company._collection?.Remove(position) ?? false;
}
/// <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);
SetObjectsPosition();
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 SetObjectsPosition();
}

View File

@ -27,12 +27,24 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
public T? Get(int position)
{
// TODO проверка позиции
if (position < 0 || position > Count)
{
return null;
}
return _collection[position];
}
public bool Insert(T obj)
{
// TODO вставка в свободное место набора
for (int i = 0; i < Count; i++)
{
if (_collection[i] == null)
{
_collection[i] = obj;
return true;
}
}
return false;
}
@ -43,6 +55,35 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
// ищется свободное место после этой позиции и идет вставка туда
// если нет после, ищем до
// TODO вставка
if (position < 0 || position > Count)
{
return false;
}
if (_collection[position] == null)
{
_collection[position] = obj;
return true;
}
for (int i = position + 1; i < Count; i++)
{
if (_collection[i] == null)
{
_collection[i] = obj;
return true;
}
}
for (int i = position - 1; i >= 0; i--)
{
if (_collection[i] == null)
{
_collection[i] = obj;
return true;
}
}
return false;
}
@ -50,6 +91,12 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
{
// TODO проверка позиции
// TODO удаление объекта из массива, присвоив элементу массива значение null
if (position < 0 || position > Count || _collection[position] == null)
{
return false;
}
_collection[position] = null;
return true;
}
}

View File

@ -0,0 +1,61 @@

using ProjectAircraftCarrier_.Drawnings;
namespace ProjectAircraftCarrier_.CollectionGenericObjects;
public class WarshipSharingService : AbstractCompany
{
public WarshipSharingService(int picWidth, int picHeight, ICollectionGenericObjects<DrawningWarship> collection) : base(picWidth, picHeight, collection)
{
}
protected override void DrawBackground(Graphics g)
{
Pen pen = new(Color.Black, 2);
Pen widerPen = new(Color.Black, 5);
for (int i = 0; i < _pictureHeight / _placeSizeHeight; i++)
{
int y = _placeSizeHeight;
y *= i;
for (int j = 0; j <= _pictureWidth / _placeSizeWidth; j++)
{
int x = _placeSizeWidth;
x *= j;
g.DrawLine(widerPen, x, y, x + _placeSizeWidth / 2, y);
g.DrawLine(widerPen, x, y + _placeSizeHeight - 10, x + _placeSizeWidth / 2, y + _placeSizeHeight - 10);
g.DrawLine(pen, x, y, x, y + _placeSizeHeight - 10);
g.DrawLine(pen, x + _placeSizeWidth / 2, y, x + _placeSizeWidth / 2, y + _placeSizeHeight - 10);
}
}
}
protected override void SetObjectsPosition()
{
int n = 0;
int m = 0;
for (int i = 0; i < (_collection?.Count ?? 0); i++)
{
if (_collection?.Get(i) != null)
{
int x = 5 + _placeSizeWidth * n;
int y = (10 + _placeSizeHeight * (_pictureHeight / _placeSizeHeight - 1)) - _placeSizeHeight * m;
_collection?.Get(i)?.SetPictureSize(_pictureWidth, _pictureHeight);
_collection?.Get(i)?.SetPosition(x, y);
}
if (n < _pictureWidth / _placeSizeWidth)
n++;
else
{
n = 0;
m++;
}
}
}
}

View File

@ -87,12 +87,12 @@ public class DrawningWarship
/// <summary>
/// Конструктор для наследников
/// </summary>
/// <param name="drawningCarrierWidth">Ширина прорисовки военного корабля</param>
/// <param name="drawningCarrierHeight">Высота прорисовки военного корабля</param>
protected DrawningWarship(int drawningCarrierWidth, int drawningCarrierHeight) : this()
/// <param name="DrawningWarshiprierWidth">Ширина прорисовки военного корабля</param>
/// <param name="DrawningWarshiprierHeight">Высота прорисовки военного корабля</param>
protected DrawningWarship(int DrawningWarshiprierWidth, int DrawningWarshiprierHeight) : this()
{
_drawningWarshipWidth = drawningCarrierWidth;
_drawningWarshipHeight = drawningCarrierHeight;
_drawningWarshipWidth = DrawningWarshiprierWidth;
_drawningWarshipHeight = DrawningWarshiprierHeight;
}
/// <summary>

View File

@ -29,12 +29,10 @@
private void InitializeComponent()
{
pictureBoxAircraftCarrier = new PictureBox();
buttonCreateAircraftCarrier = new Button();
buttonLeft = new Button();
buttonDown = new Button();
buttonRight = new Button();
buttonUp = new Button();
buttonCreateWarship = new Button();
comboBoxStrategy = new ComboBox();
buttonStrategyStep = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxAircraftCarrier).BeginInit();
@ -45,27 +43,16 @@
pictureBoxAircraftCarrier.Dock = DockStyle.Fill;
pictureBoxAircraftCarrier.Location = new Point(0, 0);
pictureBoxAircraftCarrier.Name = "pictureBoxAircraftCarrier";
pictureBoxAircraftCarrier.Size = new Size(1167, 653);
pictureBoxAircraftCarrier.Size = new Size(1392, 778);
pictureBoxAircraftCarrier.TabIndex = 0;
pictureBoxAircraftCarrier.TabStop = false;
//
// buttonCreateAircraftCarrier
//
buttonCreateAircraftCarrier.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonCreateAircraftCarrier.Location = new Point(12, 601);
buttonCreateAircraftCarrier.Name = "buttonCreateAircraftCarrier";
buttonCreateAircraftCarrier.Size = new Size(207, 40);
buttonCreateAircraftCarrier.TabIndex = 1;
buttonCreateAircraftCarrier.Text = "Создать авианосец";
buttonCreateAircraftCarrier.UseVisualStyleBackColor = true;
buttonCreateAircraftCarrier.Click += ButtonCreateAircraftCarrier_Click;
//
// buttonLeft
//
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonLeft.BackgroundImage = Properties.Resources.arrowLeft;
buttonLeft.BackgroundImageLayout = ImageLayout.Stretch;
buttonLeft.Location = new Point(1030, 606);
buttonLeft.Location = new Point(1255, 731);
buttonLeft.Name = "buttonLeft";
buttonLeft.Size = new Size(35, 35);
buttonLeft.TabIndex = 2;
@ -77,7 +64,7 @@
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonDown.BackgroundImage = Properties.Resources.arrowDown;
buttonDown.BackgroundImageLayout = ImageLayout.Stretch;
buttonDown.Location = new Point(1071, 606);
buttonDown.Location = new Point(1296, 731);
buttonDown.Name = "buttonDown";
buttonDown.Size = new Size(35, 35);
buttonDown.TabIndex = 3;
@ -89,7 +76,7 @@
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonRight.BackgroundImage = Properties.Resources.arrowRight;
buttonRight.BackgroundImageLayout = ImageLayout.Stretch;
buttonRight.Location = new Point(1112, 606);
buttonRight.Location = new Point(1337, 731);
buttonRight.Name = "buttonRight";
buttonRight.Size = new Size(35, 35);
buttonRight.TabIndex = 4;
@ -101,37 +88,28 @@
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonUp.BackgroundImage = Properties.Resources.arrowUp;
buttonUp.BackgroundImageLayout = ImageLayout.Stretch;
buttonUp.Location = new Point(1071, 565);
buttonUp.Location = new Point(1296, 690);
buttonUp.Name = "buttonUp";
buttonUp.Size = new Size(35, 35);
buttonUp.TabIndex = 5;
buttonUp.UseVisualStyleBackColor = true;
buttonUp.Click += ButtonMove_Click;
//
// buttonCreateWarship
//
buttonCreateWarship.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonCreateWarship.Location = new Point(244, 601);
buttonCreateWarship.Name = "buttonCreateWarship";
buttonCreateWarship.Size = new Size(273, 40);
buttonCreateWarship.TabIndex = 7;
buttonCreateWarship.Text = "Создать военный корабль";
buttonCreateWarship.UseVisualStyleBackColor = true;
buttonCreateWarship.Click += ButtonCreateWarship_Click;
//
// comboBoxStrategy
//
comboBoxStrategy.Anchor = AnchorStyles.Top | AnchorStyles.Right;
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxStrategy.FormattingEnabled = true;
comboBoxStrategy.Items.AddRange(new object[] { "К центру", "К краю" });
comboBoxStrategy.Location = new Point(943, 12);
comboBoxStrategy.Location = new Point(1168, 12);
comboBoxStrategy.Name = "comboBoxStrategy";
comboBoxStrategy.Size = new Size(212, 38);
comboBoxStrategy.TabIndex = 8;
//
// buttonStrategyStep
//
buttonStrategyStep.Location = new Point(1024, 56);
buttonStrategyStep.Anchor = AnchorStyles.Top | AnchorStyles.Right;
buttonStrategyStep.Location = new Point(1249, 56);
buttonStrategyStep.Name = "buttonStrategyStep";
buttonStrategyStep.Size = new Size(131, 40);
buttonStrategyStep.TabIndex = 9;
@ -143,15 +121,13 @@
//
AutoScaleDimensions = new SizeF(12F, 30F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1167, 653);
ClientSize = new Size(1392, 778);
Controls.Add(buttonStrategyStep);
Controls.Add(comboBoxStrategy);
Controls.Add(buttonCreateWarship);
Controls.Add(buttonUp);
Controls.Add(buttonRight);
Controls.Add(buttonDown);
Controls.Add(buttonLeft);
Controls.Add(buttonCreateAircraftCarrier);
Controls.Add(pictureBoxAircraftCarrier);
Name = "FormAircraftCarrier";
Text = "Авианосец";
@ -162,12 +138,10 @@
#endregion
private PictureBox pictureBoxAircraftCarrier;
private Button buttonCreateAircraftCarrier;
private Button buttonLeft;
private Button buttonDown;
private Button buttonRight;
private Button buttonUp;
private Button buttonCreateWarship;
private ComboBox comboBoxStrategy;
private Button buttonStrategyStep;
}

View File

@ -18,6 +18,22 @@ public partial class FormAircraftCarrier : Form
/// </summary>
private AbstractStrategy? _strategy;
/// <summary>
/// Получение объекта
/// </summary>
public DrawningWarship SetWarship
{
set
{
_drawningWarship = value;
_drawningWarship.SetPictureSize(pictureBoxAircraftCarrier.Width, pictureBoxAircraftCarrier.Height);
comboBoxStrategy.Enabled = true;
_strategy = null;
Draw();
}
}
/// <summary>
/// Конструктор формы
/// </summary>
@ -43,51 +59,6 @@ public partial class FormAircraftCarrier : Form
pictureBoxAircraftCarrier.Image = bmp;
}
/// <summary>
/// Создание объекта класса-перемещения
/// </summary>
/// <param name="type">Тип создаваемого объекта</param>
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)), 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();
maskedTextBoxPosition = 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(maskedTextBoxPosition);
groupBoxTools.Controls.Add(buttonAddAircraftCarrier);
groupBoxTools.Controls.Add(buttonAddWarship);
groupBoxTools.Controls.Add(comboBoxSelectorCompany);
groupBoxTools.Dock = DockStyle.Right;
groupBoxTools.Location = new Point(1126, 0);
groupBoxTools.Name = "groupBoxTools";
groupBoxTools.Size = new Size(326, 912);
groupBoxTools.TabIndex = 0;
groupBoxTools.TabStop = false;
groupBoxTools.Text = "Инструменты";
//
// buttonRefresh
//
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonRefresh.Location = new Point(6, 767);
buttonRefresh.Name = "buttonRefresh";
buttonRefresh.Size = new Size(314, 72);
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, 595);
buttonGoToCheck.Name = "buttonGoToCheck";
buttonGoToCheck.Size = new Size(314, 72);
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, 432);
buttonRemoveWarship.Name = "buttonRemoveWarship";
buttonRemoveWarship.Size = new Size(314, 72);
buttonRemoveWarship.TabIndex = 4;
buttonRemoveWarship.Text = "Удаление военного корабля";
buttonRemoveWarship.UseVisualStyleBackColor = true;
buttonRemoveWarship.Click += ButtonRemoveWarship_Click;
//
// maskedTextBoxPosition
//
maskedTextBoxPosition.Location = new Point(6, 391);
maskedTextBoxPosition.Mask = "00";
maskedTextBoxPosition.Name = "maskedTextBoxPosition";
maskedTextBoxPosition.Size = new Size(314, 35);
maskedTextBoxPosition.TabIndex = 3;
maskedTextBoxPosition.ValidatingType = typeof(int);
//
// buttonAddAircraftCarrier
//
buttonAddAircraftCarrier.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonAddAircraftCarrier.Location = new Point(6, 232);
buttonAddAircraftCarrier.Name = "buttonAddAircraftCarrier";
buttonAddAircraftCarrier.Size = new Size(314, 72);
buttonAddAircraftCarrier.TabIndex = 2;
buttonAddAircraftCarrier.Text = "Добавление авианосца";
buttonAddAircraftCarrier.UseVisualStyleBackColor = true;
buttonAddAircraftCarrier.Click += ButtonAddAircraftCarrier_Click;
//
// buttonAddWarship
//
buttonAddWarship.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonAddWarship.Location = new Point(6, 154);
buttonAddWarship.Name = "buttonAddWarship";
buttonAddWarship.Size = new Size(314, 72);
buttonAddWarship.TabIndex = 1;
buttonAddWarship.Text = "Добавление военного корабля";
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, 34);
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
comboBoxSelectorCompany.Size = new Size(314, 38);
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(1126, 912);
pictureBox.TabIndex = 1;
pictureBox.TabStop = false;
//
// FormWarshipCollection
//
AutoScaleDimensions = new SizeF(12F, 30F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1452, 912);
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 Button buttonAddWarship;
private ComboBox comboBoxSelectorCompany;
private Button buttonAddAircraftCarrier;
private PictureBox pictureBox;
private Button buttonRefresh;
private Button buttonGoToCheck;
private Button buttonRemoveWarship;
private MaskedTextBox maskedTextBoxPosition;
}
}

View File

@ -0,0 +1,187 @@
using ProjectAircraftCarrier_.CollectionGenericObjects;
using ProjectAircraftCarrier_.Drawnings;
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 WarshipSharingService(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):
// TODO вызов диалогового окна для выбора цвета
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)), Convert.ToBoolean(random.Next(0, 2)));
break;
default:
return;
}
if (_company + drawningWarship)
{
MessageBox.Show("Объект добавлен");
pictureBox.Image = _company.Show();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
/// <summary>
/// Получение цвета
/// </summary>
/// <param name="random">Генератор случайных чисел</param>
/// <returns></returns>
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;
}
/// <summary>
/// Добавление военного корабля
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonAddWarship_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningWarship));
/// <summary>
/// Добавление авианосца
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonAddAircraftCarrier_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningAircraftCarrier));
/// <summary>
/// Удаление объекта
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonRemoveWarship_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text) || _company == null)
{
return;
}
if (MessageBox.Show("Удалить объект", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
{
return;
}
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
if (_company - pos)
{
MessageBox.Show("Объект удален");
pictureBox.Image = _company.Show();
}
else
{
MessageBox.Show("Не удалось удалить объект");
}
}
/// <summary>
/// Передача объекта в другую форму
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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();
}
/// <summary>
/// Перерисовка коллекции
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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());
}
}
}