что-то с чем-то

This commit is contained in:
DjonniStorm 2024-03-06 00:25:29 +04:00
parent d43b47f7b4
commit fc34842ef1
12 changed files with 689 additions and 80 deletions

View File

@ -0,0 +1,101 @@
using ProjectCleaningCar.Drawning;
namespace ProjectCleaningCar.CollectionGenericObjects;
/// <summary>
/// Абстракция компании, хранящая коллекцию автомобилей
/// </summary>
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<DrawningCar>? _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<DrawningCar> collection)
{
_pictureWidth = picWidth;
_pictureHeight = picHeight;
_collection = collection;
_collection.SetMaxCount = GetMaxCount;
}
/// <summary>
/// Перегрузка оператора сложения для класса
/// </summary>
/// <param name="company">Компания</param>
/// <param name="car">Добавляемый объект</param>
/// <returns></returns>
public static bool operator +(AbstractCompany company, DrawningCar car)
{
return company._collection?.Insert(car) ?? 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 DrawningCar? GetRandomObject()
{
Random random = new();
return _collection?.Get(random.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)
{
DrawningCar? 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,58 @@
using ProjectCleaningCar.Drawning;
using ProjectCleaningCar.Entities;
using System.Drawing;
namespace ProjectCleaningCar.CollectionGenericObjects;
/// <summary>
/// Реализация абстрактной компании каршеринг
/// </summary>
public class CarSharingService : AbstractCompany
{
/// <summary>
/// Конструктор
/// </summary>
/// <param name="picWidth"></param>
/// <param name="picHeight"></param>
/// <param name="collection"></param>
public CarSharingService(int picWidth, int picHeight, ICollectionGenericObjects<DrawningCar> collection) : base(picWidth, picHeight, collection)
{
}
protected override void DrawBackgound(Graphics g)
{
Pen pen = new Pen(Color.Black, 4f);
for (int i = 0; i < _pictureHeight / _placeSizeHeight / 2; i++)
{
g.DrawLine(pen, 0, i * _placeSizeHeight * 2, _pictureWidth / _placeSizeWidth * _placeSizeWidth, i * _placeSizeHeight * 2);
for (int j = 0; j < _pictureWidth / _placeSizeWidth + 1; ++j)
{
g.DrawLine(pen, j * _placeSizeWidth, i * _placeSizeHeight * 2, j * _placeSizeWidth, i * _placeSizeHeight * 2 + _placeSizeHeight);
}
}
}
protected override void SetObjectsPosition()
{
int nowWidth = 0;
int nowHeight = 0;
for (int i = 0; i < (_collection?.Count ?? 0); i++)
{
if (nowHeight > _pictureHeight / _placeSizeHeight)
{
return;
}
if (_collection?.Get(i) != null)
{
_collection?.Get(i)?.SetPictureSize(_pictureWidth, _pictureHeight);
_collection?.Get(i)?.SetPosition(_placeSizeWidth * nowWidth + 30, nowHeight * _placeSizeHeight * 2 + 20);
}
if (nowWidth < _pictureWidth / _placeSizeWidth - 1) nowWidth++;
else
{
nowWidth = 0;
nowHeight++;
}
}
}
}

View File

@ -9,7 +9,8 @@ public interface ICollectionGenericObjects<T>
/// <summary> /// <summary>
/// Количество объектов в коллекции /// Количество объектов в коллекции
/// </summary> /// </summary>
/// /// <summary> int Count { get; }
/// <summary>
/// Установка максимального количества элементов /// Установка максимального количества элементов
/// </summary> /// </summary>
int SetMaxCount { set; } int SetMaxCount { set; }

View File

@ -32,11 +32,12 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
public T? Get(int position) public T? Get(int position)
{ {
// TODO проверка позиции // TODO проверка позиции
if (position < 0 || position >= Count) return null;
return _collection[position]; return _collection[position];
} }
public bool Insert(T obj) public bool Insert(T obj)
{ {
for (int i = 0; i < _collection.Length; i++) for (int i = 0; i < Count; i++)
{ {
if (_collection[i] == null) if (_collection[i] == null)
{ {
@ -54,13 +55,40 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
// ищется свободное место после этой позиции и идет вставка туда // ищется свободное место после этой позиции и идет вставка туда
// если нет после, ищем до // если нет после, ищем до
// TODO вставка // TODO вставка
if (position >= Count || position < 0) return false;
if (_collection[position] == null)
{
_collection[position] = obj;
return true;
}
int temp = position + 1;
while(temp < Count)
{
if (_collection[temp] == null)
{
_collection[temp] = obj;
return true;
}
++temp;
}
temp = position - 1;
while(temp > 0)
{
if (_collection[temp] == null)
{
_collection[temp] = obj;
return true;
}
--temp;
}
return false; return false;
} }
public bool Remove(int position) public bool Remove(int position)
{ {
// TODO проверка позиции // TODO проверка позиции
// TODO удаление объекта из массива, присвоив элементу массива значение null // TODO удаление объекта из массива, присвоив элементу массива значение null
if (position >= Count || position < 0) return false;
_collection[position] = null;
return true; return true;
} }
} }

View File

@ -16,11 +16,9 @@ public class DrawningCleaningCar : DrawningCar
/// <param name="tank">Бак с водой</param> /// <param name="tank">Бак с водой</param>
/// <param name="sweepingBrush">Подметательная щётка</param> /// <param name="sweepingBrush">Подметательная щётка</param>
/// <param name="flashlight">Проблескового маячок</param> /// <param name="flashlight">Проблескового маячок</param>
public DrawningCleaningCar(int speed, double weight, Color bodyColor, Color public DrawningCleaningCar(int speed, double weight, Color bodyColor, Color additionalColor, bool tank, bool sweepingBrush, bool flashlight) : base(132, 65)
additionalColor, bool tank, bool sweepingBrush, bool flashlight) : base(132, 65)
{ {
EntityCar = new EntityCleaningCar(speed, weight, bodyColor, additionalColor, EntityCar = new EntityCleaningCar(speed, weight, bodyColor, additionalColor, tank, sweepingBrush, flashlight);
tank, sweepingBrush, flashlight);
} }
/// <summary> /// <summary>
/// Отрисовка объекта /// Отрисовка объекта

View File

@ -29,12 +29,10 @@
private void InitializeComponent() private void InitializeComponent()
{ {
pictureBoxCleaningCar = new PictureBox(); pictureBoxCleaningCar = new PictureBox();
buttonCreateCleaningCar = new Button();
buttonRight = new Button(); buttonRight = new Button();
buttonLeft = new Button(); buttonLeft = new Button();
buttonUp = new Button(); buttonUp = new Button();
buttonDown = new Button(); buttonDown = new Button();
buttonCreateCar = new Button();
comboBoxStrategy = new ComboBox(); comboBoxStrategy = new ComboBox();
buttonStrategyStep = new Button(); buttonStrategyStep = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxCleaningCar).BeginInit(); ((System.ComponentModel.ISupportInitialize)pictureBoxCleaningCar).BeginInit();
@ -49,18 +47,6 @@
pictureBoxCleaningCar.TabIndex = 0; pictureBoxCleaningCar.TabIndex = 0;
pictureBoxCleaningCar.TabStop = false; pictureBoxCleaningCar.TabStop = false;
// //
// buttonCreateCleaningCar
//
buttonCreateCleaningCar.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonCreateCleaningCar.Font = new Font("Segoe UI", 9F, FontStyle.Regular, GraphicsUnit.Point);
buttonCreateCleaningCar.Location = new Point(12, 421);
buttonCreateCleaningCar.Name = "buttonCreateCleaningCar";
buttonCreateCleaningCar.Size = new Size(192, 32);
buttonCreateCleaningCar.TabIndex = 1;
buttonCreateCleaningCar.Text = "Создать уборочную машину";
buttonCreateCleaningCar.UseVisualStyleBackColor = true;
buttonCreateCleaningCar.Click += ButtonCreateCleaningCar_Click;
//
// buttonRight // buttonRight
// //
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
@ -109,17 +95,6 @@
buttonDown.UseVisualStyleBackColor = true; buttonDown.UseVisualStyleBackColor = true;
buttonDown.Click += ButtonMove_Click; buttonDown.Click += ButtonMove_Click;
// //
// buttonCreateCar
//
buttonCreateCar.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonCreateCar.Location = new Point(210, 421);
buttonCreateCar.Name = "buttonCreateCar";
buttonCreateCar.Size = new Size(192, 32);
buttonCreateCar.TabIndex = 6;
buttonCreateCar.Text = "Создать машину";
buttonCreateCar.UseVisualStyleBackColor = true;
buttonCreateCar.Click += ButtonCreateCar_Click;
//
// comboBoxStrategy // comboBoxStrategy
// //
comboBoxStrategy.Anchor = AnchorStyles.Top | AnchorStyles.Right; comboBoxStrategy.Anchor = AnchorStyles.Top | AnchorStyles.Right;
@ -149,12 +124,10 @@
ClientSize = new Size(824, 465); ClientSize = new Size(824, 465);
Controls.Add(buttonStrategyStep); Controls.Add(buttonStrategyStep);
Controls.Add(comboBoxStrategy); Controls.Add(comboBoxStrategy);
Controls.Add(buttonCreateCar);
Controls.Add(buttonDown); Controls.Add(buttonDown);
Controls.Add(buttonUp); Controls.Add(buttonUp);
Controls.Add(buttonLeft); Controls.Add(buttonLeft);
Controls.Add(buttonRight); Controls.Add(buttonRight);
Controls.Add(buttonCreateCleaningCar);
Controls.Add(pictureBoxCleaningCar); Controls.Add(pictureBoxCleaningCar);
Name = "FormCleaningCar"; Name = "FormCleaningCar";
Text = "FormCleaningCar"; Text = "FormCleaningCar";
@ -165,12 +138,10 @@
#endregion #endregion
private PictureBox pictureBoxCleaningCar; private PictureBox pictureBoxCleaningCar;
private Button buttonCreateCleaningCar;
private Button buttonRight; private Button buttonRight;
private Button buttonLeft; private Button buttonLeft;
private Button buttonUp; private Button buttonUp;
private Button buttonDown; private Button buttonDown;
private Button buttonCreateCar;
private ComboBox comboBoxStrategy; private ComboBox comboBoxStrategy;
private Button buttonStrategyStep; private Button buttonStrategyStep;
} }

View File

@ -16,6 +16,20 @@ public partial class FormCleaningCar : Form
/// </summary> /// </summary>
private AbstractStrategy? _strategy; private AbstractStrategy? _strategy;
/// <summary> /// <summary>
/// Получение объекта
/// </summary>
public DrawningCar SetCar
{
set
{
_drawningCar = value;
_drawningCar.SetPictureSize(pictureBoxCleaningCar.Width, pictureBoxCleaningCar.Height);
comboBoxStrategy.Enabled = true;
_strategy = null;
Draw();
}
}
/// <summary>
/// Конструктор формы /// Конструктор формы
/// </summary> /// </summary>
public FormCleaningCar() public FormCleaningCar()
@ -39,48 +53,6 @@ public partial class FormCleaningCar : Form
pictureBoxCleaningCar.Image = bmp; pictureBoxCleaningCar.Image = bmp;
} }
/// <summary> /// <summary>
/// Обработка нажатия кнопки "Создать подметательно-уборочную машину"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonCreateCleaningCar_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningCleaningCar));
/// <summary>
/// Обработка нажатия кнопки "Создать машину"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonCreateCar_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningCar));
/// <summary>
/// Создание объекта класса-перемещения
/// </summary>
/// <param name="type">Тип создаваемого объекта</param>
public void CreateObject(string type)
{
Random random = new Random();
switch (type)
{
case nameof(DrawningCar):
_drawningCar = new DrawningCar(random.Next(100, 300), random.Next(1000, 3000),
Color.FromArgb(random.Next(0, 255), random.Next(0, 255), random.Next(0, 255)));
break;
case nameof(DrawningCleaningCar):
_drawningCar = new DrawningCleaningCar(random.Next(100, 300), random.Next(1000, 3000),
Color.FromArgb(random.Next(0, 255), random.Next(0, 255), random.Next(0, 255)),
Color.FromArgb(random.Next(0, 255), random.Next(0, 255), random.Next(0, 255)),
Convert.ToBoolean(random.Next(0, 2)),
Convert.ToBoolean(random.Next(0, 2)),
Convert.ToBoolean(random.Next(0, 2)));
break;
default:
return;
}
_drawningCar.SetPictureSize(pictureBoxCleaningCar.Width, pictureBoxCleaningCar.Height);
_drawningCar.SetPosition(random.Next(0, 200), random.Next(0, 200));
_strategy = null;
comboBoxStrategy.Enabled = true;
Draw();
}
/// <summary>
/// Перемещение объекта по форме (нажатие кнопок навигации) /// Перемещение объекта по форме (нажатие кнопок навигации)
/// </summary> /// </summary>
/// <param name="sender"></param> /// <param name="sender"></param>

View File

@ -0,0 +1,170 @@
namespace ProjectCleaningCar
{
partial class FormCleaningCarCollection
{
/// <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()
{
tools = new GroupBox();
buttonRefresh = new Button();
buttonGoToCheck = new Button();
buttonDelCar = new Button();
maskedTextBoxPosition = new MaskedTextBox();
buttonAddCleaningCar = new Button();
buttonAddCar = new Button();
comboBoxSelectorCompany = new ComboBox();
pictureBox = new PictureBox();
tools.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
SuspendLayout();
//
// tools
//
tools.Controls.Add(buttonRefresh);
tools.Controls.Add(buttonGoToCheck);
tools.Controls.Add(buttonDelCar);
tools.Controls.Add(maskedTextBoxPosition);
tools.Controls.Add(buttonAddCleaningCar);
tools.Controls.Add(buttonAddCar);
tools.Controls.Add(comboBoxSelectorCompany);
tools.Dock = DockStyle.Right;
tools.Location = new Point(752, 0);
tools.Name = "tools";
tools.Size = new Size(208, 557);
tools.TabIndex = 0;
tools.TabStop = false;
tools.Text = "Инструменты";
//
// buttonRefresh
//
buttonRefresh.Location = new Point(24, 389);
buttonRefresh.Name = "buttonRefresh";
buttonRefresh.Size = new Size(163, 38);
buttonRefresh.TabIndex = 6;
buttonRefresh.Text = "Обновить";
buttonRefresh.UseVisualStyleBackColor = true;
buttonRefresh.Click += ButtonRefresh_Click;
//
// buttonGoToCheck
//
buttonGoToCheck.Location = new Point(24, 274);
buttonGoToCheck.Name = "buttonGoToCheck";
buttonGoToCheck.Size = new Size(163, 38);
buttonGoToCheck.TabIndex = 5;
buttonGoToCheck.Text = "Передать на тесты";
buttonGoToCheck.UseVisualStyleBackColor = true;
buttonGoToCheck.Click += ButtonGoToCheck_Click;
//
// buttonDelCar
//
buttonDelCar.Location = new Point(24, 187);
buttonDelCar.Name = "buttonDelCar";
buttonDelCar.Size = new Size(163, 38);
buttonDelCar.TabIndex = 4;
buttonDelCar.Text = "Удалить машину";
buttonDelCar.UseVisualStyleBackColor = true;
buttonDelCar.Click += ButtonRemoveCar_Click;
//
// maskedTextBoxPosition
//
maskedTextBoxPosition.Location = new Point(24, 158);
maskedTextBoxPosition.Mask = "00";
maskedTextBoxPosition.Name = "maskedTextBoxPosition";
maskedTextBoxPosition.Size = new Size(163, 23);
maskedTextBoxPosition.TabIndex = 3;
maskedTextBoxPosition.ValidatingType = typeof(int);
//
// buttonAddCleaningCar
//
buttonAddCleaningCar.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonAddCleaningCar.Location = new Point(24, 114);
buttonAddCleaningCar.Name = "buttonAddCleaningCar";
buttonAddCleaningCar.Size = new Size(163, 38);
buttonAddCleaningCar.TabIndex = 2;
buttonAddCleaningCar.Text = "Добавление уборочной машины";
buttonAddCleaningCar.UseVisualStyleBackColor = true;
buttonAddCleaningCar.Click += ButtonAddCleaningCar_Click;
//
// buttonAddCar
//
buttonAddCar.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonAddCar.Location = new Point(24, 70);
buttonAddCar.Name = "buttonAddCar";
buttonAddCar.Size = new Size(163, 38);
buttonAddCar.TabIndex = 1;
buttonAddCar.Text = "Добавление машины";
buttonAddCar.UseVisualStyleBackColor = true;
buttonAddCar.Click += ButtonAddCar_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(24, 22);
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
comboBoxSelectorCompany.Size = new Size(163, 23);
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(752, 557);
pictureBox.TabIndex = 1;
pictureBox.TabStop = false;
//
// FormCleaningCarCollection
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(960, 557);
Controls.Add(pictureBox);
Controls.Add(tools);
Name = "FormCleaningCarCollection";
Text = "Коллекция уборочных машин";
tools.ResumeLayout(false);
tools.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
ResumeLayout(false);
}
#endregion
private GroupBox tools;
private Button buttonAddCar;
private ComboBox comboBoxSelectorCompany;
private MaskedTextBox maskedTextBoxPosition;
private Button buttonAddCleaningCar;
private PictureBox pictureBox;
private Button buttonDelCar;
private Button buttonRefresh;
private Button buttonGoToCheck;
}
}

View File

@ -0,0 +1,190 @@
using ProjectCleaningCar.CollectionGenericObjects;
using ProjectCleaningCar.Drawning;
namespace ProjectCleaningCar;
/// <summary>
/// Форма работы с компанией и ее коллекцией
/// </summary>
public partial class FormCleaningCarCollection : Form
{
/// <summary>
/// Компания
/// </summary>
private AbstractCompany? _company = null;
/// <summary>
/// Конструктор
/// </summary>
public FormCleaningCarCollection()
{
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 CarSharingService(pictureBox.Width,
pictureBox.Height, new MassiveGenericObjects<DrawningCar>());
break;
}
}
/// <summary>
/// Добавление спортивного автомобиля
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonAddCar_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningCar));
/// <summary>
/// Добавление подметательно-уборочной машины
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonAddCleaningCar_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningCleaningCar));
/// <summary>
/// Создание объекта класса-перемещенияв
/// </summary>
/// <param name="type"></param>
private void CreateObject(string type)
{
if (_company == null)
{
return;
}
Random random = new();
DrawningCar drawningCar;
switch (type)
{
case nameof(DrawningCar):
drawningCar = new DrawningCar(random.Next(100, 300),
random.Next(1000, 3000), GetColor(random));
break;
case nameof(DrawningCleaningCar):
// TODO вызов диалогового окна для выбора цвета
drawningCar = new DrawningCleaningCar(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 + drawningCar)
{
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 ButtonRemoveCar_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;
}
DrawningCar? car = null;
int counter = 100;
while (car == null)
{
car = _company.GetRandomObject();
counter--;
if (counter <= 0) break;
}
if (car == null)
{
return;
}
FormCleaningCar form = new FormCleaningCar();
form.SetCar = car;
form.ShowDialog();
}
/// <summary>
/// Перерисовка коллекции
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonRefresh_Click(object sender, EventArgs e)
{
if (_company == null)
{
return;
}
DrawningCar? car = null;
int counter = 100;
while (car == null)
{
car = _company.GetRandomObject();
counter--;
if (counter <= 0)
{
break;
}
}
if (car == null)
{
return;
}
FormCleaningCar form = new()
{
SetCar = car
};
form.ShowDialog();
}
}

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 @@ public class MoveToBorder : AbstractStrategy
{ {
return false; return false;
} }
return objParams.RightBorder + GetStep() >= FieldWidth && objParams.DownBorder + GetStep() >= FieldHeight;\ return objParams.RightBorder + GetStep() >= FieldWidth && objParams.DownBorder + GetStep() >= FieldHeight;
} }
protected override void MoveToTarget() protected override void MoveToTarget()

View File

@ -11,7 +11,7 @@ namespace ProjectCleaningCar
// 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 FormCleaningCar()); Application.Run(new FormCleaningCarCollection());
} }
} }
} }