Compare commits

...

2 Commits

Author SHA1 Message Date
3d664c461e LabWork3 2024-03-11 13:38:15 +03:00
be605e1ae1 Коллекция объектов 2024-03-09 21:25:28 +03:00
11 changed files with 790 additions and 81 deletions

View File

@ -0,0 +1,102 @@
using AntiAircraftGun.Drawnings;
namespace AntiAircraftGun.CollectionGenericObjects;
public abstract class AbstractCompany
{
/// <summary>
/// Размер места (ширина)
/// </summary>
protected readonly int _placeSizeWidth = 210;
/// <summary>
/// Размер места (высота)
/// </summary>
protected readonly int _placeSizeHeight = 130;
/// <summary>
/// Ширина окна
/// </summary>
protected readonly int _pictureWidth;
/// <summary>
/// Высота окна
/// </summary>
protected readonly int _pictureHeight;
/// <summary>
/// Коллекция установок
/// </summary>
protected ICollectionGenericObjects<DrawningGun>? _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<DrawningGun> collection)
{
_pictureWidth = picWidth;
_pictureHeight = picHeight;
_collection = collection;
_collection.SetMaxCount = GetMaxCount;
}
/// <summary>
/// Перегрузка оператора сложения для класса
/// </summary>
/// <param name="company">Компания</param>
/// <param name="gun">Добавляемый объект</param>
/// <returns></returns>
public static int operator +(AbstractCompany company, DrawningGun gun)
{
return company._collection.Insert(gun);
}
/// <summary>
/// Перегрузка оператора удаления для класса
/// </summary>
/// <param name="company">Компания</param>
/// <param name="position">Номер удаляемого объекта</param>
/// <returns></returns>
public static DrawningGun? operator -(AbstractCompany company, int position)
{
return company._collection?.Remove(position);
}
/// <summary>
/// Получение случайного объекта из коллекции
/// </summary>
/// <returns></returns>
public DrawningGun? 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);
DrawBackgound(graphics);
SetObjectsPosition();
for (int i = 0; i < (_collection?.Count ?? 0); ++i)
{
DrawningGun? obj = _collection?.Get(i);
obj?.DrawTransport(graphics);
}
return bitmap;
}
/// <summary>
/// Вывод заднего фона
/// </summary>
/// <param name="g"></param>
protected abstract void DrawBackgound(Graphics g);
/// <summary>
/// Расстановка объектов
/// </summary>
protected abstract void SetObjectsPosition();
}

View File

@ -0,0 +1,61 @@
using AntiAircraftGun.Drawnings;
namespace AntiAircraftGun.CollectionGenericObjects;
/// <summary>
/// Класс, отвечающий за базу
/// </summary>
public class GunSharingService : AbstractCompany
{
public GunSharingService(int picWidth, int picHeight, ICollectionGenericObjects<DrawningGun> collection) : base(picWidth, picHeight, collection)
{
}
private int offsetX = 30;
/// <summary>
/// Отрисовка базы
/// </summary>
/// <param name="g">Графика</param>
protected override void DrawBackgound(Graphics g)
{
Pen pen = new Pen(Color.Black, 4);
int maxCountX = (_pictureWidth / _placeSizeWidth);
int maxCountY = (_pictureHeight / _placeSizeHeight);
for (int i = 0; i < maxCountX; i++)
{
for (int j = 0; j < maxCountY; j++)
{
g.DrawLine(pen, i * offsetX + i * _placeSizeWidth, j * _placeSizeHeight, _placeSizeWidth + i * offsetX + i * _placeSizeWidth, j * _placeSizeHeight);
g.DrawLine(pen, i * offsetX + i * _placeSizeWidth, j * _placeSizeHeight, i * offsetX + i * _placeSizeWidth, _placeSizeHeight + j * _placeSizeHeight);
g.DrawLine(pen, i * offsetX + i * _placeSizeWidth, _placeSizeHeight + j * _placeSizeHeight, _placeSizeWidth + i * offsetX + i * _placeSizeWidth, _placeSizeHeight + j * _placeSizeHeight);
}
}
}
/// <summary>
/// Установка объекта в базу
/// </summary>
protected override void SetObjectsPosition()
{
int maxCountX = _pictureWidth / _placeSizeWidth;
int maxCountY = _pictureHeight / _placeSizeHeight;
int boarderOffsetX = 10;
int boarderOffsetY = 10;
int currentIndex = -1;
for (int j = 0; j < maxCountY; j++)
{
for (int i = 0; i < maxCountX; i++)
{
currentIndex++;
if (_collection.Get(currentIndex) == null) continue;
_collection.Get(currentIndex).SetPictureSize(_pictureWidth, _pictureHeight);
_collection.Get(currentIndex).SetPosition(boarderOffsetX + i * _placeSizeWidth + i * offsetX, boarderOffsetY + j * _placeSizeHeight);
}
}
}
}

View File

@ -0,0 +1,45 @@
namespace AntiAircraftGun.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,103 @@
using System.Diagnostics;
namespace AntiAircraftGun.CollectionGenericObjects;
/// <summary>
/// Параметризованный набор объектов
/// </summary>
/// <typeparam name="T">Параметр: ограничение - ссылочный тип</typeparam>
internal 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)
{
if (_collection.Length > 0)
{
Array.Resize(ref _collection, value);
}
else
{
_collection = new T?[value];
}
}
}
}
/// <summary>
/// Конструктор
/// </summary>
public MassiveGenericObjects()
{
_collection = Array.Empty<T?>();
}
public T? Get(int position)
{
// TODO проверка позиции
if (_collection[position] == null)
return null;
return _collection[position];
}
public int Insert(T obj)
{
// TODO вставка в свободное место набора
for (int i = 0; i < Count; i++)
{
if (InsertingElementCollection(i, obj)) return i;
}
return -1;
}
public int Insert(T obj, int position)
{
// TODO проверка позиции
// TODO проверка, что элемент массива по этой позиции пустой, если нет, то
// ищется свободное место после этой позиции и идет вставка туда
// если нет после, ищем до
// TODO вставка
if (InsertingElementCollection(position, obj)) return position;
for (int i = position + 1; i < Count; i++)
{
if (InsertingElementCollection(i, obj)) return position;
}
for (int i = position - 1; i >= 0; i--)
{
if (InsertingElementCollection(i, obj)) return position;
}
return -1;
}
public T? Remove(int position)
{
// TODO проверка позиции
// TODO удаление объекта из массива, присвоив элементу массива значение null
if (_collection[position] == null) return null;
T? temp = _collection[position];
_collection[position] = null;
return temp;
}
/// <summary>
/// Если элемент массива пустой, то вставляем новый элемент
/// </summary>
/// <param name="index">Индекс элемента</param>
/// <param name="obj">Элемент</param>
/// <returns>false - элемент массива != null, true - = null</returns>
private bool InsertingElementCollection(int index, T obj)
{
if (_collection[index] != null) return false;
_collection[index] = obj;
return true;
}
}

View File

@ -19,6 +19,10 @@ public class DrawningAntiAircraftGun:DrawningGun
{ {
EntityGun = new EntityAntiAircraftGun(speed,weight,bodyColor,optionalElementsColor,barrelLenth,hatchHeight,radar); EntityGun = new EntityAntiAircraftGun(speed,weight,bodyColor,optionalElementsColor,barrelLenth,hatchHeight,radar);
} }
/// <summary>
/// Прорисовка объекта
/// </summary>
/// <param name="g"></param>
public override void DrawTransport(Graphics g) public override void DrawTransport(Graphics g)
{ {

View File

@ -29,12 +29,10 @@
private void InitializeComponent() private void InitializeComponent()
{ {
pictureBoxAntiAircraftGun = new PictureBox(); pictureBoxAntiAircraftGun = new PictureBox();
buttonCreate = new Button();
buttonDown = new Button(); buttonDown = new Button();
buttonLeft = new Button(); buttonLeft = new Button();
buttonUp = new Button(); buttonUp = new Button();
buttonRight = new Button(); buttonRight = new Button();
buttonCreateGun = new Button();
comboBoxStrategy = new ComboBox(); comboBoxStrategy = new ComboBox();
buttonStrategyStep = new Button(); buttonStrategyStep = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxAntiAircraftGun).BeginInit(); ((System.ComponentModel.ISupportInitialize)pictureBoxAntiAircraftGun).BeginInit();
@ -49,17 +47,6 @@
pictureBoxAntiAircraftGun.TabIndex = 8; pictureBoxAntiAircraftGun.TabIndex = 8;
pictureBoxAntiAircraftGun.TabStop = false; pictureBoxAntiAircraftGun.TabStop = false;
// //
// buttonCreate
//
buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonCreate.Location = new Point(12, 352);
buttonCreate.Name = "buttonCreate";
buttonCreate.Size = new Size(261, 29);
buttonCreate.TabIndex = 1;
buttonCreate.Text = "Создать зенитную установку";
buttonCreate.UseVisualStyleBackColor = true;
buttonCreate.Click += ButtonCreate_Click;
//
// buttonDown // buttonDown
// //
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
@ -108,17 +95,6 @@
buttonRight.UseVisualStyleBackColor = true; buttonRight.UseVisualStyleBackColor = true;
buttonRight.Click += ButtonMove_Click; buttonRight.Click += ButtonMove_Click;
// //
// buttonCreateGun
//
buttonCreateGun.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonCreateGun.Location = new Point(288, 352);
buttonCreateGun.Name = "buttonCreateGun";
buttonCreateGun.Size = new Size(203, 29);
buttonCreateGun.TabIndex = 7;
buttonCreateGun.Text = "Создать установку";
buttonCreateGun.UseVisualStyleBackColor = true;
buttonCreateGun.Click += buttonCreateGun_Click;
//
// comboBoxStrategy // comboBoxStrategy
// //
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
@ -147,12 +123,10 @@
ClientSize = new Size(939, 393); ClientSize = new Size(939, 393);
Controls.Add(buttonStrategyStep); Controls.Add(buttonStrategyStep);
Controls.Add(comboBoxStrategy); Controls.Add(comboBoxStrategy);
Controls.Add(buttonCreateGun);
Controls.Add(buttonRight); Controls.Add(buttonRight);
Controls.Add(buttonUp); Controls.Add(buttonUp);
Controls.Add(buttonLeft); Controls.Add(buttonLeft);
Controls.Add(buttonDown); Controls.Add(buttonDown);
Controls.Add(buttonCreate);
Controls.Add(pictureBoxAntiAircraftGun); Controls.Add(pictureBoxAntiAircraftGun);
Name = "FormAntiAircraftGun"; Name = "FormAntiAircraftGun";
Text = "Зенитная установка"; Text = "Зенитная установка";
@ -163,12 +137,10 @@
#endregion #endregion
private PictureBox pictureBoxAntiAircraftGun; private PictureBox pictureBoxAntiAircraftGun;
private Button buttonCreate;
private Button buttonDown; private Button buttonDown;
private Button buttonLeft; private Button buttonLeft;
private Button buttonUp; private Button buttonUp;
private Button buttonRight; private Button buttonRight;
private Button buttonCreateGun;
private ComboBox comboBoxStrategy; private ComboBox comboBoxStrategy;
private Button buttonStrategyStep; private Button buttonStrategyStep;
} }

View File

@ -9,15 +9,33 @@ namespace AntiAircraftGun
/// Стратегия перемещения /// Стратегия перемещения
/// </summary> /// </summary>
private AbstractStrategy? _abstractStrategy; private AbstractStrategy? _abstractStrategy;
/// <summary>
/// Поле-объект для прорисовки объекта
/// </summary>
private DrawningGun? _drawningGun; private DrawningGun? _drawningGun;
/// <summary>
/// Конуструктор формы
/// </summary>
public FormAntiAircraftGun() public FormAntiAircraftGun()
{ {
InitializeComponent(); InitializeComponent();
_abstractStrategy = null; _abstractStrategy = null;
} }
/// <summary>
/// Получение объекта
/// </summary>
public DrawningGun SetGun
{
set
{
_drawningGun = value;
_drawningGun.SetPictureSize(pictureBoxAntiAircraftGun.Width, pictureBoxAntiAircraftGun.Height);
comboBoxStrategy.Enabled = true;
_abstractStrategy = null;
Draw();
}
}
/// <summary> /// <summary>
/// Метод рисования машины /// Метод рисования машины
/// </summary> /// </summary>
@ -33,55 +51,6 @@ namespace AntiAircraftGun
pictureBoxAntiAircraftGun.Image = bmp; pictureBoxAntiAircraftGun.Image = bmp;
_drawningGun.DrawTransport(gr); _drawningGun.DrawTransport(gr);
} }
private void CreateObj(string type)
{
Random random = new();
switch (type)
{
case nameof(DrawningGun):
_drawningGun = new DrawningGun(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(DrawningAntiAircraftGun):
_drawningGun = new DrawningAntiAircraftGun(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)),
random.Next(10, 100),
Convert.ToBoolean(random.Next(0, 2)),
Convert.ToBoolean(random.Next(0, 2)));
break;
}
_drawningGun.SetPictureSize(pictureBoxAntiAircraftGun.Width, pictureBoxAntiAircraftGun.Height);
_drawningGun.SetPosition(random.Next(10, 100), random.Next(10, 100));
_abstractStrategy = null;
comboBoxStrategy.Enabled = true;
Draw();
}
/// <summary>
/// Обработка нажатия "Создать зенитную установку"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonCreate_Click(object sender, EventArgs e)
{
CreateObj(nameof(DrawningAntiAircraftGun));
}
/// <summary>
/// Обработка нажатия "Создать установку"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonCreateGun_Click(object sender, EventArgs e)
{
CreateObj(nameof(DrawningGun));
}
private void ButtonMove_Click(object sender, EventArgs e) private void ButtonMove_Click(object sender, EventArgs e)
{ {
if (_drawningGun == null) if (_drawningGun == null)

View File

@ -0,0 +1,173 @@
namespace AntiAircraftGun
{
partial class FormGunCollections
{
/// <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()
{
groupBox1 = new GroupBox();
buttonRefresh = new Button();
buttonGoToCheck = new Button();
buttonRemoveGun = new Button();
maskedTextBox = new MaskedTextBox();
buttonAddAntiAircraftGun = new Button();
buttonAddGun = new Button();
comboBoxSelectorCompany = new ComboBox();
pictureBox = new PictureBox();
groupBox1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
SuspendLayout();
//
// groupBox1
//
groupBox1.Controls.Add(buttonRefresh);
groupBox1.Controls.Add(buttonGoToCheck);
groupBox1.Controls.Add(buttonRemoveGun);
groupBox1.Controls.Add(maskedTextBox);
groupBox1.Controls.Add(buttonAddAntiAircraftGun);
groupBox1.Controls.Add(buttonAddGun);
groupBox1.Controls.Add(comboBoxSelectorCompany);
groupBox1.Dock = DockStyle.Right;
groupBox1.Location = new Point(940, 0);
groupBox1.Name = "groupBox1";
groupBox1.Size = new Size(235, 669);
groupBox1.TabIndex = 0;
groupBox1.TabStop = false;
groupBox1.Text = "Инструменты";
//
// buttonRefresh
//
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonRefresh.Location = new Point(32, 578);
buttonRefresh.Name = "buttonRefresh";
buttonRefresh.Size = new Size(171, 70);
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(32, 465);
buttonGoToCheck.Name = "buttonGoToCheck";
buttonGoToCheck.Size = new Size(171, 70);
buttonGoToCheck.TabIndex = 5;
buttonGoToCheck.Text = "Передать на тесты";
buttonGoToCheck.UseVisualStyleBackColor = true;
buttonGoToCheck.Click += ButtonGoToCheck_Click;
//
// buttonRemoveGun
//
buttonRemoveGun.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonRemoveGun.Location = new Point(32, 364);
buttonRemoveGun.Name = "buttonRemoveGun";
buttonRemoveGun.Size = new Size(171, 70);
buttonRemoveGun.TabIndex = 4;
buttonRemoveGun.Text = "Удалить установку";
buttonRemoveGun.UseVisualStyleBackColor = true;
buttonRemoveGun.Click += ButtonRemoveGun_Click;
//
// maskedTextBox
//
maskedTextBox.Location = new Point(32, 292);
maskedTextBox.Mask = "00";
maskedTextBox.Name = "maskedTextBox";
maskedTextBox.Size = new Size(171, 27);
maskedTextBox.TabIndex = 3;
maskedTextBox.ValidatingType = typeof(int);
//
// buttonAddAntiAircraftGun
//
buttonAddAntiAircraftGun.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonAddAntiAircraftGun.Location = new Point(33, 191);
buttonAddAntiAircraftGun.Name = "buttonAddAntiAircraftGun";
buttonAddAntiAircraftGun.Size = new Size(171, 70);
buttonAddAntiAircraftGun.TabIndex = 2;
buttonAddAntiAircraftGun.Text = "Добавление зенитной установки";
buttonAddAntiAircraftGun.UseVisualStyleBackColor = true;
buttonAddAntiAircraftGun.Click += ButtonAddAntiAircraftGun_Click;
//
// buttonAddGun
//
buttonAddGun.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonAddGun.Location = new Point(32, 106);
buttonAddGun.Name = "buttonAddGun";
buttonAddGun.Size = new Size(171, 70);
buttonAddGun.TabIndex = 1;
buttonAddGun.Text = "Добавление установки";
buttonAddGun.UseVisualStyleBackColor = true;
buttonAddGun.Click += ButtonAddGun_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(33, 43);
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
comboBoxSelectorCompany.Size = new Size(171, 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(940, 669);
pictureBox.TabIndex = 1;
pictureBox.TabStop = false;
//
// FormGunCollections
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1175, 669);
Controls.Add(pictureBox);
Controls.Add(groupBox1);
Name = "FormGunCollections";
Text = "Коллекция установок";
groupBox1.ResumeLayout(false);
groupBox1.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
ResumeLayout(false);
}
#endregion
private GroupBox groupBox1;
private Button buttonAddGun;
private ComboBox comboBoxSelectorCompany;
private MaskedTextBox maskedTextBox;
private Button buttonAddAntiAircraftGun;
private PictureBox pictureBox;
private Button buttonRemoveGun;
private Button buttonRefresh;
private Button buttonGoToCheck;
}
}

View File

@ -0,0 +1,160 @@
using AntiAircraftGun.CollectionGenericObjects;
using AntiAircraftGun.Drawnings;
namespace AntiAircraftGun;
public partial class FormGunCollections : Form
{
/// <summary>
///
/// </summary>
private AbstractCompany? _company = null;
/// <summary>
/// Конструктор
/// </summary>
public FormGunCollections()
{
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 GunSharingService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects<DrawningGun>());
break;
}
}
/// <summary>
/// Создание объекта класса перемещения
/// </summary>
/// <param name="type">Тип создаваемого объекта</param>
private void CreateObj(string type)
{
if (_company == null)
{
return;
}
DrawningGun _drawningGun;
Random random = new();
switch (type)
{
case nameof(DrawningGun):
_drawningGun = new DrawningGun(random.Next(100, 300),
random.Next(1000, 3000), SetColor(random));
break;
case nameof(DrawningAntiAircraftGun):
_drawningGun = new DrawningAntiAircraftGun(random.Next(100, 300),
random.Next(1000, 3000),
SetColor(random),
SetColor(random),
random.Next(10, 100),
Convert.ToBoolean(random.Next(0, 2)),
Convert.ToBoolean(random.Next(0, 2)));
break;
default:
return;
}
if (_company + _drawningGun!=-1)
{
MessageBox.Show("Объект добавлен");
pictureBox.Image = _company.Show();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
/// <summary>
/// Получение цвета
/// </summary>
/// <param name="random">Случайные числа</param>
/// <returns></returns>
private static Color SetColor(Random random)
{
Color color = Color.FromArgb(random.Next(0, 255), random.Next(0, 255), random.Next(0, 255));
ColorDialog dialog = new();
if (dialog.ShowDialog() == DialogResult.OK) { color = dialog.Color; }
return color;
}
private void ButtonAddGun_Click(object sender, EventArgs e)
{
CreateObj(nameof(DrawningGun));
}
private void ButtonAddAntiAircraftGun_Click(object sender, EventArgs e)
{
CreateObj(nameof(DrawningAntiAircraftGun));
}
private void ButtonRemoveGun_Click(object sender, EventArgs e)
{
if (_company == null)
{
return;
}
if (string.IsNullOrEmpty(maskedTextBox.Text))
{
return;
}
if (MessageBox.Show("Удалить объект", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; }
int pos = Convert.ToInt32(maskedTextBox.Text);
if (_company - pos is DrawningGun)
{
MessageBox.Show("Объект удален");
pictureBox.Image = _company.Show();
}
else
{
MessageBox.Show("Не удалось удалить объект");
}
}
private void ButtonGoToCheck_Click(object sender, EventArgs e)
{
if (_company == null)
{
return;
}
DrawningGun? gun = null;
int counter = 100;
while (gun == null)
{
gun = _company.GetRandomObject();
counter--;
if (counter <= 0)
{
break;
}
}
if (gun == null)
{
return;
}
FormAntiAircraftGun form = new()
{
SetGun = gun,
};
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 AntiAircraftGun
// To customize application configuration such as set high DPI settings or default font, // To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration. // see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize(); ApplicationConfiguration.Initialize();
Application.Run(new FormAntiAircraftGun()); Application.Run(new FormGunCollections());
} }
} }
} }