Компания

This commit is contained in:
кристина лаврова 2024-04-24 22:45:48 +04:00
parent a3c0a89868
commit 98990e36de
12 changed files with 686 additions and 128 deletions

View File

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

View File

@ -0,0 +1,62 @@
using lab1.Drawnings;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace lab1.CollectionGenericObjects;
public class TrackedVehicleSharingService : AbstractCompany
{
public TrackedVehicleSharingService(int picWidth, int picHeight, ICollectionGenericObjects<DrawningTrackedVehicle> collection) : base(picWidth, picHeight, collection)
{
}
/// <summary>
/// Вывод заднего фона
/// </summary>
/// <param name="g"></param>
protected override void DrawBackgound(Graphics g)
{
int width = _pictureWidth / _placeSizeWidth;
int height = _pictureHeight / _placeSizeHeight;
Pen pen = new(Color.Black, 2);
for (int i = 0; i < width; i++)
{
for (int j = 0; j < height + 1; ++j)
{
g.DrawLine(pen, i * _placeSizeWidth + 15, j * _placeSizeHeight, i * _placeSizeWidth + 15 + _placeSizeWidth - 55, j * _placeSizeHeight);
g.DrawLine(pen, i * _placeSizeWidth + 15, j * _placeSizeHeight, i * _placeSizeWidth + 15, j * _placeSizeHeight - _placeSizeHeight);
}
}
}
/// <summary>
/// Расстановка объектов
/// </summary>
protected override void SetObjectsPosition()
{
int width = _pictureWidth / _placeSizeWidth;
int height = _pictureHeight / _placeSizeHeight;
int curWidth = width - 1;
int curHeight = 0;
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 * curWidth + 45, curHeight * _placeSizeHeight + 30);
}
if (curWidth > 0)
curWidth--;
else
{
curWidth = width - 1;
curHeight++;
}
if (curHeight > height)
{
return;
}
}
}
}

View File

@ -28,58 +28,12 @@ public class DrawningEntityFighter : DrawningTrackedVehicle
return;
}
Pen pen = new(Color.Black);
Brush additionalBrush = new SolidBrush(fighter.AdditionalColor);
Brush BodyBrush = new SolidBrush(fighter.BodyColor);
Brush CraneBrush = new SolidBrush(fighter.AdditionalColor);
//корпус
g.FillRectangle(BodyBrush, _startPosX.Value + 10, _startPosY.Value + 30, 62, 12);
g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 30, 62, 12);
g.FillRectangle(BodyBrush, _startPosX.Value + 22, _startPosY.Value + 16, 4, 15);
g.DrawRectangle(pen, _startPosX.Value + 22, _startPosY.Value + 16, 4, 14);
g.FillRectangle(BodyBrush, _startPosX.Value + 37, _startPosY.Value + 1, 5, 30);
g.DrawRectangle(pen, _startPosX.Value + 37, _startPosY.Value + 1, 5, 30);
//стекло
g.FillRectangle(additionalBrush, _startPosX.Value + 52, _startPosY.Value + 14, 21, 16);
g.DrawRectangle(pen, _startPosX.Value + 52, _startPosY.Value + 14, 20, 16);
//гусеницы
g.DrawLine(pen, _startPosX.Value + 8, _startPosY.Value + 42, _startPosX.Value + 10, _startPosY.Value + 42);
g.DrawLine(pen, _startPosX.Value + 7, _startPosY.Value + 43, _startPosX.Value + 7, _startPosY.Value + 53);
g.DrawLine(pen, _startPosX.Value + 8, _startPosY.Value + 54, _startPosX.Value + 12, _startPosY.Value + 54);
g.DrawLine(pen, _startPosX.Value + 13, _startPosY.Value + 55, _startPosX.Value + 69, _startPosY.Value + 55);
g.DrawLine(pen, _startPosX.Value + 70, _startPosY.Value + 54, _startPosX.Value + 73, _startPosY.Value + 54);
g.DrawLine(pen, _startPosX.Value + 74, _startPosY.Value + 53, _startPosX.Value + 74, _startPosY.Value + 43);
g.DrawLine(pen, _startPosX.Value + 71, _startPosY.Value + 42, _startPosX.Value + 73, _startPosY.Value + 42);
//колеса
g.FillEllipse(BodyBrush, _startPosX.Value + 10, _startPosY.Value + 44, 9, 9);
g.DrawEllipse(pen, _startPosX.Value + 10, _startPosY.Value + 44, 9, 9);
g.FillEllipse(BodyBrush, _startPosX.Value + 63, _startPosY.Value + 44, 9, 9);
g.DrawEllipse(pen, _startPosX.Value + 63, _startPosY.Value + 44, 9, 9);
g.FillEllipse(BodyBrush, _startPosX.Value + 25, _startPosY.Value + 48, 6, 6);
g.DrawEllipse(pen, _startPosX.Value + 25, _startPosY.Value + 48, 6, 6);
g.FillEllipse(BodyBrush, _startPosX.Value + 38, _startPosY.Value + 48, 6, 6);
g.DrawEllipse(pen, _startPosX.Value + 38, _startPosY.Value + 48, 6, 6);
g.FillEllipse(BodyBrush, _startPosX.Value + 50, _startPosY.Value + 48, 6, 6);
g.DrawEllipse(pen, _startPosX.Value + 50, _startPosY.Value + 48, 6, 6);
g.FillEllipse(BodyBrush, _startPosX.Value + 33, _startPosY.Value + 44, 4, 4);
g.DrawEllipse(pen, _startPosX.Value + 33, _startPosY.Value + 44, 4, 4);
g.FillEllipse(BodyBrush, _startPosX.Value + 45, _startPosY.Value + 44, 4, 4);
g.DrawEllipse(pen, _startPosX.Value + 45, _startPosY.Value + 44, 4, 4);
_startPosX += 10;
_startPosY += 25;
base.DrawTransport(g);
_startPosX -= 10;
_startPosY -= 25;
if (fighter.Kovsh)
{
@ -98,7 +52,6 @@ public class DrawningEntityFighter : DrawningTrackedVehicle
}
}
}

View File

@ -29,12 +29,10 @@
private void InitializeComponent()
{
pictureBoxFighter = new PictureBox();
buttonCreate = new Button();
buttonLeft = new Button();
buttonDown = new Button();
buttonUp = new Button();
buttonRight = new Button();
buttonCreateTrackedVehicle = new Button();
comboBoxStrategy = new ComboBox();
buttonStrategyStep = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxFighter).BeginInit();
@ -50,17 +48,6 @@
pictureBoxFighter.TabStop = false;
pictureBoxFighter.Click += pictureBoxFighter_Click;
//
// buttonCreate
//
buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonCreate.Location = new Point(12, 538);
buttonCreate.Name = "buttonCreate";
buttonCreate.Size = new Size(226, 34);
buttonCreate.TabIndex = 1;
buttonCreate.Text = "создать истребитель";
buttonCreate.UseVisualStyleBackColor = true;
buttonCreate.Click += ButtonCreate_Click;
//
// buttonLeft
//
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
@ -113,17 +100,6 @@
buttonRight.UseVisualStyleBackColor = false;
buttonRight.Click += ButtonMove_Click;
//
// buttonCreateTrackedVehicle
//
buttonCreateTrackedVehicle.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonCreateTrackedVehicle.Location = new Point(234, 538);
buttonCreateTrackedVehicle.Name = "buttonCreateTrackedVehicle";
buttonCreateTrackedVehicle.Size = new Size(264, 34);
buttonCreateTrackedVehicle.TabIndex = 6;
buttonCreateTrackedVehicle.Text = "создать гусеничную машину";
buttonCreateTrackedVehicle.UseVisualStyleBackColor = true;
buttonCreateTrackedVehicle.Click += ButtonCreateTrackedVehicle_Click;
//
// comboBoxStrategy
//
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
@ -151,12 +127,10 @@
ClientSize = new Size(1164, 584);
Controls.Add(buttonStrategyStep);
Controls.Add(comboBoxStrategy);
Controls.Add(buttonCreateTrackedVehicle);
Controls.Add(buttonRight);
Controls.Add(buttonUp);
Controls.Add(buttonDown);
Controls.Add(buttonLeft);
Controls.Add(buttonCreate);
Controls.Add(pictureBoxFighter);
Name = "FormFighter";
Text = "Истребитель";
@ -168,12 +142,10 @@
#endregion
private PictureBox pictureBoxFighter;
private Button buttonCreate;
private Button buttonLeft;
private Button buttonDown;
private Button buttonUp;
private Button buttonRight;
private Button buttonCreateTrackedVehicle;
private ComboBox comboBoxStrategy;
private Button buttonStrategyStep;
}

View File

@ -17,11 +17,30 @@ namespace lab1;
public partial class FormFighter : Form
{
/// <summary>
/// Поле-объект для прорисовки объекта
/// </summary>
private DrawningTrackedVehicle? _drawningTrackedVehicle;
/// <summary>
/// Стратегия перемещения
/// </summary>
private AbstractSrategy? _strategy;
/// <summary>
/// Получение объекта
/// </summary>
public DrawningTrackedVehicle SetTrackedVehicle
{
set
{
_drawningTrackedVehicle = value;
_drawningTrackedVehicle = value;
_drawningTrackedVehicle.SetPictureSize(pictureBoxFighter.Width, pictureBoxFighter.Height);
comboBoxStrategy.Enabled = true;
_strategy = null;
Draw();
}
}
public FormFighter()
{
InitializeComponent();
@ -42,62 +61,14 @@ public partial class FormFighter : Form
pictureBoxFighter.Image = bmp;
}
/// <summary>
/// Создание объекта класса-перемещения
/// </summary>
/// <param name="type"></param>
private void CreateObject(string type)
{
Random random = new();
switch (type)
{
case nameof(DrawningTrackedVehicle):
_drawningTrackedVehicle = new DrawningTrackedVehicle(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(DrawningEntityFighter):
_drawningTrackedVehicle = new DrawningEntityFighter(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;
}
_drawningTrackedVehicle.SetPictureSize(pictureBoxFighter.Width, pictureBoxFighter.Height);
_drawningTrackedVehicle.SetPosition(random.Next(10, 100), random.Next(10, 100));
_strategy = null;
Draw();
}
/// <summary>
/// Обработка нажатия кнопки "Создать истребитель"
/// Перемещение объекта по форме (нажатие кнопок навигации)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonCreate_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningEntityFighter));
/// <summary>
/// Обработка нажатия кнопки "Создать гусеничную машину"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonCreateTrackedVehicle_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningTrackedVehicle));
private void ButtonMove_Click(object sender, EventArgs e)
{
if (_drawningTrackedVehicle == null)

View File

@ -0,0 +1,176 @@
namespace lab1
{
partial class FormTrackedVehicleCollection
{
/// <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();
buttonRemoveTrackedVehicle = new Button();
maskedTextBox = new MaskedTextBox();
buttonAddTrackedVehicle = new Button();
buttonAddFighter = 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(buttonRemoveTrackedVehicle);
groupBoxTools.Controls.Add(maskedTextBox);
groupBoxTools.Controls.Add(buttonAddTrackedVehicle);
groupBoxTools.Controls.Add(buttonAddFighter);
groupBoxTools.Controls.Add(comboBoxSelectorCompany);
groupBoxTools.Dock = DockStyle.Right;
groupBoxTools.Location = new Point(886, 0);
groupBoxTools.Name = "groupBoxTools";
groupBoxTools.Size = new Size(297, 617);
groupBoxTools.TabIndex = 0;
groupBoxTools.TabStop = false;
groupBoxTools.Text = "Инструменты";
//
// buttonRefresh
//
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonRefresh.Location = new Point(7, 516);
buttonRefresh.Name = "buttonRefresh";
buttonRefresh.Size = new Size(284, 53);
buttonRefresh.TabIndex = 7;
buttonRefresh.Text = "Обновить";
buttonRefresh.UseVisualStyleBackColor = true;
buttonRefresh.Click += ButtonRefresh_Click_1;
//
// buttonGoToCheck
//
buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonGoToCheck.Location = new Point(5, 457);
buttonGoToCheck.Name = "buttonGoToCheck";
buttonGoToCheck.Size = new Size(286, 53);
buttonGoToCheck.TabIndex = 6;
buttonGoToCheck.Text = "Передать на тесты";
buttonGoToCheck.UseVisualStyleBackColor = true;
buttonGoToCheck.Click += button1_Click;
//
// buttonRemoveTrackedVehicle
//
buttonRemoveTrackedVehicle.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonRemoveTrackedVehicle.Location = new Point(5, 342);
buttonRemoveTrackedVehicle.Name = "buttonRemoveTrackedVehicle";
buttonRemoveTrackedVehicle.Size = new Size(286, 82);
buttonRemoveTrackedVehicle.TabIndex = 5;
buttonRemoveTrackedVehicle.Text = "Удаление гусеничной машины";
buttonRemoveTrackedVehicle.UseVisualStyleBackColor = true;
buttonRemoveTrackedVehicle.Click += ButtonRemoveTrackedVehicle_Click;
//
// maskedTextBox
//
maskedTextBox.Location = new Point(7, 305);
maskedTextBox.Mask = "00";
maskedTextBox.Name = "maskedTextBox";
maskedTextBox.Size = new Size(284, 31);
maskedTextBox.TabIndex = 4;
maskedTextBox.ValidatingType = typeof(int);
maskedTextBox.MaskInputRejected += maskedTextBox1_MaskInputRejected;
//
// buttonAddTrackedVehicle
//
buttonAddTrackedVehicle.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonAddTrackedVehicle.Location = new Point(12, 181);
buttonAddTrackedVehicle.Name = "buttonAddTrackedVehicle";
buttonAddTrackedVehicle.Size = new Size(279, 82);
buttonAddTrackedVehicle.TabIndex = 3;
buttonAddTrackedVehicle.Text = "Добавление гусеничной машины";
buttonAddTrackedVehicle.UseVisualStyleBackColor = true;
buttonAddTrackedVehicle.Click += ButtonAddTrackedVehicle_Click;
//
// buttonAddFighter
//
buttonAddFighter.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonAddFighter.Location = new Point(0, 98);
buttonAddFighter.Name = "buttonAddFighter";
buttonAddFighter.Size = new Size(291, 77);
buttonAddFighter.TabIndex = 2;
buttonAddFighter.Text = "Добавление истребителя";
buttonAddFighter.UseVisualStyleBackColor = true;
buttonAddFighter.Click += ButtonAddTrackedVehicle_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(7, 30);
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
comboBoxSelectorCompany.Size = new Size(284, 33);
comboBoxSelectorCompany.TabIndex = 1;
comboBoxSelectorCompany.SelectedIndexChanged += comboBoxSelectorCompany_SelectedIndexChanged;
//
// pictureBox
//
pictureBox.Dock = DockStyle.Fill;
pictureBox.Location = new Point(0, 0);
pictureBox.Name = "pictureBox";
pictureBox.Size = new Size(886, 617);
pictureBox.TabIndex = 1;
pictureBox.TabStop = false;
pictureBox.Click += pictureBox1_Click;
//
// FormTrackedVehicleCollection
//
AutoScaleDimensions = new SizeF(10F, 25F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1183, 617);
Controls.Add(pictureBox);
Controls.Add(groupBoxTools);
Name = "FormTrackedVehicleCollection";
Text = "Коллекция гусеничных машин";
Load += FormTrackedVehicleCollection_Load;
groupBoxTools.ResumeLayout(false);
groupBoxTools.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
ResumeLayout(false);
}
#endregion
private GroupBox groupBoxTools;
private ComboBox comboBoxSelectorCompany;
private Button buttonAddTrackedVehicle;
private Button buttonAddFighter;
private PictureBox pictureBox;
private Button buttonRemoveTrackedVehicle;
private MaskedTextBox maskedTextBox;
private Button buttonGoToCheck;
private Button buttonRefresh;
}
}

View File

@ -0,0 +1,204 @@
using lab1.CollectionGenericObjects;
using lab1.Drawnings;
namespace lab1;
/// <summary>
///Форма работы с компанией и её коллекцией
/// </summary>
public partial class FormTrackedVehicleCollection : Form
{
/// <summary>
/// Компания
/// </summary>
private AbstractCompany? _company = null;
/// <summary>
/// Конструктор
/// </summary>
public FormTrackedVehicleCollection()
{
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 TrackedVehicleSharingService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects<DrawningTrackedVehicle>());
break;
}
}
/// <summary>
/// Добавление гусеничной машины
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonAddTrackedVehicle_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningTrackedVehicle));
/// <summary>
/// Добавление истребителя
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonAddEntityFighter_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningEntityFighter));
/// <summary>
/// Создание объекта класса-перемещения
/// </summary>
/// <param name="type"></param>
private void CreateObject(string type)
{
if (_company == null)
{
return;
}
Random random = new();
DrawningTrackedVehicle drawningTrackedVehicle;
switch (type)
{
case nameof(DrawningTrackedVehicle):
drawningTrackedVehicle = new DrawningTrackedVehicle(random.Next(100, 300), random.Next(1000, 3000), GetColor(random));
break;
case nameof(DrawningEntityFighter):
drawningTrackedVehicle = new DrawningEntityFighter(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 + drawningTrackedVehicle != -1)
{
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 ButtonRemoveTrackedVehicle_Click(object sender, EventArgs e)
{
if (_company == null)
{
return;
}
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("Не удалось удалить объект");
}
}
/// <summary>
/// Передача объекта в другую форму
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Click(object sender, EventArgs e)
{
if (_company == null)
{
return;
}
DrawningTrackedVehicle? fighter = null;
int counter = 100;
while (fighter == null)
{
fighter = _company.GetRandomObject();
counter--;
if (counter <= 0)
{
break;
}
}
if (fighter == null)
{
return;
}
FormFighter form = new()
{
SetTrackedVehicle = fighter
};
form.ShowDialog();
}
/// <summary>
/// Перерисовка коллекции
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonRefresh_Click_1(object sender, EventArgs e)
{
if (_company == null)
{
return;
}
pictureBox.Image = _company.Show();
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
private void maskedTextBox1_MaskInputRejected(object sender, MaskInputRejectedEventArgs e)
{
}
private void FormTrackedVehicleCollection_Load(object sender, EventArgs e)
{
}
}

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 lab1
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.Run(new FormFighter());
Application.Run(new FormTrackedVehicleCollection());
}
}
}