лабораторная 3

This commit is contained in:
mara-1 2024-03-30 22:55:26 +04:00
parent 1353638437
commit 0cef2fe107
12 changed files with 715 additions and 105 deletions

View File

@ -0,0 +1,4 @@
[*.cs]
# IDE0004: Удалить ненужное приведение
dotnet_diagnostic.IDE0004.severity = none

View File

@ -3,7 +3,12 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.9.34607.119
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProjectBulldozer", "ProjectBulldozer\ProjectBulldozer.csproj", "{B5EB70F6-27D7-48D1-B3A2-22049B8286F2}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ProjectBulldozer", "ProjectBulldozer\ProjectBulldozer.csproj", "{B5EB70F6-27D7-48D1-B3A2-22049B8286F2}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{5D00A175-7BBA-4247-B014-5919F831C588}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution

View File

@ -0,0 +1,116 @@
using ProjectBulldozer.Drawnings;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectBulldozer.CollectionGenericObjects;
public abstract class AbstractCompany
{
/// <summary>
/// Размер места (ширина)
/// </summary>
protected readonly int _placeSizeWidth = 180;
/// <summary>
/// Размер места (высота)
/// </summary>
protected readonly int _placeSizeHeight = 150;
/// <summary>
/// Ширина окна
/// </summary>
protected readonly int _pictureWidth;
/// <summary>
/// Высота окна
/// </summary>
protected readonly int _pictureHeight;
/// <summary>
/// Коллекция машин
/// </summary>
protected ICollectionGenericObjects<DrawningTrackedMachine>? _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<DrawningTrackedMachine> collection)
{
_pictureWidth = picWidth;
_pictureHeight = picHeight;
_collection = collection;
_collection.SetMaxCount = GetMaxCount;
}
/// <summary>
/// Перегрузка оператора сложения для класса
/// </summary>
/// <param name="company">Компания</param>
/// <param name="trackedMachine">Добавляемый объект</param>
/// <returns></returns>
public static int operator +(AbstractCompany company, DrawningTrackedMachine trackedMachine)
{
return company._collection.Insert(trackedMachine);
}
/// <summary>
/// Перегрузка оператора удаления для класса
/// </summary>
/// <param name="company">Компания</param>
/// <param name="position">Номер удаляемого объекта</param>
/// <returns></returns>
public static DrawningTrackedMachine operator -(AbstractCompany company, int position)
{
return company._collection.Remove(position);
}
/// <summary>
/// Получение случайного объекта из коллекции
/// </summary>
/// <returns></returns>
public DrawningTrackedMachine? 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)
{
DrawningTrackedMachine? 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,52 @@
using ProjectBulldozer.Drawnings;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectBulldozer.CollectionGenericObjects;
public class Garage : AbstractCompany
{
public Garage(int picWidth, int picHeight, ICollectionGenericObjects<DrawningTrackedMachine> collection) : base(picWidth, picHeight, collection)
{
}
protected override void DrawBackgound(Graphics g)
{
Pen pen = new(Color.Black, 4f);
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
{
for (int j = 0; j < _pictureHeight / _placeSizeHeight; j++)
{
g.DrawLine(pen, new(_placeSizeWidth * i, _placeSizeHeight * j), new((int)(_placeSizeWidth * (i + 0.5f)), _placeSizeHeight * j));
g.DrawLine(pen, new(_placeSizeWidth * i, _placeSizeHeight * j), new(_placeSizeWidth * i, _placeSizeHeight * (j + 1)));
}
g.DrawLine(pen, new(_placeSizeWidth * i, _placeSizeHeight * (_pictureHeight / _placeSizeHeight)), new((int)(_placeSizeWidth * (i + 0.5f)), _placeSizeHeight * (_pictureHeight / _placeSizeHeight)));
}
}
protected override void SetObjectsPosition()
{
int n = 0;
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
{
for (int j = 0; j < _pictureHeight / _placeSizeHeight; j++)
{
DrawningTrackedMachine? drawningTrackedMachine = _collection?.Get(n);
n++;
if (drawningTrackedMachine != null)
{
drawningTrackedMachine.SetPictureSize(_pictureWidth, _pictureHeight);
drawningTrackedMachine.SetPosition(i * _placeSizeWidth + 5, j * _placeSizeHeight + 5);
}
}
}
}
}

View File

@ -36,7 +36,7 @@ public class DrawningBulldozer : DrawningTrackedMachine
Pen pen = new(Color.Black);
Brush bodyBrush = new SolidBrush(Bulldozer.BodyColor);
Brush bodyBrush2 = new SolidBrush(Bulldozer.AdditionalColor);
@ -46,11 +46,10 @@ public class DrawningBulldozer : DrawningTrackedMachine
base.DrawTransport(g);
_startPosX -= 10;
Brush bl = new SolidBrush(Bulldozer.AdditionalColor);
Brush bodyBrush2 = new SolidBrush(Bulldozer.AdditionalColor);
/////////отвал
///
if (Bulldozer.AdditionalOtval)
{
Point[] Otval =
{
new Point(_startPosX.Value + 142, _startPosY.Value + 70),
@ -60,17 +59,6 @@ public class DrawningBulldozer : DrawningTrackedMachine
};
g.FillPolygon(bl, Otval);
g.DrawPolygon(pen, Otval);
}
///рыхлитель
if (Bulldozer.AdditionalRihl)
{
Brush black = new SolidBrush(Color.Black);
Point[] Rihl =
{
@ -93,7 +81,9 @@ public class DrawningBulldozer : DrawningTrackedMachine
g.FillPolygon(black, Ttt);
g.DrawPolygon(pen, Ttt);
}
g.FillPolygon(bodyBrush2, Otval);
g.DrawPolygon(pen, Otval);
}
}

View File

@ -148,8 +148,7 @@ public class DrawningTrackedMachine
public bool MoveTransport(DirectionType direction)
{
if (EntityTrackedMachine == null || !_startPosX.HasValue ||
!_startPosY.HasValue)
if (EntityTrackedMachine == null || !_startPosX.HasValue || !_startPosY.HasValue)
{
return false;
}

View File

@ -29,12 +29,10 @@
private void InitializeComponent()
{
pictureBoxBulldozer = new PictureBox();
buttonCreate = new Button();
buttonRight = new Button();
buttonDown = new Button();
buttonLeft = new Button();
buttonUp = new Button();
buttonCreateBulldozerProstoy = new Button();
ButtonStrategyStep = new Button();
comboBoxStrategy = new ComboBox();
((System.ComponentModel.ISupportInitialize)pictureBoxBulldozer).BeginInit();
@ -49,17 +47,6 @@
pictureBoxBulldozer.TabIndex = 0;
pictureBoxBulldozer.TabStop = false;
//
// buttonCreate
//
buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonCreate.Location = new Point(12, 511);
buttonCreate.Name = "buttonCreate";
buttonCreate.Size = new Size(231, 29);
buttonCreate.TabIndex = 1;
buttonCreate.Text = "Создать бульозер с доп.";
buttonCreate.UseVisualStyleBackColor = true;
buttonCreate.Click += ButtonCreateBulldozer_Click;
//
// buttonRight
//
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
@ -108,17 +95,6 @@
buttonUp.UseVisualStyleBackColor = true;
buttonUp.Click += ButtonMove_Click;
//
// buttonCreateBulldozerProstoy
//
buttonCreateBulldozerProstoy.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonCreateBulldozerProstoy.Location = new Point(274, 511);
buttonCreateBulldozerProstoy.Name = "buttonCreateBulldozerProstoy";
buttonCreateBulldozerProstoy.Size = new Size(231, 29);
buttonCreateBulldozerProstoy.TabIndex = 6;
buttonCreateBulldozerProstoy.Text = "Создать простой бульдозер";
buttonCreateBulldozerProstoy.UseVisualStyleBackColor = true;
buttonCreateBulldozerProstoy.Click += buttonCreateBulldozerProstoy_Click;
//
// ButtonStrategyStep
//
ButtonStrategyStep.Location = new Point(793, 46);
@ -138,19 +114,16 @@
comboBoxStrategy.Name = "comboBoxStrategy";
comboBoxStrategy.Size = new Size(143, 28);
comboBoxStrategy.TabIndex = 9;
//
// FormBulldozer
//
ClientSize = new Size(899, 552);
Controls.Add(comboBoxStrategy);
Controls.Add(ButtonStrategyStep);
Controls.Add(buttonCreateBulldozerProstoy);
Controls.Add(buttonUp);
Controls.Add(buttonLeft);
Controls.Add(buttonDown);
Controls.Add(buttonRight);
Controls.Add(buttonCreate);
Controls.Add(pictureBoxBulldozer);
Name = "FormBulldozer";
((System.ComponentModel.ISupportInitialize)pictureBoxBulldozer).EndInit();
@ -161,12 +134,10 @@
private PictureBox pictureBoxBulldozer;
private Button buttonCreate;
private Button buttonRight;
private Button buttonDown;
private Button buttonLeft;
private Button buttonUp;
private Button buttonCreateBulldozerProstoy;
private Button ButtonStrategyStep;
private ComboBox comboBoxStrategy;
}

View File

@ -17,9 +17,28 @@ namespace ProjectBulldozer
/// <summary>
/// Поле-объект для прорисовки объекта
/// </summary>
private DrawningTrackedMachine? _drawningBulldozerProstoy;
private DrawningTrackedMachine? _drawningTrackedMachine;
/// <summary>
/// Стратегия перемещения
/// </summary>
private AbstractStrategy? _strategy;
/// <summary>
/// Получение объекта
/// </summary>
public DrawningTrackedMachine SetTrackedMachine
{
set
{
_drawningTrackedMachine = value;
_drawningTrackedMachine.SetPictureSize(pictureBoxBulldozer.Width, pictureBoxBulldozer.Height);
comboBoxStrategy.Enabled = true;
_strategy = null;
Draw();
}
}
/// <summary>
/// Конструктор формы
/// </summary>
@ -33,63 +52,17 @@ namespace ProjectBulldozer
/// </summary>
private void Draw()
{
if (_drawningBulldozerProstoy == null)
if (_drawningTrackedMachine == null)
{
return;
}
Bitmap bmp = new(pictureBoxBulldozer.Width,
pictureBoxBulldozer.Height);
Graphics gr = Graphics.FromImage(bmp);
_drawningBulldozerProstoy.DrawTransport(gr);
_drawningTrackedMachine.DrawTransport(gr);
pictureBoxBulldozer.Image = bmp;
}
/// <summary>
/// создеание объекта класса-перемещения
/// </summary>
/// <param name="type">Тип создаваемого объекта</param>
private void CreateObject(string type)
{
Random random = new();
switch (type)
{
case nameof(DrawningTrackedMachine):
_drawningBulldozerProstoy = new DrawningTrackedMachine(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(DrawningBulldozer):
_drawningBulldozerProstoy = new DrawningBulldozer(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;
}
_drawningBulldozerProstoy.SetPictureSize(pictureBoxBulldozer.Width, pictureBoxBulldozer.Height);
_drawningBulldozerProstoy.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 ButtonCreateBulldozer_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningBulldozer));
/// <summary>
/// Обработка нажатия кнопки "Создать обычный бульдозер"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonCreateBulldozerProstoy_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningTrackedMachine));
/// <summary>
/// Перемещение объекта по форме (нажатие кнопок навигации)
/// </summary>
@ -97,7 +70,7 @@ namespace ProjectBulldozer
/// <param name="e"></param>
private void ButtonMove_Click(object sender, EventArgs e)
{
if (_drawningBulldozerProstoy == null)
if (_drawningTrackedMachine == null)
{
return;
}
@ -107,19 +80,19 @@ namespace ProjectBulldozer
{
case "buttonUp":
result =
_drawningBulldozerProstoy.MoveTransport(DirectionType.Up);
_drawningTrackedMachine.MoveTransport(DirectionType.Up);
break;
case "buttonDown":
result =
_drawningBulldozerProstoy.MoveTransport(DirectionType.Down);
_drawningTrackedMachine.MoveTransport(DirectionType.Down);
break;
case "buttonLeft":
result =
_drawningBulldozerProstoy.MoveTransport(DirectionType.Left);
_drawningTrackedMachine.MoveTransport(DirectionType.Left);
break;
case "buttonRight":
result =
_drawningBulldozerProstoy.MoveTransport(DirectionType.Right);
_drawningTrackedMachine.MoveTransport(DirectionType.Right);
break;
}
if (result)
@ -130,7 +103,7 @@ namespace ProjectBulldozer
private void ButtonStrategyStep_Click(object sender, EventArgs e)
{
if (_drawningBulldozerProstoy == null)
if (_drawningTrackedMachine == null)
{
return;
}
@ -147,7 +120,7 @@ namespace ProjectBulldozer
{
return;
}
_strategy.SetData(new MoveableBulldozer(_drawningBulldozerProstoy),
_strategy.SetData(new MoveableBulldozer(_drawningTrackedMachine),
pictureBoxBulldozer.Width, pictureBoxBulldozer.Height);
}

View File

@ -0,0 +1,174 @@
namespace ProjectBulldozer
{
partial class FormMachineCollectoin
{
/// <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();
maskedTextBox = new MaskedTextBox();
comboBoxSelectorCompany = new ComboBox();
buttonGoToCheck = new Button();
buttonRemoveMachine = new Button();
buttonAddBulldozer = new Button();
buttonAddMachine = new Button();
pictureBox = new PictureBox();
groupBoxTools.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
SuspendLayout();
//
// groupBoxTools
//
groupBoxTools.Controls.Add(buttonRefresh);
groupBoxTools.Controls.Add(maskedTextBox);
groupBoxTools.Controls.Add(comboBoxSelectorCompany);
groupBoxTools.Controls.Add(buttonGoToCheck);
groupBoxTools.Controls.Add(buttonRemoveMachine);
groupBoxTools.Controls.Add(buttonAddBulldozer);
groupBoxTools.Controls.Add(buttonAddMachine);
groupBoxTools.Dock = DockStyle.Right;
groupBoxTools.Location = new Point(742, 0);
groupBoxTools.Name = "groupBoxTools";
groupBoxTools.Size = new Size(200, 583);
groupBoxTools.TabIndex = 0;
groupBoxTools.TabStop = false;
groupBoxTools.Text = "Инструменты";
//
// buttonRefresh
//
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonRefresh.Location = new Point(6, 435);
buttonRefresh.Name = "buttonRefresh";
buttonRefresh.Size = new Size(188, 51);
buttonRefresh.TabIndex = 6;
buttonRefresh.Text = "Обновить";
buttonRefresh.UseVisualStyleBackColor = true;
buttonRefresh.Click += ButtonRefresh_Click;
//
// maskedTextBox
//
maskedTextBox.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
maskedTextBox.Location = new Point(6, 227);
maskedTextBox.Mask = "00";
maskedTextBox.Name = "maskedTextBox";
maskedTextBox.Size = new Size(188, 27);
maskedTextBox.TabIndex = 5;
maskedTextBox.ValidatingType = typeof(int);
//
// 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(6, 26);
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
comboBoxSelectorCompany.Size = new Size(188, 28);
comboBoxSelectorCompany.TabIndex = 4;
comboBoxSelectorCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged;
//
// buttonGoToCheck
//
buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonGoToCheck.Location = new Point(6, 349);
buttonGoToCheck.Name = "buttonGoToCheck";
buttonGoToCheck.Size = new Size(188, 51);
buttonGoToCheck.TabIndex = 3;
buttonGoToCheck.Text = "Передать на тесты";
buttonGoToCheck.UseVisualStyleBackColor = true;
buttonGoToCheck.Click += ButtonGoToCheck_Click;
//
// buttonRemoveMachine
//
buttonRemoveMachine.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonRemoveMachine.Location = new Point(6, 260);
buttonRemoveMachine.Name = "buttonRemoveMachine";
buttonRemoveMachine.Size = new Size(188, 51);
buttonRemoveMachine.TabIndex = 2;
buttonRemoveMachine.Text = "Удалить машину";
buttonRemoveMachine.UseVisualStyleBackColor = true;
buttonRemoveMachine.Click += ButtonRemoveMachine_Click;
//
// buttonAddBulldozer
//
buttonAddBulldozer.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonAddBulldozer.Location = new Point(6, 135);
buttonAddBulldozer.Name = "buttonAddBulldozer";
buttonAddBulldozer.Size = new Size(188, 51);
buttonAddBulldozer.TabIndex = 1;
buttonAddBulldozer.Text = "Добавление бульдозера";
buttonAddBulldozer.UseVisualStyleBackColor = true;
buttonAddBulldozer.Click += ButtonAddBulldozer_Click;
//
// buttonAddMachine
//
buttonAddMachine.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonAddMachine.Location = new Point(6, 78);
buttonAddMachine.Name = "buttonAddMachine";
buttonAddMachine.Size = new Size(188, 51);
buttonAddMachine.TabIndex = 0;
buttonAddMachine.Text = "Добавление гусеничной машины";
buttonAddMachine.UseVisualStyleBackColor = true;
buttonAddMachine.Click += ButtonAddMachine_Click;
//
// pictureBox
//
pictureBox.Dock = DockStyle.Fill;
pictureBox.Location = new Point(0, 0);
pictureBox.Name = "pictureBox";
pictureBox.Size = new Size(742, 583);
pictureBox.TabIndex = 5;
pictureBox.TabStop = false;
//
// FormMachineCollectoin
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(942, 583);
Controls.Add(pictureBox);
Controls.Add(groupBoxTools);
Name = "FormMachineCollectoin";
Text = "Коллекция машин";
groupBoxTools.ResumeLayout(false);
groupBoxTools.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
ResumeLayout(false);
}
#endregion
private GroupBox groupBoxTools;
private ComboBox comboBoxSelectorCompany;
private Button buttonGoToCheck;
private Button buttonRemoveMachine;
private Button buttonAddBulldozer;
private Button buttonAddMachine;
private MaskedTextBox maskedTextBox;
private PictureBox pictureBox;
private Button buttonRefresh;
}
}

View File

@ -0,0 +1,206 @@
using ProjectBulldozer.CollectionGenericObjects;
using ProjectBulldozer.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 ProjectBulldozer;
/// <summary>
/// Форма работы с компанией и ее коллекцией
/// </summary
public partial class FormMachineCollectoin : Form
{
/// <summary>
/// Компания
/// </summary>
private AbstractCompany? _company = null;
/// <summary>
/// Конструктор
/// </summary>
public FormMachineCollectoin()
{
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 Garage(pictureBox.Width,
pictureBox.Height, new MassiveGenericObjects<DrawningTrackedMachine>());
break;
}
}
/// <summary>
/// создеание объекта класса-перемещения
/// </summary>
/// <param name="type">Тип создаваемого объекта</param>
private void CreateObject(string type)
{
if (_company == null)
{
return;
}
Random random = new();
DrawningTrackedMachine drawningTrackedMachine;
switch (type)
{
case nameof(DrawningTrackedMachine):
drawningTrackedMachine = new DrawningTrackedMachine(random.Next(100, 300), random.Next(1000, 3000), GetColor(random));
break;
case nameof(DrawningBulldozer):
drawningTrackedMachine = new DrawningBulldozer(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 + drawningTrackedMachine >= 0)
{
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 ButtonAddMachine_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningTrackedMachine));
/// <summary>
/// Добавление бульдозера
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonAddBulldozer_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningBulldozer));
/// <summary>
/// Удаление объекта
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonRemoveMachine_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("Не удалось удалить объект");
}
}
/// <summary>
/// Передача объекта в другую форму
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonGoToCheck_Click(object sender, EventArgs e)
{
if (_company == null)
{
return;
}
DrawningTrackedMachine? trackedMachine = null;
int counter = 100;
while (trackedMachine == null)
{
trackedMachine = _company.GetRandomObject();
counter--;
if (counter <= 0)
{
break;
}
}
if (trackedMachine == null)
{
return;
}
FormBulldozer form = new()
{
SetTrackedMachine = trackedMachine
};
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();
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -11,7 +11,7 @@ namespace ProjectBulldozer
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.Run(new FormBulldozer());
Application.Run(new FormMachineCollectoin());
}
}
}