Лабораторная работа №3
This commit is contained in:
parent
f4d9f4ae93
commit
cd8d8bdf35
@ -0,0 +1,106 @@
|
|||||||
|
using ProjectCleaningCar.Drawnings;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectCleaningCar.CollectionGenericObjects;
|
||||||
|
/// <summary>
|
||||||
|
/// Абстракция компании, хранящий коллекцию автомобилей
|
||||||
|
/// </summary>
|
||||||
|
public abstract class AbstractCompany
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Размер места (ширина)
|
||||||
|
/// </summary>
|
||||||
|
protected readonly int _placeSizeWidth = 150;
|
||||||
|
/// <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 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)
|
||||||
|
{
|
||||||
|
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();
|
||||||
|
}
|
@ -0,0 +1,53 @@
|
|||||||
|
using ProjectCleaningCar.Drawnings;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics.Metrics;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectCleaningCar.CollectionGenericObjects;
|
||||||
|
/// <summary>
|
||||||
|
/// Реализация абстрактной компании - каршеринг
|
||||||
|
/// </summary>
|
||||||
|
public class CarSharingCompany : AbstractCompany
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="picWidth"></param>
|
||||||
|
/// <param name="picHeight"></param>
|
||||||
|
/// <param name="collection"></param>
|
||||||
|
public CarSharingCompany(int picWidth, int picHeight, ICollectionGenericObjects<DrawningCar> collection) : base(picWidth, picHeight, collection)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void DrawBackgound(Graphics g)
|
||||||
|
{
|
||||||
|
Pen pen = new(Color.Black, 4);
|
||||||
|
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
|
||||||
|
{
|
||||||
|
g.DrawLine(pen, i * 190, j * 90, i * 190 + 150, j * 90);
|
||||||
|
}
|
||||||
|
g.DrawLine(pen, i * 190, 0, i * 190, 630);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void SetObjectsPosition()
|
||||||
|
{
|
||||||
|
int counter = 0;
|
||||||
|
for (int y = 5; y < _pictureHeight; y += 90)
|
||||||
|
{
|
||||||
|
for (int x = 5; x < _pictureWidth; x += 190)
|
||||||
|
{
|
||||||
|
_collection?.Get(counter)?.SetPictureSize(_pictureWidth, _pictureHeight);
|
||||||
|
_collection?.Get(counter)?.SetPosition(x, y);
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,48 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectCleaningCar.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>
|
||||||
|
bool Insert(T obj);
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление объекта в коллекцию на конкретную позицию
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="obj">Добавляемый объект</param>
|
||||||
|
/// <param name="position">Позиция</param>
|
||||||
|
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
|
||||||
|
bool Insert(T obj, int position);
|
||||||
|
/// <summary>
|
||||||
|
/// Удаление объекта из коллекции с конкретной позиции
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="position">Позиция</param>
|
||||||
|
/// <returns>true - удаление прошло удачно, false - удаление не удалось</returns>
|
||||||
|
bool Remove(int position);
|
||||||
|
/// <summary>
|
||||||
|
/// Получение объекта по позиции
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="position">Позиция</param>
|
||||||
|
/// <returns>Объект</returns>
|
||||||
|
T? Get(int position);
|
||||||
|
}
|
@ -0,0 +1,97 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectCleaningCar.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)
|
||||||
|
{
|
||||||
|
if (position < 0 || position >= _collection.Length)
|
||||||
|
{
|
||||||
|
throw new IndexOutOfRangeException("Position is out of range.");
|
||||||
|
}
|
||||||
|
return _collection[position];
|
||||||
|
}
|
||||||
|
public bool Insert(T obj)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < _collection.Length; i++)
|
||||||
|
{
|
||||||
|
if (_collection[i] == null)
|
||||||
|
{
|
||||||
|
_collection[i] = obj;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
public bool Insert(T obj, int position)
|
||||||
|
{
|
||||||
|
if (position < 0 || position >= _collection.Length)
|
||||||
|
{
|
||||||
|
throw new IndexOutOfRangeException("Position is out of range.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_collection[position] == null)
|
||||||
|
{
|
||||||
|
_collection[position] = obj;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
public bool Remove(int position)
|
||||||
|
{
|
||||||
|
if (position < 0 || position >= _collection.Length)
|
||||||
|
{
|
||||||
|
throw new IndexOutOfRangeException("Position is out of range.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_collection[position] != null)
|
||||||
|
{
|
||||||
|
_collection[position] = null;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -112,7 +112,7 @@ public class DrawningCar
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Установка позиция
|
/// Установка позиции
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="x">Координата Х</param>
|
/// <param name="x">Координата Х</param>
|
||||||
/// <param name="y">Координата Y</param>
|
/// <param name="y">Координата Y</param>
|
||||||
|
175
ProjectCleaningCar/ProjectCleaningCar/FormCarCollection.Designer.cs
generated
Normal file
175
ProjectCleaningCar/ProjectCleaningCar/FormCarCollection.Designer.cs
generated
Normal file
@ -0,0 +1,175 @@
|
|||||||
|
|
||||||
|
namespace ProjectCleaningCar
|
||||||
|
{
|
||||||
|
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();
|
||||||
|
buttonRemoveCar = new Button();
|
||||||
|
maskedTextBoxPosition = new MaskedTextBox();
|
||||||
|
buttonAddCleaningCar = new Button();
|
||||||
|
buttonAddCar = 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(buttonRemoveCar);
|
||||||
|
groupBoxTools.Controls.Add(maskedTextBoxPosition);
|
||||||
|
groupBoxTools.Controls.Add(buttonAddCleaningCar);
|
||||||
|
groupBoxTools.Controls.Add(buttonAddCar);
|
||||||
|
groupBoxTools.Controls.Add(comboBoxSelectorCompany);
|
||||||
|
groupBoxTools.Dock = DockStyle.Right;
|
||||||
|
groupBoxTools.Location = new Point(933, 0);
|
||||||
|
groupBoxTools.Name = "groupBoxTools";
|
||||||
|
groupBoxTools.Size = new Size(250, 636);
|
||||||
|
groupBoxTools.TabIndex = 0;
|
||||||
|
groupBoxTools.TabStop = false;
|
||||||
|
groupBoxTools.Text = "Инструменты";
|
||||||
|
//
|
||||||
|
// buttonRefresh
|
||||||
|
//
|
||||||
|
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
|
buttonRefresh.Location = new Point(12, 470);
|
||||||
|
buttonRefresh.Name = "buttonRefresh";
|
||||||
|
buttonRefresh.Size = new Size(226, 69);
|
||||||
|
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(12, 378);
|
||||||
|
buttonGoToCheck.Name = "buttonGoToCheck";
|
||||||
|
buttonGoToCheck.Size = new Size(226, 69);
|
||||||
|
buttonGoToCheck.TabIndex = 5;
|
||||||
|
buttonGoToCheck.Text = "Передать на тесты";
|
||||||
|
buttonGoToCheck.UseVisualStyleBackColor = true;
|
||||||
|
buttonGoToCheck.Click += buttonGoToCheck_Click;
|
||||||
|
//
|
||||||
|
// buttonRemoveCar
|
||||||
|
//
|
||||||
|
buttonRemoveCar.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
|
buttonRemoveCar.Location = new Point(12, 284);
|
||||||
|
buttonRemoveCar.Name = "buttonRemoveCar";
|
||||||
|
buttonRemoveCar.Size = new Size(226, 69);
|
||||||
|
buttonRemoveCar.TabIndex = 4;
|
||||||
|
buttonRemoveCar.Text = "Удаление машины";
|
||||||
|
buttonRemoveCar.UseVisualStyleBackColor = true;
|
||||||
|
buttonRemoveCar.Click += buttonRemoveCar_Click;
|
||||||
|
//
|
||||||
|
// maskedTextBoxPosition
|
||||||
|
//
|
||||||
|
maskedTextBoxPosition.Location = new Point(12, 228);
|
||||||
|
maskedTextBoxPosition.Mask = "00";
|
||||||
|
maskedTextBoxPosition.Name = "maskedTextBoxPosition";
|
||||||
|
maskedTextBoxPosition.Size = new Size(226, 27);
|
||||||
|
maskedTextBoxPosition.TabIndex = 3;
|
||||||
|
maskedTextBoxPosition.ValidatingType = typeof(int);
|
||||||
|
maskedTextBoxPosition.MaskInputRejected += maskedTextBoxPosition_MaskInputRejected;
|
||||||
|
//
|
||||||
|
// buttonAddCleaningCar
|
||||||
|
//
|
||||||
|
buttonAddCleaningCar.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
|
buttonAddCleaningCar.Location = new Point(12, 129);
|
||||||
|
buttonAddCleaningCar.Name = "buttonAddCleaningCar";
|
||||||
|
buttonAddCleaningCar.Size = new Size(226, 69);
|
||||||
|
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(12, 69);
|
||||||
|
buttonAddCar.Name = "buttonAddCar";
|
||||||
|
buttonAddCar.Size = new Size(226, 54);
|
||||||
|
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(12, 26);
|
||||||
|
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
|
||||||
|
comboBoxSelectorCompany.Size = new Size(232, 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(933, 636);
|
||||||
|
pictureBox.TabIndex = 1;
|
||||||
|
pictureBox.TabStop = false;
|
||||||
|
//
|
||||||
|
// FormCarCollection
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(1183, 636);
|
||||||
|
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 comboBoxSelectorCompany;
|
||||||
|
private Button buttonAddCar;
|
||||||
|
private Button buttonAddCleaningCar;
|
||||||
|
private PictureBox pictureBox;
|
||||||
|
private MaskedTextBox maskedTextBoxPosition;
|
||||||
|
private Button buttonRemoveCar;
|
||||||
|
private Button buttonGoToCheck;
|
||||||
|
private Button buttonRefresh;
|
||||||
|
}
|
||||||
|
}
|
222
ProjectCleaningCar/ProjectCleaningCar/FormCarCollection.cs
Normal file
222
ProjectCleaningCar/ProjectCleaningCar/FormCarCollection.cs
Normal file
@ -0,0 +1,222 @@
|
|||||||
|
using ProjectCleaningCar.CollectionGenericObjects;
|
||||||
|
using ProjectCleaningCar.Drawnings;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Data;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace ProjectCleaningCar;
|
||||||
|
/// <summary>
|
||||||
|
/// Форма работы с компанией и ее коллекцией
|
||||||
|
/// </summary>
|
||||||
|
public partial class FormCarCollection : Form
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Компания
|
||||||
|
/// </summary>
|
||||||
|
private AbstractCompany? _company = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
public FormCarCollection()
|
||||||
|
{
|
||||||
|
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 CarSharingCompany(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):
|
||||||
|
// Вызываем диалоговое окно для выбора основного цвета машины
|
||||||
|
Color bodyColor;
|
||||||
|
using (ColorDialog dialogBody = new ColorDialog())
|
||||||
|
{
|
||||||
|
if (dialogBody.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
bodyColor = dialogBody.Color;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Если диалог был закрыт без выбора цвета, выходим из метода
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Вызываем диалоговое окно для выбора дополнительного цвета машины
|
||||||
|
Color additionalColor;
|
||||||
|
using (ColorDialog dialogAdditional = new ColorDialog())
|
||||||
|
{
|
||||||
|
if (dialogAdditional.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
additionalColor = dialogAdditional.Color;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Если диалог был закрыт без выбора цвета, выходим из метода
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Создаем объект класса DrawningCleaningCar с выбранными цветами
|
||||||
|
drawningCar = new DrawningCleaningCar(
|
||||||
|
random.Next(100, 300),
|
||||||
|
random.Next(1000, 3000),
|
||||||
|
bodyColor,
|
||||||
|
additionalColor,
|
||||||
|
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()
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
pictureBox.Image = _company.Show();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void maskedTextBoxPosition_MaskInputRejected(object sender, MaskInputRejectedEventArgs e)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
120
ProjectCleaningCar/ProjectCleaningCar/FormCarCollection.resx
Normal file
120
ProjectCleaningCar/ProjectCleaningCar/FormCarCollection.resx
Normal 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>
|
@ -29,12 +29,10 @@
|
|||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
pictureBoxCleaningCar = new PictureBox();
|
pictureBoxCleaningCar = new PictureBox();
|
||||||
buttonCreateCleaningCar = new Button();
|
|
||||||
ButtonUp = new Button();
|
ButtonUp = new Button();
|
||||||
ButtonRight = new Button();
|
ButtonRight = new Button();
|
||||||
ButtonLeft = new Button();
|
ButtonLeft = 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();
|
||||||
@ -44,33 +42,24 @@
|
|||||||
//
|
//
|
||||||
pictureBoxCleaningCar.Dock = DockStyle.Fill;
|
pictureBoxCleaningCar.Dock = DockStyle.Fill;
|
||||||
pictureBoxCleaningCar.Location = new Point(0, 0);
|
pictureBoxCleaningCar.Location = new Point(0, 0);
|
||||||
|
pictureBoxCleaningCar.Margin = new Padding(3, 4, 3, 4);
|
||||||
pictureBoxCleaningCar.Name = "pictureBoxCleaningCar";
|
pictureBoxCleaningCar.Name = "pictureBoxCleaningCar";
|
||||||
pictureBoxCleaningCar.Size = new Size(884, 461);
|
pictureBoxCleaningCar.Size = new Size(1010, 615);
|
||||||
pictureBoxCleaningCar.SizeMode = PictureBoxSizeMode.AutoSize;
|
pictureBoxCleaningCar.SizeMode = PictureBoxSizeMode.AutoSize;
|
||||||
pictureBoxCleaningCar.TabIndex = 1;
|
pictureBoxCleaningCar.TabIndex = 1;
|
||||||
pictureBoxCleaningCar.TabStop = false;
|
pictureBoxCleaningCar.TabStop = false;
|
||||||
pictureBoxCleaningCar.Click += buttonMove_Click;
|
pictureBoxCleaningCar.Click += buttonMove_Click;
|
||||||
pictureBoxCleaningCar.Resize += PictureBox_Resize;
|
pictureBoxCleaningCar.Resize += PictureBox_Resize;
|
||||||
//
|
//
|
||||||
// buttonCreateCleaningCar
|
|
||||||
//
|
|
||||||
buttonCreateCleaningCar.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
|
||||||
buttonCreateCleaningCar.Location = new Point(22, 409);
|
|
||||||
buttonCreateCleaningCar.Name = "buttonCreateCleaningCar";
|
|
||||||
buttonCreateCleaningCar.Size = new Size(198, 30);
|
|
||||||
buttonCreateCleaningCar.TabIndex = 2;
|
|
||||||
buttonCreateCleaningCar.Text = "Создать уборочную машину";
|
|
||||||
buttonCreateCleaningCar.UseVisualStyleBackColor = true;
|
|
||||||
buttonCreateCleaningCar.Click += buttonCreateCleaningCar_Click;
|
|
||||||
//
|
|
||||||
// ButtonUp
|
// ButtonUp
|
||||||
//
|
//
|
||||||
ButtonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
ButtonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
ButtonUp.BackgroundImage = Properties.Resources._1614525823_30_p_strelka_na_belom_fone_33__Up_;
|
ButtonUp.BackgroundImage = Properties.Resources._1614525823_30_p_strelka_na_belom_fone_33__Up_;
|
||||||
ButtonUp.BackgroundImageLayout = ImageLayout.Zoom;
|
ButtonUp.BackgroundImageLayout = ImageLayout.Zoom;
|
||||||
ButtonUp.Location = new Point(761, 373);
|
ButtonUp.Location = new Point(870, 497);
|
||||||
|
ButtonUp.Margin = new Padding(3, 4, 3, 4);
|
||||||
ButtonUp.Name = "ButtonUp";
|
ButtonUp.Name = "ButtonUp";
|
||||||
ButtonUp.Size = new Size(30, 30);
|
ButtonUp.Size = new Size(34, 40);
|
||||||
ButtonUp.TabIndex = 3;
|
ButtonUp.TabIndex = 3;
|
||||||
ButtonUp.UseVisualStyleBackColor = true;
|
ButtonUp.UseVisualStyleBackColor = true;
|
||||||
ButtonUp.Click += buttonMove_Click;
|
ButtonUp.Click += buttonMove_Click;
|
||||||
@ -80,9 +69,10 @@
|
|||||||
ButtonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
ButtonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
ButtonRight.BackgroundImage = Properties.Resources._1614525823_30_p_strelka_na_belom_fone__Right_;
|
ButtonRight.BackgroundImage = Properties.Resources._1614525823_30_p_strelka_na_belom_fone__Right_;
|
||||||
ButtonRight.BackgroundImageLayout = ImageLayout.Zoom;
|
ButtonRight.BackgroundImageLayout = ImageLayout.Zoom;
|
||||||
ButtonRight.Location = new Point(797, 409);
|
ButtonRight.Location = new Point(911, 545);
|
||||||
|
ButtonRight.Margin = new Padding(3, 4, 3, 4);
|
||||||
ButtonRight.Name = "ButtonRight";
|
ButtonRight.Name = "ButtonRight";
|
||||||
ButtonRight.Size = new Size(30, 30);
|
ButtonRight.Size = new Size(34, 40);
|
||||||
ButtonRight.TabIndex = 4;
|
ButtonRight.TabIndex = 4;
|
||||||
ButtonRight.UseVisualStyleBackColor = true;
|
ButtonRight.UseVisualStyleBackColor = true;
|
||||||
ButtonRight.Click += buttonMove_Click;
|
ButtonRight.Click += buttonMove_Click;
|
||||||
@ -92,9 +82,10 @@
|
|||||||
ButtonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
ButtonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
ButtonLeft.BackgroundImage = Properties.Resources._1614525823_30_p_strelka_na_belom_fone_33__Left_;
|
ButtonLeft.BackgroundImage = Properties.Resources._1614525823_30_p_strelka_na_belom_fone_33__Left_;
|
||||||
ButtonLeft.BackgroundImageLayout = ImageLayout.Zoom;
|
ButtonLeft.BackgroundImageLayout = ImageLayout.Zoom;
|
||||||
ButtonLeft.Location = new Point(725, 409);
|
ButtonLeft.Location = new Point(829, 545);
|
||||||
|
ButtonLeft.Margin = new Padding(3, 4, 3, 4);
|
||||||
ButtonLeft.Name = "ButtonLeft";
|
ButtonLeft.Name = "ButtonLeft";
|
||||||
ButtonLeft.Size = new Size(30, 30);
|
ButtonLeft.Size = new Size(34, 40);
|
||||||
ButtonLeft.TabIndex = 5;
|
ButtonLeft.TabIndex = 5;
|
||||||
ButtonLeft.UseVisualStyleBackColor = true;
|
ButtonLeft.UseVisualStyleBackColor = true;
|
||||||
ButtonLeft.Click += buttonMove_Click;
|
ButtonLeft.Click += buttonMove_Click;
|
||||||
@ -104,39 +95,31 @@
|
|||||||
ButtonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
ButtonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
ButtonDown.BackgroundImage = Properties.Resources._1614525823_30_p_strelka_na_belom_fone_33__Down_;
|
ButtonDown.BackgroundImage = Properties.Resources._1614525823_30_p_strelka_na_belom_fone_33__Down_;
|
||||||
ButtonDown.BackgroundImageLayout = ImageLayout.Zoom;
|
ButtonDown.BackgroundImageLayout = ImageLayout.Zoom;
|
||||||
ButtonDown.Location = new Point(761, 409);
|
ButtonDown.Location = new Point(870, 545);
|
||||||
|
ButtonDown.Margin = new Padding(3, 4, 3, 4);
|
||||||
ButtonDown.Name = "ButtonDown";
|
ButtonDown.Name = "ButtonDown";
|
||||||
ButtonDown.Size = new Size(30, 30);
|
ButtonDown.Size = new Size(34, 40);
|
||||||
ButtonDown.TabIndex = 6;
|
ButtonDown.TabIndex = 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(238, 409);
|
|
||||||
buttonCreateCar.Name = "buttonCreateCar";
|
|
||||||
buttonCreateCar.Size = new Size(198, 30);
|
|
||||||
buttonCreateCar.TabIndex = 7;
|
|
||||||
buttonCreateCar.Text = "Создать машину";
|
|
||||||
buttonCreateCar.UseVisualStyleBackColor = true;
|
|
||||||
buttonCreateCar.Click += buttonCreateCar_Click;
|
|
||||||
//
|
|
||||||
// comboBoxStrategy
|
// comboBoxStrategy
|
||||||
//
|
//
|
||||||
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
|
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||||
comboBoxStrategy.FormattingEnabled = true;
|
comboBoxStrategy.FormattingEnabled = true;
|
||||||
comboBoxStrategy.Items.AddRange(new object[] { "К центру ", "К краю" });
|
comboBoxStrategy.Items.AddRange(new object[] { "К центру ", "К краю" });
|
||||||
comboBoxStrategy.Location = new Point(761, 12);
|
comboBoxStrategy.Location = new Point(870, 16);
|
||||||
|
comboBoxStrategy.Margin = new Padding(3, 4, 3, 4);
|
||||||
comboBoxStrategy.Name = "comboBoxStrategy";
|
comboBoxStrategy.Name = "comboBoxStrategy";
|
||||||
comboBoxStrategy.Size = new Size(121, 23);
|
comboBoxStrategy.Size = new Size(138, 28);
|
||||||
comboBoxStrategy.TabIndex = 8;
|
comboBoxStrategy.TabIndex = 8;
|
||||||
//
|
//
|
||||||
// buttonStrategyStep
|
// buttonStrategyStep
|
||||||
//
|
//
|
||||||
buttonStrategyStep.Location = new Point(797, 41);
|
buttonStrategyStep.Location = new Point(911, 55);
|
||||||
|
buttonStrategyStep.Margin = new Padding(3, 4, 3, 4);
|
||||||
buttonStrategyStep.Name = "buttonStrategyStep";
|
buttonStrategyStep.Name = "buttonStrategyStep";
|
||||||
buttonStrategyStep.Size = new Size(75, 23);
|
buttonStrategyStep.Size = new Size(86, 31);
|
||||||
buttonStrategyStep.TabIndex = 9;
|
buttonStrategyStep.TabIndex = 9;
|
||||||
buttonStrategyStep.Text = "Шаг";
|
buttonStrategyStep.Text = "Шаг";
|
||||||
buttonStrategyStep.UseVisualStyleBackColor = true;
|
buttonStrategyStep.UseVisualStyleBackColor = true;
|
||||||
@ -144,18 +127,17 @@
|
|||||||
//
|
//
|
||||||
// FormCleaningCar
|
// FormCleaningCar
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(884, 461);
|
ClientSize = new Size(1010, 615);
|
||||||
Controls.Add(buttonStrategyStep);
|
Controls.Add(buttonStrategyStep);
|
||||||
Controls.Add(comboBoxStrategy);
|
Controls.Add(comboBoxStrategy);
|
||||||
Controls.Add(buttonCreateCar);
|
|
||||||
Controls.Add(ButtonDown);
|
Controls.Add(ButtonDown);
|
||||||
Controls.Add(ButtonLeft);
|
Controls.Add(ButtonLeft);
|
||||||
Controls.Add(ButtonRight);
|
Controls.Add(ButtonRight);
|
||||||
Controls.Add(ButtonUp);
|
Controls.Add(ButtonUp);
|
||||||
Controls.Add(buttonCreateCleaningCar);
|
|
||||||
Controls.Add(pictureBoxCleaningCar);
|
Controls.Add(pictureBoxCleaningCar);
|
||||||
|
Margin = new Padding(3, 4, 3, 4);
|
||||||
Name = "FormCleaningCar";
|
Name = "FormCleaningCar";
|
||||||
StartPosition = FormStartPosition.CenterScreen;
|
StartPosition = FormStartPosition.CenterScreen;
|
||||||
Text = "Подметально-уборочная машина";
|
Text = "Подметально-уборочная машина";
|
||||||
@ -167,12 +149,10 @@
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private PictureBox pictureBoxCleaningCar;
|
private PictureBox pictureBoxCleaningCar;
|
||||||
private Button buttonCreateCleaningCar;
|
|
||||||
private Button ButtonUp;
|
private Button ButtonUp;
|
||||||
private Button ButtonRight;
|
private Button ButtonRight;
|
||||||
private Button ButtonLeft;
|
private Button ButtonLeft;
|
||||||
private Button ButtonDown;
|
private Button ButtonDown;
|
||||||
private Button buttonCreateCar;
|
|
||||||
private ComboBox comboBoxStrategy;
|
private ComboBox comboBoxStrategy;
|
||||||
private Button buttonStrategyStep;
|
private Button buttonStrategyStep;
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,19 @@ namespace ProjectCleaningCar
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private AbstractStrategy? _strategy;
|
private AbstractStrategy? _strategy;
|
||||||
|
|
||||||
|
public DrawningCar SetCar
|
||||||
|
{
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_drawningCar = value;
|
||||||
|
_drawningCar.SetPictureSize(pictureBoxCleaningCar.Width,
|
||||||
|
pictureBoxCleaningCar.Height);
|
||||||
|
comboBoxStrategy.Enabled = true;
|
||||||
|
_strategy = null;
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Конструктор формы
|
/// Конструктор формы
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -50,49 +63,6 @@ namespace ProjectCleaningCar
|
|||||||
_drawningCar.DrawTransport(gr);
|
_drawningCar.DrawTransport(gr);
|
||||||
pictureBoxCleaningCar.Image = bmp;
|
pictureBoxCleaningCar.Image = bmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Создание объекта класса-перемещения
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="type">Тип создаваемоего объекта</param>
|
|
||||||
private void CreateObject(string type)
|
|
||||||
{
|
|
||||||
Random random = new();
|
|
||||||
switch (type)
|
|
||||||
{
|
|
||||||
case nameof(DrawningCar):
|
|
||||||
_drawningCar = new DrawningCar(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(DrawningCleaningCar):
|
|
||||||
_drawningCar = new DrawningCleaningCar(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;
|
|
||||||
}
|
|
||||||
_drawningCar.SetPictureSize(pictureBoxCleaningCar.Width, pictureBoxCleaningCar.Height);
|
|
||||||
_drawningCar.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 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>
|
||||||
/// Перемещение объекта по форме (нажатие кнопок навигации)
|
/// Перемещение объекта по форме (нажатие кнопок навигации)
|
||||||
|
@ -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 FormCarCollection());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user