Lab_3_Kryukov_AI_Excavator
This commit is contained in:
parent
c42834e908
commit
a75dd9c18d
@ -1,4 +1,5 @@
|
||||
using ProjectExcavator.Entities;
|
||||
using ProjectExcavator.MovementStrategy;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@ -13,6 +14,11 @@ namespace ProjectExcavator.DrawningObjects
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntityExcavator? EntityExcavator { get; protected set; }
|
||||
/// <summary>
|
||||
/// Получение объекта IMoveableObject из объекта DrawningCar
|
||||
/// </summary>
|
||||
public IMoveableObject GetMoveableObject => new DrawningObjectExcavator(this);
|
||||
|
||||
/// <summary>
|
||||
/// Ширина окна
|
||||
/// </summary>
|
||||
@ -169,7 +175,7 @@ namespace ProjectExcavator.DrawningObjects
|
||||
}
|
||||
Pen pen = new(Color.Black);
|
||||
//корпус
|
||||
Brush bodyBrush = new SolidBrush(Color.Red);
|
||||
Brush bodyBrush = new SolidBrush(Color.Aqua);
|
||||
g.FillRectangle(bodyBrush, _startPosX + 20, _startPosY + 60, 130, 20);
|
||||
g.FillRectangle(bodyBrush, _startPosX + 100, _startPosY + 20, 30, 40);
|
||||
g.FillRectangle(bodyBrush, _startPosX + 30, _startPosY + 40, 10, 20);
|
||||
|
@ -37,6 +37,7 @@
|
||||
comboBoxStrategy = new ComboBox();
|
||||
buttonCreateExcavatorBodyKits = new Button();
|
||||
buttonStep = new Button();
|
||||
buttonSelectObject = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxExcavator).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
@ -44,9 +45,8 @@
|
||||
//
|
||||
pictureBoxExcavator.Dock = DockStyle.Fill;
|
||||
pictureBoxExcavator.Location = new Point(0, 0);
|
||||
pictureBoxExcavator.Margin = new Padding(3, 4, 3, 4);
|
||||
pictureBoxExcavator.Name = "pictureBoxExcavator";
|
||||
pictureBoxExcavator.Size = new Size(914, 600);
|
||||
pictureBoxExcavator.Size = new Size(800, 450);
|
||||
pictureBoxExcavator.SizeMode = PictureBoxSizeMode.AutoSize;
|
||||
pictureBoxExcavator.TabIndex = 0;
|
||||
pictureBoxExcavator.TabStop = false;
|
||||
@ -54,10 +54,9 @@
|
||||
// buttonCreate
|
||||
//
|
||||
buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreate.Location = new Point(14, 529);
|
||||
buttonCreate.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonCreate.Location = new Point(12, 397);
|
||||
buttonCreate.Name = "buttonCreate";
|
||||
buttonCreate.Size = new Size(177, 55);
|
||||
buttonCreate.Size = new Size(155, 41);
|
||||
buttonCreate.TabIndex = 1;
|
||||
buttonCreate.Text = "Создать простой экскаватор";
|
||||
buttonCreate.UseVisualStyleBackColor = true;
|
||||
@ -68,10 +67,9 @@
|
||||
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonDown.BackgroundImage = Properties.Resources.down;
|
||||
buttonDown.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
buttonDown.Location = new Point(825, 553);
|
||||
buttonDown.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonDown.Location = new Point(722, 415);
|
||||
buttonDown.Name = "buttonDown";
|
||||
buttonDown.Size = new Size(34, 40);
|
||||
buttonDown.Size = new Size(30, 30);
|
||||
buttonDown.TabIndex = 2;
|
||||
buttonDown.UseVisualStyleBackColor = true;
|
||||
buttonDown.Click += buttonMove_Click;
|
||||
@ -81,10 +79,9 @@
|
||||
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonUp.BackgroundImage = Properties.Resources.up;
|
||||
buttonUp.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
buttonUp.Location = new Point(825, 505);
|
||||
buttonUp.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonUp.Location = new Point(722, 379);
|
||||
buttonUp.Name = "buttonUp";
|
||||
buttonUp.Size = new Size(34, 40);
|
||||
buttonUp.Size = new Size(30, 30);
|
||||
buttonUp.TabIndex = 3;
|
||||
buttonUp.UseVisualStyleBackColor = true;
|
||||
buttonUp.Click += buttonMove_Click;
|
||||
@ -94,10 +91,9 @@
|
||||
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonLeft.BackgroundImage = Properties.Resources.left;
|
||||
buttonLeft.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
buttonLeft.Location = new Point(784, 553);
|
||||
buttonLeft.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonLeft.Location = new Point(686, 415);
|
||||
buttonLeft.Name = "buttonLeft";
|
||||
buttonLeft.Size = new Size(34, 40);
|
||||
buttonLeft.Size = new Size(30, 30);
|
||||
buttonLeft.TabIndex = 4;
|
||||
buttonLeft.UseVisualStyleBackColor = true;
|
||||
buttonLeft.Click += buttonMove_Click;
|
||||
@ -107,10 +103,9 @@
|
||||
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonRight.BackgroundImage = Properties.Resources.right;
|
||||
buttonRight.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
buttonRight.Location = new Point(866, 553);
|
||||
buttonRight.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonRight.Location = new Point(758, 415);
|
||||
buttonRight.Name = "buttonRight";
|
||||
buttonRight.Size = new Size(34, 40);
|
||||
buttonRight.Size = new Size(30, 30);
|
||||
buttonRight.TabIndex = 5;
|
||||
buttonRight.UseVisualStyleBackColor = true;
|
||||
buttonRight.Click += buttonMove_Click;
|
||||
@ -120,18 +115,16 @@
|
||||
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBoxStrategy.FormattingEnabled = true;
|
||||
comboBoxStrategy.Items.AddRange(new object[] { "Двигаться в центр", "Двигаться к краю экрана" });
|
||||
comboBoxStrategy.Location = new Point(762, 16);
|
||||
comboBoxStrategy.Margin = new Padding(3, 4, 3, 4);
|
||||
comboBoxStrategy.Location = new Point(667, 12);
|
||||
comboBoxStrategy.Name = "comboBoxStrategy";
|
||||
comboBoxStrategy.Size = new Size(138, 28);
|
||||
comboBoxStrategy.Size = new Size(121, 23);
|
||||
comboBoxStrategy.TabIndex = 6;
|
||||
//
|
||||
// buttonCreateExcavatorBodyKits
|
||||
//
|
||||
buttonCreateExcavatorBodyKits.Location = new Point(198, 529);
|
||||
buttonCreateExcavatorBodyKits.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonCreateExcavatorBodyKits.Location = new Point(173, 397);
|
||||
buttonCreateExcavatorBodyKits.Name = "buttonCreateExcavatorBodyKits";
|
||||
buttonCreateExcavatorBodyKits.Size = new Size(166, 55);
|
||||
buttonCreateExcavatorBodyKits.Size = new Size(145, 41);
|
||||
buttonCreateExcavatorBodyKits.TabIndex = 7;
|
||||
buttonCreateExcavatorBodyKits.Text = "Создать Экскаватор с обвесами";
|
||||
buttonCreateExcavatorBodyKits.UseVisualStyleBackColor = true;
|
||||
@ -139,20 +132,30 @@
|
||||
//
|
||||
// buttonStep
|
||||
//
|
||||
buttonStep.Location = new Point(815, 55);
|
||||
buttonStep.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonStep.Location = new Point(713, 41);
|
||||
buttonStep.Name = "buttonStep";
|
||||
buttonStep.Size = new Size(86, 31);
|
||||
buttonStep.Size = new Size(75, 23);
|
||||
buttonStep.TabIndex = 8;
|
||||
buttonStep.Text = "Шаг";
|
||||
buttonStep.UseVisualStyleBackColor = true;
|
||||
buttonStep.Click += buttonStep_Click;
|
||||
//
|
||||
// buttonSelectObject
|
||||
//
|
||||
buttonSelectObject.Location = new Point(713, 70);
|
||||
buttonSelectObject.Name = "buttonSelectObject";
|
||||
buttonSelectObject.Size = new Size(75, 23);
|
||||
buttonSelectObject.TabIndex = 9;
|
||||
buttonSelectObject.Text = "Выбрать объект";
|
||||
buttonSelectObject.UseVisualStyleBackColor = true;
|
||||
buttonSelectObject.Click += buttonSelectObject_Click;
|
||||
//
|
||||
// ExcavatorForm
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(914, 600);
|
||||
ClientSize = new Size(800, 450);
|
||||
Controls.Add(buttonSelectObject);
|
||||
Controls.Add(buttonStep);
|
||||
Controls.Add(buttonCreateExcavatorBodyKits);
|
||||
Controls.Add(comboBoxStrategy);
|
||||
@ -162,7 +165,6 @@
|
||||
Controls.Add(buttonDown);
|
||||
Controls.Add(buttonCreate);
|
||||
Controls.Add(pictureBoxExcavator);
|
||||
Margin = new Padding(3, 4, 3, 4);
|
||||
Name = "ExcavatorForm";
|
||||
Text = "Excavator";
|
||||
Click += buttonMove_Click;
|
||||
@ -182,5 +184,6 @@
|
||||
private ComboBox comboBoxStrategy;
|
||||
private Button buttonCreateExcavatorBodyKits;
|
||||
private Button buttonStep;
|
||||
private Button buttonSelectObject;
|
||||
}
|
||||
}
|
@ -13,12 +13,15 @@ namespace ProjectExcavator
|
||||
/// Ñòðàòåãèÿ ïåðåìåùåíèÿ
|
||||
/// </summary>
|
||||
private AbstractStrategy? _abstractStrategy;
|
||||
public DrawningExcavator? SelectedExcavator { get; private set; }
|
||||
/// <summary>
|
||||
/// Èíèöèàëèçàöèÿ ôîðìû
|
||||
/// </summary>
|
||||
public ExcavatorForm()
|
||||
{
|
||||
InitializeComponent();
|
||||
_drawnigExcavator = null;
|
||||
_abstractStrategy = null;
|
||||
}
|
||||
/// <summary>
|
||||
/// Ìåòîä ïðîðèñîâêè ìàøèíû
|
||||
@ -84,12 +87,24 @@ namespace ProjectExcavator
|
||||
private void buttonCreateExcavatorBodyKits_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
ColorDialog mainDialog = new ColorDialog();
|
||||
if (mainDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
color = mainDialog.Color;
|
||||
}
|
||||
Color dopcolor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
|
||||
ColorDialog dopDialog = new ColorDialog();
|
||||
if (dopDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
dopcolor = dopDialog.Color;
|
||||
}
|
||||
_drawnigExcavator = new DrawningExcavarorBodyKits(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)),
|
||||
color,
|
||||
dopcolor,
|
||||
true,
|
||||
true,
|
||||
pictureBoxExcavator.Width,
|
||||
pictureBoxExcavator.Height);
|
||||
_drawnigExcavator.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
@ -131,5 +146,10 @@ namespace ProjectExcavator
|
||||
_abstractStrategy = null;
|
||||
}
|
||||
}
|
||||
private void buttonSelectObject_Click(object sender, EventArgs e)
|
||||
{
|
||||
SelectedExcavator = _drawnigExcavator;
|
||||
DialogResult = DialogResult.OK;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,94 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ProjectExcavator.MovementStrategy;
|
||||
using ProjectExcavator.DrawningObjects;
|
||||
using ProjectExcavator.Generic;
|
||||
|
||||
namespace ProjectExcavator.Generic
|
||||
{
|
||||
internal class ExcavatorGenericCollection<T, U>
|
||||
where T : DrawningExcavator
|
||||
where U : IMoveableObject
|
||||
{
|
||||
private readonly int _pictureWidth;
|
||||
private readonly int _pictureHeight;
|
||||
private readonly int _placeSizeWidth = 210;
|
||||
private readonly int _placeSizeHeight = 110;
|
||||
private readonly SetGeneric<T> _collection;
|
||||
public ExcavatorGenericCollection(int picWidth, int picHeight)
|
||||
{
|
||||
int width = picWidth / _placeSizeWidth;
|
||||
int height = picHeight / _placeSizeHeight;
|
||||
_pictureWidth = picWidth;
|
||||
_pictureHeight = picHeight;
|
||||
_collection = new SetGeneric<T>(width * height);
|
||||
}
|
||||
public static bool operator +(ExcavatorGenericCollection<T, U> collect, T? obj)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return collect?._collection.Insert(obj) ?? false;
|
||||
}
|
||||
public static T? operator -(ExcavatorGenericCollection<T, U> collect, int pos)
|
||||
{
|
||||
T? obj = collect._collection.Get(pos);
|
||||
if (obj != null)
|
||||
{
|
||||
collect._collection.Remove(pos);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
public U? GetU(int pos) => (U)_collection.Get(pos)?.GetMoveableObject;
|
||||
/// <summary>
|
||||
/// Вывод всего набора объектов
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Bitmap ShowExcavator()
|
||||
{
|
||||
Bitmap bmp = new(_pictureWidth, _pictureHeight);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
DrawBackground(gr);
|
||||
DrawObjects(gr);
|
||||
return bmp;
|
||||
}
|
||||
private void DrawBackground(Graphics g)
|
||||
{
|
||||
Pen pen = new(Color.Black, 3);
|
||||
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
|
||||
{
|
||||
for (int j = 0; j < _pictureHeight / _placeSizeHeight; j++)
|
||||
{
|
||||
g.DrawLine(pen, i * i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight);
|
||||
}
|
||||
g.DrawLine(pen, i * _placeSizeWidth, 0, i *
|
||||
_placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
|
||||
}
|
||||
}
|
||||
private void DrawObjects(Graphics g)
|
||||
{
|
||||
for(int i = 0; i < _collection.Count;i++)
|
||||
{
|
||||
T t = _collection.Get(i);
|
||||
if(t != null)
|
||||
{
|
||||
t.SetPosition((i % (_pictureWidth / _placeSizeWidth)) * _placeSizeWidth, (i / (_pictureWidth / _placeSizeWidth)) * _placeSizeHeight);
|
||||
if (t is DrawningExcavator)
|
||||
{
|
||||
//тут преведение избыточно
|
||||
t.DrawTransport(g);
|
||||
}
|
||||
else
|
||||
{
|
||||
t.DrawTransport(g);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
109
ProjectExcavator/ProjectExcavator/FormExcavatorCollection.Designer.cs
generated
Normal file
109
ProjectExcavator/ProjectExcavator/FormExcavatorCollection.Designer.cs
generated
Normal file
@ -0,0 +1,109 @@
|
||||
namespace ProjectExcavator
|
||||
{
|
||||
partial class FormExcavatorCollection
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
pictureBoxCollection = new PictureBox();
|
||||
buttonAddExcavator = new Button();
|
||||
maskedTextBoxNumber = new MaskedTextBox();
|
||||
buttonRemoveExcavator = new Button();
|
||||
buttonRefreshCollection = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// pictureBoxCollection
|
||||
//
|
||||
pictureBoxCollection.Location = new Point(0, 0);
|
||||
pictureBoxCollection.Name = "pictureBoxCollection";
|
||||
pictureBoxCollection.Size = new Size(617, 450);
|
||||
pictureBoxCollection.TabIndex = 0;
|
||||
pictureBoxCollection.TabStop = false;
|
||||
//
|
||||
// buttonAddExcavator
|
||||
//
|
||||
buttonAddExcavator.Location = new Point(623, 26);
|
||||
buttonAddExcavator.Name = "buttonAddExcavator";
|
||||
buttonAddExcavator.Size = new Size(174, 51);
|
||||
buttonAddExcavator.TabIndex = 1;
|
||||
buttonAddExcavator.Text = "Добавить экскавотор";
|
||||
buttonAddExcavator.UseVisualStyleBackColor = true;
|
||||
buttonAddExcavator.Click += buttonAddExcavator_Click;
|
||||
//
|
||||
// maskedTextBoxNumber
|
||||
//
|
||||
maskedTextBoxNumber.Location = new Point(623, 83);
|
||||
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||
maskedTextBoxNumber.Size = new Size(174, 23);
|
||||
maskedTextBoxNumber.TabIndex = 2;
|
||||
//
|
||||
// buttonRemoveExcavator
|
||||
//
|
||||
buttonRemoveExcavator.Location = new Point(623, 128);
|
||||
buttonRemoveExcavator.Name = "buttonRemoveExcavator";
|
||||
buttonRemoveExcavator.Size = new Size(174, 38);
|
||||
buttonRemoveExcavator.TabIndex = 3;
|
||||
buttonRemoveExcavator.Text = "Удалить объект";
|
||||
buttonRemoveExcavator.UseVisualStyleBackColor = true;
|
||||
buttonRemoveExcavator.Click += buttonRemoveExcavator_Click;
|
||||
//
|
||||
// buttonRefreshCollection
|
||||
//
|
||||
buttonRefreshCollection.Location = new Point(625, 172);
|
||||
buttonRefreshCollection.Name = "buttonRefreshCollection";
|
||||
buttonRefreshCollection.Size = new Size(172, 33);
|
||||
buttonRefreshCollection.TabIndex = 4;
|
||||
buttonRefreshCollection.Text = "Обновить коллекцию";
|
||||
buttonRefreshCollection.UseVisualStyleBackColor = true;
|
||||
buttonRefreshCollection.Click += buttonRefreshCollection_Click;
|
||||
//
|
||||
// FormExcavatorCollection
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(800, 450);
|
||||
Controls.Add(buttonRefreshCollection);
|
||||
Controls.Add(buttonRemoveExcavator);
|
||||
Controls.Add(maskedTextBoxNumber);
|
||||
Controls.Add(buttonAddExcavator);
|
||||
Controls.Add(pictureBoxCollection);
|
||||
Name = "FormExcavatorCollection";
|
||||
Text = "Набор экскаваторов";
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private PictureBox pictureBoxCollection;
|
||||
private Button buttonAddExcavator;
|
||||
private MaskedTextBox maskedTextBoxNumber;
|
||||
private Button buttonRemoveExcavator;
|
||||
private Button buttonRefreshCollection;
|
||||
}
|
||||
}
|
64
ProjectExcavator/ProjectExcavator/FormExcavatorCollection.cs
Normal file
64
ProjectExcavator/ProjectExcavator/FormExcavatorCollection.cs
Normal file
@ -0,0 +1,64 @@
|
||||
using ProjectExcavator.DrawningObjects;
|
||||
using ProjectExcavator.Generic;
|
||||
using ProjectExcavator.MovementStrategy;
|
||||
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 ProjectExcavator
|
||||
{
|
||||
public partial class FormExcavatorCollection : Form
|
||||
{
|
||||
private readonly ExcavatorGenericCollection<DrawningExcavator, DrawningObjectExcavator> _excavators;
|
||||
|
||||
public FormExcavatorCollection()
|
||||
{
|
||||
InitializeComponent();
|
||||
_excavators = new ExcavatorGenericCollection<DrawningExcavator, DrawningObjectExcavator>(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
||||
}
|
||||
private void buttonAddExcavator_Click(object sender, EventArgs e)
|
||||
{
|
||||
ExcavatorForm form = new();
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (_excavators + form.SelectedExcavator)
|
||||
{
|
||||
MessageBox.Show("Объект добален");
|
||||
pictureBoxCollection.Image = _excavators.ShowExcavator();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось добавить новый обьект");
|
||||
}
|
||||
}
|
||||
}
|
||||
private void buttonRemoveExcavator_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (MessageBox.Show("Удалить объект?", "Удаление...", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
||||
if(_excavators - pos != null)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBoxCollection.Image = _excavators.ShowExcavator();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось удалить обхект");
|
||||
}
|
||||
|
||||
}
|
||||
private void buttonRefreshCollection_Click(object sender, EventArgs e)
|
||||
{
|
||||
pictureBoxCollection.Image = _excavators.ShowExcavator();
|
||||
}
|
||||
}
|
||||
}
|
120
ProjectExcavator/ProjectExcavator/FormExcavatorCollection.resx
Normal file
120
ProjectExcavator/ProjectExcavator/FormExcavatorCollection.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>
|
@ -11,7 +11,7 @@ namespace ProjectExcavator
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new ExcavatorForm());
|
||||
Application.Run(new FormExcavatorCollection());
|
||||
}
|
||||
}
|
||||
}
|
72
ProjectExcavator/ProjectExcavator/SetGeneric.cs
Normal file
72
ProjectExcavator/ProjectExcavator/SetGeneric.cs
Normal file
@ -0,0 +1,72 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectExcavator
|
||||
{
|
||||
internal class SetGeneric<T>
|
||||
where T : class
|
||||
{
|
||||
private readonly T?[] _places;
|
||||
public int Count => _places.Length;
|
||||
public SetGeneric(int count)
|
||||
{
|
||||
_places = new T?[count];
|
||||
}
|
||||
public bool Insert(T excavator)
|
||||
{
|
||||
int i = 0;
|
||||
for (; i < _places.Length; i++)
|
||||
{
|
||||
if (_places[i] == null)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i == _places.Length)
|
||||
return false;
|
||||
for (; i > 0; i--)
|
||||
{
|
||||
_places[i] = _places[i - 1];
|
||||
}
|
||||
_places[i] = excavator;
|
||||
return true;
|
||||
}
|
||||
public bool Insert(T excavator, int position)
|
||||
{
|
||||
if (position < 0 || position >= _places.Length)
|
||||
return false;
|
||||
for (; position < _places.Length; position++)
|
||||
{
|
||||
if (_places[position] == null)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (position == _places.Length)
|
||||
return false;
|
||||
for (; position > 0; position--)
|
||||
{
|
||||
_places[position] = _places[position - 1];
|
||||
}
|
||||
_places[position] = excavator;
|
||||
return true;
|
||||
}
|
||||
public bool Remove(int position) {
|
||||
if (position >= _places.Length || position<0)
|
||||
return false;
|
||||
_places[position] = null;
|
||||
return true;
|
||||
}
|
||||
public T? Get(int position)
|
||||
{
|
||||
if(position >= _places.Length || position < 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return _places[position];
|
||||
}
|
||||
}
|
||||
}
|
@ -8,8 +8,8 @@ namespace ProjectExcavator
|
||||
{
|
||||
public enum Status
|
||||
{
|
||||
NotInit = 0,
|
||||
InProgress = 1,
|
||||
Finish = 2
|
||||
NotInit ,
|
||||
InProgress,
|
||||
Finish
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user