коллекции и компания

This commit is contained in:
SVETLANA_8 2024-03-23 11:55:48 +04:00
parent 100ebe34b8
commit 985dd19b2c
10 changed files with 817 additions and 84 deletions

View File

@ -0,0 +1,117 @@
///using ProjectByldozer.CollectionGenericObjects;
using ProjectByldozer.Drawnings;
namespace ProjectByldozer.CollectionGenericObjects;
/// <summary>
/// Абстракция компании, хранящий коллекцию автомобилей
/// </summary>
public abstract class AbstractCompany
{
/// <summary>
/// Размер места (ширина)
/// </summary>
protected readonly int _placeSizeWidth = 210;
/// <summary>
/// Размер места (высота)
/// </summary>
protected readonly int _placeSizeHeight = 83;
/// <summary>
/// Ширина окна
/// </summary>
protected readonly int _pictureWidth;
/// <summary>
/// Высота окна
/// </summary>
protected readonly int _pictureHeight;
/// <summary>
/// Коллекция бульдозеров
/// </summary>
protected ICollectionGenericObjects<DrawningTrackedCar>? _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<DrawningTrackedCar> collection)
{
_pictureWidth = picWidth;
_pictureHeight = picHeight;
_collection = collection;
_collection.SetMaxCount = GetMaxCount;
}
/// <summary>
/// Перегрузка оператора сложения для класса
/// </summary>
/// <param name="company">Компания</param>
/// <param name="car">Добавляемый объект</param>
/// <returns></returns>
public static int operator +(AbstractCompany company, DrawningTrackedCar TrackedCar)
{
return company._collection.Insert(TrackedCar);
}
/// <summary>
/// Перегрузка оператора удаления для класса
/// </summary>
/// <param name="company">Компания</param>
/// <param name="position">Номер удаляемого объекта</param>
/// <returns></returns>
public static DrawningTrackedCar operator -(AbstractCompany company, int position)
{
return company._collection?.Remove(position);
}
/// <summary>
/// Получение случайного объекта из коллекции
/// </summary>
/// <returns></returns>
public DrawningTrackedCar? 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)
{
DrawningTrackedCar? 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,47 @@
namespace ProjectByldozer.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,114 @@
namespace ProjectByldozer.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)
{
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 (position >= _collection.Length || position < 0)
{ return null; }
return _collection[position];
}
public int Insert(T obj)
{
// TODO вставка в свободное место набора
int index = 0;
while (index < _collection.Length)
{
if (_collection[index] == null)
{
_collection[index] = obj;
return index;
}
index++;
}
return -1;
}
public int Insert(T obj, int position)
{
// TODO проверка позиции
// TODO проверка, что элемент массива по этой позиции пустой, если нет, то
// ищется свободное место после этой позиции и идет вставка туда
// если нет после, ищем до
// TODO вставка
if (position >= _collection.Length || position < 0)
{ return -1; }
if (_collection[position] == null)
{
_collection[position] = obj;
return position;
}
int index;
for (index = position + 1; index < _collection.Length; ++index)
{
if (_collection[index] == null)
{
_collection[position] = obj;
return position;
}
}
for (index = position - 1; index >= 0; --index)
{
if (_collection[index] == null)
{
_collection[position] = obj;
return position;
}
}
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,66 @@

using ProjectByldozer.Drawnings;
namespace ProjectByldozer.CollectionGenericObjects;
public class TrackedCarGarage : AbstractCompany
{
/// <summary>
/// Конструктор
/// </summary>
/// <param name="picWidth"></param>
/// <param name="picHeight"></param>
/// <param name="collection"></param>
public TrackedCarGarage(int picWidth, int picHeight, ICollectionGenericObjects<DrawningTrackedCar> collection) : base(picWidth, picHeight, collection)
{
}
protected override void DrawBackgound(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 - 15, j * _placeSizeHeight);
}
}
}
protected override void SetObjectsPosition()
{
int width = _pictureWidth / _placeSizeWidth;
int height = _pictureHeight / _placeSizeHeight;
int curWidth = width - 1;
int curHeight = 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 * curWidth + 20, curHeight * _placeSizeHeight + 2);
}
if (curWidth > 0)
curWidth--;
else
{
curWidth = width - 1;
curHeight--;
}
if (curHeight < 0)
{
return;
}
}
}
}

View File

@ -29,12 +29,10 @@
private void InitializeComponent()
{
pictureBoxByldozer = new PictureBox();
buttonCreateByldozer = new Button();
buttonLeft = new Button();
buttonUp = new Button();
buttonDown = new Button();
buttonRight = new Button();
buttonCreatecar = new Button();
comboBoxStrategy = new ComboBox();
buttonStrategyStep = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxByldozer).BeginInit();
@ -45,29 +43,16 @@
pictureBoxByldozer.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
pictureBoxByldozer.Location = new Point(-2, -1);
pictureBoxByldozer.Name = "pictureBoxByldozer";
pictureBoxByldozer.Size = new Size(751, 406);
pictureBoxByldozer.Size = new Size(774, 421);
pictureBoxByldozer.TabIndex = 0;
pictureBoxByldozer.TabStop = false;
pictureBoxByldozer.Click += pictureBoxByldozer_Click;
//
// buttonCreateByldozer
//
buttonCreateByldozer.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonCreateByldozer.Location = new Point(26, 367);
buttonCreateByldozer.Name = "buttonCreateByldozer";
buttonCreateByldozer.Size = new Size(120, 26);
buttonCreateByldozer.TabIndex = 1;
buttonCreateByldozer.Text = "Создать бульдозер";
buttonCreateByldozer.TextAlign = ContentAlignment.TopRight;
buttonCreateByldozer.UseVisualStyleBackColor = true;
buttonCreateByldozer.Click += ButtonCreateByldozer_Click;
//
// buttonLeft
//
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonLeft.BackgroundImage = Properties.Resources.arrowLeft;
buttonLeft.BackgroundImageLayout = ImageLayout.Stretch;
buttonLeft.Location = new Point(620, 370);
buttonLeft.Location = new Point(643, 385);
buttonLeft.Name = "buttonLeft";
buttonLeft.Size = new Size(35, 35);
buttonLeft.TabIndex = 2;
@ -79,7 +64,7 @@
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonUp.BackgroundImage = Properties.Resources.arrowUp;
buttonUp.BackgroundImageLayout = ImageLayout.Stretch;
buttonUp.Location = new Point(661, 329);
buttonUp.Location = new Point(684, 344);
buttonUp.Name = "buttonUp";
buttonUp.Size = new Size(35, 35);
buttonUp.TabIndex = 3;
@ -91,7 +76,7 @@
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonDown.BackgroundImage = Properties.Resources.arrowDown;
buttonDown.BackgroundImageLayout = ImageLayout.Stretch;
buttonDown.Location = new Point(661, 370);
buttonDown.Location = new Point(684, 385);
buttonDown.Name = "buttonDown";
buttonDown.Size = new Size(35, 35);
buttonDown.TabIndex = 4;
@ -103,25 +88,13 @@
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonRight.BackgroundImage = Properties.Resources.arrowRight;
buttonRight.BackgroundImageLayout = ImageLayout.Stretch;
buttonRight.Location = new Point(702, 370);
buttonRight.Location = new Point(725, 385);
buttonRight.Name = "buttonRight";
buttonRight.Size = new Size(35, 35);
buttonRight.TabIndex = 5;
buttonRight.UseVisualStyleBackColor = true;
buttonRight.Click += ButtonMove_Click;
//
// buttonCreatecar
//
buttonCreatecar.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonCreatecar.Location = new Point(164, 367);
buttonCreatecar.Name = "buttonCreatecar";
buttonCreatecar.Size = new Size(179, 26);
buttonCreatecar.TabIndex = 6;
buttonCreatecar.Text = "Создать гусеничную машину";
buttonCreatecar.TextAlign = ContentAlignment.TopRight;
buttonCreatecar.UseVisualStyleBackColor = true;
buttonCreatecar.Click += ButtonCreatecar_Click;
//
// comboBoxStrategy
//
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
@ -146,15 +119,13 @@
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(749, 405);
ClientSize = new Size(772, 420);
Controls.Add(buttonStrategyStep);
Controls.Add(comboBoxStrategy);
Controls.Add(buttonCreatecar);
Controls.Add(buttonRight);
Controls.Add(buttonDown);
Controls.Add(buttonUp);
Controls.Add(buttonLeft);
Controls.Add(buttonCreateByldozer);
Controls.Add(pictureBoxByldozer);
Name = "FormByldozer";
Text = "Бульдозер";
@ -165,12 +136,10 @@
#endregion
private PictureBox pictureBoxByldozer;
private Button buttonCreateByldozer;
private Button buttonLeft;
private Button buttonUp;
private Button buttonDown;
private Button buttonRight;
private Button buttonCreatecar;
private ComboBox comboBoxStrategy;
private Button buttonStrategyStep;
}

View File

@ -17,6 +17,17 @@ public partial class FormByldozer : Form
/// стратегия перемещения
/// </summary>
private AbstractStrategy? _strategy;
public DrawningTrackedCar SetTrackedCar
{
set
{
_drawningTrackedCar = value;
_drawningTrackedCar.SetPictureSize(pictureBoxByldozer.Width, pictureBoxByldozer.Height);
comboBoxStrategy.Enabled = true;
_strategy = null;
Draw();
}
}
/// <summary>
/// инциализация формы
/// </summary>
@ -42,49 +53,6 @@ public partial class FormByldozer : Form
}
/// <summary>
/// Создание объекта класса-перемещения
/// </summary>
/// <param name="type">Тип создаваемого объекта</param>
private void CreateObject(string type)
{
Random random = new();
switch (type)
{
case nameof(DrawningTrackedCar):
_drawningTrackedCar = new DrawningTrackedCar(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(DrawningByldozer):
_drawningTrackedCar = new DrawningByldozer(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;
}
_drawningTrackedCar.SetPictureSize(pictureBoxByldozer.Width, pictureBoxByldozer.Height);
_drawningTrackedCar.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 ButtonCreateByldozer_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningByldozer));
/// <summary>
/// обработка нажатия кнопки "создать машину"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonCreatecar_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningTrackedCar));
/// <summary>
/// премещение объекта по форме
/// </summary>
@ -158,9 +126,6 @@ public partial class FormByldozer : Form
}
}
private void pictureBoxByldozer_Click(object sender, EventArgs e)
{
}
}

View File

@ -0,0 +1,173 @@
namespace ProjectByldozer
{
partial class FormCarCollection
{
/// <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();
buttonDelCar = new Button();
maskedTextBox = new MaskedTextBox();
buttonAddByldozer = new Button();
buttonAddTrackedCar = new Button();
comboBoxSelectionCompany = 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(buttonDelCar);
groupBoxTools.Controls.Add(maskedTextBox);
groupBoxTools.Controls.Add(buttonAddByldozer);
groupBoxTools.Controls.Add(buttonAddTrackedCar);
groupBoxTools.Controls.Add(comboBoxSelectionCompany);
groupBoxTools.Dock = DockStyle.Right;
groupBoxTools.Location = new Point(750, 0);
groupBoxTools.Name = "groupBoxTools";
groupBoxTools.Size = new Size(209, 499);
groupBoxTools.TabIndex = 0;
groupBoxTools.TabStop = false;
groupBoxTools.Text = "Инструменты";
//
// buttonRefresh
//
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonRefresh.Location = new Point(6, 403);
buttonRefresh.Name = "buttonRefresh";
buttonRefresh.Size = new Size(191, 36);
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, 324);
buttonGoToCheck.Name = "buttonGoToCheck";
buttonGoToCheck.Size = new Size(191, 34);
buttonGoToCheck.TabIndex = 5;
buttonGoToCheck.Text = "Передать на тесты";
buttonGoToCheck.UseVisualStyleBackColor = true;
buttonGoToCheck.Click += ButtonGoToCheck_Click;
//
// buttonDelCar
//
buttonDelCar.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonDelCar.Location = new Point(6, 248);
buttonDelCar.Name = "buttonDelCar";
buttonDelCar.Size = new Size(191, 34);
buttonDelCar.TabIndex = 4;
buttonDelCar.Text = "Удаление машины";
buttonDelCar.UseVisualStyleBackColor = true;
buttonDelCar.Click += ButtonDelCar_Click;
//
// maskedTextBox
//
maskedTextBox.Location = new Point(6, 219);
maskedTextBox.Mask = "00";
maskedTextBox.Name = "maskedTextBox";
maskedTextBox.Size = new Size(191, 23);
maskedTextBox.TabIndex = 3;
maskedTextBox.ValidatingType = typeof(int);
//
// buttonAddByldozer
//
buttonAddByldozer.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonAddByldozer.Location = new Point(6, 128);
buttonAddByldozer.Name = "buttonAddByldozer";
buttonAddByldozer.Size = new Size(191, 41);
buttonAddByldozer.TabIndex = 2;
buttonAddByldozer.Text = "Добавления бульдозера";
buttonAddByldozer.UseVisualStyleBackColor = true;
buttonAddByldozer.Click += ButtonAddByldozer_Click;
//
// buttonAddTrackedCar
//
buttonAddTrackedCar.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonAddTrackedCar.Location = new Point(6, 77);
buttonAddTrackedCar.Name = "buttonAddTrackedCar";
buttonAddTrackedCar.Size = new Size(191, 45);
buttonAddTrackedCar.TabIndex = 1;
buttonAddTrackedCar.Text = "Добавления гусеничной машины";
buttonAddTrackedCar.UseVisualStyleBackColor = true;
buttonAddTrackedCar.Click += ButtonAddTrackedCar_Click;
//
// comboBoxSelectionCompany
//
comboBoxSelectionCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
comboBoxSelectionCompany.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxSelectionCompany.FormattingEnabled = true;
comboBoxSelectionCompany.Items.AddRange(new object[] { "Хранилище" });
comboBoxSelectionCompany.Location = new Point(6, 22);
comboBoxSelectionCompany.Name = "comboBoxSelectionCompany";
comboBoxSelectionCompany.Size = new Size(191, 23);
comboBoxSelectionCompany.TabIndex = 0;
comboBoxSelectionCompany.SelectedIndexChanged += ComboBoxSelectionCompany_SelectedIndexChanged;
//
// pictureBox
//
pictureBox.Dock = DockStyle.Fill;
pictureBox.Location = new Point(0, 0);
pictureBox.Name = "pictureBox";
pictureBox.Size = new Size(750, 499);
pictureBox.TabIndex = 1;
pictureBox.TabStop = false;
//
// FormCarCollection
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(959, 499);
Controls.Add(pictureBox);
Controls.Add(groupBoxTools);
Name = "FormCarCollection";
Text = "коллекция бульдозеров";
groupBoxTools.ResumeLayout(false);
groupBoxTools.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
ResumeLayout(false);
}
#endregion
private GroupBox groupBoxTools;
private ComboBox comboBoxSelectionCompany;
private Button buttonAddByldozer;
private Button buttonAddTrackedCar;
private MaskedTextBox maskedTextBox;
private PictureBox pictureBox;
private Button buttonDelCar;
private Button buttonRefresh;
private Button buttonGoToCheck;
}
}

View File

@ -0,0 +1,161 @@
using ProjectByldozer.CollectionGenericObjects;
using ProjectByldozer.Drawnings;
namespace ProjectByldozer;
/// <summary>
/// Форма работы с компанией и ее коллекцией
/// </summary>
public partial class FormCarCollection : Form
{
/// <summary>
/// Компания
/// </summary>
private AbstractCompany? _company = null;
/// <summary>
/// Конструктор
/// </summary>
public FormCarCollection()
{
InitializeComponent();
}
private void ComboBoxSelectionCompany_SelectedIndexChanged(object sender, EventArgs e)
{
switch (comboBoxSelectionCompany.Text)
{
case "Хранилище":
_company = new TrackedCarGarage(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects<DrawningTrackedCar>());
break;
}
}
/// <summary>
/// Добавление обычной машины
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonAddByldozer_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningByldozer));
/// /// Добавление полного экскаватора
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonAddTrackedCar_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningTrackedCar));
private void CreateObject(string type)
{
if (_company == null)
{
return;
}
Random random = new();
DrawningTrackedCar drawningTrackedCar;
switch (type)
{
case nameof(DrawningTrackedCar):
drawningTrackedCar = new DrawningTrackedCar(random.Next(100, 300), random.Next(1000, 3000), GetColor(random));
break;
case nameof(DrawningByldozer):
// TODO вызов диалогового окна для выбора цвета
drawningTrackedCar = new DrawningByldozer(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 + drawningTrackedCar != -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 ButtonDelCar_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == null)
{
return;
}
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
{
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;
}
DrawningTrackedCar? trackedcar = null;
int counter = 100;
while (trackedcar == null)
{
trackedcar = _company.GetRandomObject();
counter--;
if (counter <= 0)
{
break;
}
}
if (trackedcar == null)
{
return;
}
FormByldozer form = new()
{
SetTrackedCar = trackedcar
};
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,8 @@ namespace ProjectByldozer
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.Run(new FormByldozer());
Application.Run(new FormCarCollection());
}
}
}