PIbd-23 Firsov Kirill LabWork 04 #23
@ -4,6 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ProjectTractor.Entities;
|
||||
using ProjectTractor.MovementStrategy;
|
||||
|
||||
namespace ProjectTractor.DrawningObjects {
|
||||
|
||||
@ -79,6 +80,12 @@ namespace ProjectTractor.DrawningObjects {
|
||||
EntityTractor = new EntityTractor(speed, weight, bodyColor);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получение объекта IMoveableObject из объекта DrawningTractor
|
||||
/// </summary>
|
||||
public IMoveableObject GetMoveableObject => new
|
||||
DrawningObjectTractor(this);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Координата X объекта
|
||||
|
@ -20,30 +20,28 @@ namespace ProjectTractor
|
||||
private ComboBox comboBoxStrategy;
|
||||
private Button buttonRight;
|
||||
|
||||
/// <summary>
|
||||
/// Ñòðàòåãèÿ ïåðåìåùåíèÿ
|
||||
/// </summary>
|
||||
private AbstractStrategy? _abstractStrategy;
|
||||
|
||||
public int getPictureWidth()
|
||||
{
|
||||
return pictureBoxTractor.Width;
|
||||
}
|
||||
public int getPictureHeight()
|
||||
{
|
||||
return pictureBoxTractor.Height;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ïîëå-îáúåêò äëÿ ïðîðèñîâêè îáúåêòà
|
||||
/// </summary>
|
||||
private DrawningTractor? _drawningTractor;
|
||||
private Button ButtonSelectTractor;
|
||||
|
||||
/// <summary>
|
||||
/// Ñòðàòåãèÿ ïåðåìåùåíèÿ
|
||||
/// </summary>
|
||||
private AbstractStrategy? _strategy;
|
||||
/// <summary>
|
||||
/// Âûáðàííûé àâòîìîáèëü
|
||||
/// </summary>
|
||||
public DrawningTractor? SelectedTractor { get; private set; }
|
||||
/// <summary>
|
||||
/// Èíèöèàëèçàöèÿ ôîðìû
|
||||
/// </summary>
|
||||
public FormTractor()
|
||||
{
|
||||
InitializeComponent();
|
||||
_strategy = null;
|
||||
SelectedTractor = null;
|
||||
}
|
||||
/// <summary>
|
||||
/// Ìåòîä ïðîðèñîâêè ìàøèíû
|
||||
@ -60,24 +58,6 @@ namespace ProjectTractor
|
||||
_drawningTractor.DrawTransport(gr);
|
||||
pictureBoxTractor.Image = bmp;
|
||||
}
|
||||
/// <summary>
|
||||
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
_drawningTractor = new DrawningTractor(random.Next(100, 300),
|
||||
random.Next(1000, 3000),
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256),
|
||||
random.Next(0, 256)),
|
||||
pictureBoxTractor.Width, pictureBoxTractor.Height);
|
||||
_drawningTractor.SetPosition(random.Next(10, 100),
|
||||
random.Next(10, 100));
|
||||
Draw();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Èçìåíåíèå ðàçìåðîâ ôîðìû
|
||||
/// </summary>
|
||||
@ -92,7 +72,7 @@ namespace ProjectTractor
|
||||
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||
switch (name)
|
||||
{
|
||||
case "buttonTop":
|
||||
case "buttonUp":
|
||||
_drawningTractor.MoveTransport(DirectionType.Up);
|
||||
break;
|
||||
case "buttonDown":
|
||||
@ -107,6 +87,76 @@ namespace ProjectTractor
|
||||
}
|
||||
Draw();
|
||||
}
|
||||
/// <summary>
|
||||
/// Ñîçäàíèå ïðîñòîãî àâòîìîáèëÿ
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonCreate_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 dialog = new();
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
color = dialog.Color;
|
||||
}
|
||||
_drawningTractor = new DrawningTractor(random.Next(100, 300),
|
||||
random.Next(1000, 3000), color,
|
||||
pictureBoxTractor.Width, pictureBoxTractor.Height);
|
||||
_drawningTractor.SetPosition(random.Next(10, 100), random.Next(10,
|
||||
100));
|
||||
Draw();
|
||||
}
|
||||
/// <summary>
|
||||
/// Øàã ñòðàòåãèè ïåðåìåùåíèÿ
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonStartegyStep_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawningTractor == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (comboBoxStrategy.Enabled)
|
||||
{
|
||||
_strategy = comboBoxStrategy.SelectedIndex switch
|
||||
{
|
||||
0 => new MoveToCenter(),
|
||||
1 => new MoveToBorder(),
|
||||
_ => null,
|
||||
};
|
||||
if (_strategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_strategy.SetData(_drawningTractor.GetMoveableObject,
|
||||
pictureBoxTractor.Width, pictureBoxTractor.Height);
|
||||
}
|
||||
if (_strategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
comboBoxStrategy.Enabled = false;
|
||||
_strategy.MakeStep();
|
||||
Draw();
|
||||
if (_strategy.GetStatus() == Status.Finish)
|
||||
{
|
||||
comboBoxStrategy.Enabled = true;
|
||||
_strategy = null;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Âûáîð àâòîìîáèëÿ
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonSelectTractor_Click(object sender, EventArgs e)
|
||||
{
|
||||
SelectedTractor = _drawningTractor;
|
||||
DialogResult = DialogResult.OK;
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
@ -119,6 +169,7 @@ namespace ProjectTractor
|
||||
this.buttonCreateBulldoserTractor = new System.Windows.Forms.Button();
|
||||
this.buttonStep = new System.Windows.Forms.Button();
|
||||
this.comboBoxStrategy = new System.Windows.Forms.ComboBox();
|
||||
this.ButtonSelectTractor = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxTractor)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
@ -226,9 +277,21 @@ namespace ProjectTractor
|
||||
this.comboBoxStrategy.Size = new System.Drawing.Size(151, 28);
|
||||
this.comboBoxStrategy.TabIndex = 8;
|
||||
//
|
||||
// ButtonSelectTractor
|
||||
//
|
||||
this.ButtonSelectTractor.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.ButtonSelectTractor.Location = new System.Drawing.Point(469, 403);
|
||||
this.ButtonSelectTractor.Name = "ButtonSelectTractor";
|
||||
this.ButtonSelectTractor.Size = new System.Drawing.Size(199, 29);
|
||||
this.ButtonSelectTractor.TabIndex = 9;
|
||||
this.ButtonSelectTractor.Text = "Âûáðàòü òðàêòîð";
|
||||
this.ButtonSelectTractor.UseVisualStyleBackColor = true;
|
||||
this.ButtonSelectTractor.Click += new System.EventHandler(this.ButtonSelectTractor_Click);
|
||||
//
|
||||
// FormTractor
|
||||
//
|
||||
this.ClientSize = new System.Drawing.Size(882, 453);
|
||||
this.Controls.Add(this.ButtonSelectTractor);
|
||||
this.Controls.Add(this.comboBoxStrategy);
|
||||
this.Controls.Add(this.buttonStep);
|
||||
this.Controls.Add(this.buttonCreateBulldoserTractor);
|
||||
@ -248,19 +311,30 @@ namespace ProjectTractor
|
||||
private void buttonCreateBulldoserTractor_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 dialogColor = new();
|
||||
if (dialogColor.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
color = dialogColor.Color;
|
||||
}
|
||||
Color dopColor = Color.FromArgb(random.Next(0, 256),
|
||||
random.Next(0, 256), random.Next(0, 256));
|
||||
ColorDialog dialogDopColor = new();
|
||||
if (dialogDopColor.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
dopColor = dialogDopColor.Color;
|
||||
}
|
||||
_drawningTractor = new DrawningBulldoser(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)),
|
||||
color,
|
||||
dopColor,
|
||||
Convert.ToBoolean(random.Next(0, 2)),
|
||||
Convert.ToBoolean(random.Next(0, 2)),
|
||||
pictureBoxTractor.Width, pictureBoxTractor.Height);
|
||||
_drawningTractor.SetPosition(random.Next(10, 100), random.Next(10,
|
||||
100));
|
||||
pictureBoxTractor.Width,
|
||||
pictureBoxTractor.Height);
|
||||
_drawningTractor.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
Draw();
|
||||
|
||||
}
|
||||
|
||||
private void buttonStep_Click(object sender, EventArgs e)
|
||||
@ -271,32 +345,32 @@ namespace ProjectTractor
|
||||
}
|
||||
if (comboBoxStrategy.Enabled)
|
||||
{
|
||||
_abstractStrategy = comboBoxStrategy.SelectedIndex
|
||||
_strategy = comboBoxStrategy.SelectedIndex
|
||||
switch
|
||||
{
|
||||
0 => new MoveToCenter(),
|
||||
1 => new MoveToBorder(),
|
||||
_ => null,
|
||||
};
|
||||
if (_abstractStrategy == null)
|
||||
if (_strategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_abstractStrategy.SetData(new
|
||||
_strategy.SetData(new
|
||||
DrawningObjectTractor(_drawningTractor), pictureBoxTractor.Width,
|
||||
pictureBoxTractor.Height);
|
||||
comboBoxStrategy.Enabled = false;
|
||||
}
|
||||
if (_abstractStrategy == null)
|
||||
if (_strategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_abstractStrategy.MakeStep();
|
||||
_strategy.MakeStep();
|
||||
Draw();
|
||||
if (_abstractStrategy.GetStatus() == Status.Finish)
|
||||
if (_strategy.GetStatus() == Status.Finish)
|
||||
{
|
||||
comboBoxStrategy.Enabled = true;
|
||||
_abstractStrategy = null;
|
||||
_strategy = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,345 @@
|
||||
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;
|
||||
using ProjectTractor.DrawningObjects;
|
||||
using ProjectTractor.Generics;
|
||||
using ProjectTractor.MovementStrategy;
|
||||
|
||||
namespace ProjectTractor
|
||||
{
|
||||
public partial class FormTractorCollection : Form
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Набор объектов
|
||||
/// </summary>
|
||||
private readonly TractorsGenericStorage _storage;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
public FormTractorCollection()
|
||||
{
|
||||
InitializeComponent();
|
||||
_storage = new TractorsGenericStorage(pictureBoxCollection.Width,
|
||||
pictureBoxCollection.Height);
|
||||
}
|
||||
/// <summary>
|
||||
/// Заполнение listBoxObjects
|
||||
/// </summary>
|
||||
private void ReloadObjects()
|
||||
{
|
||||
int index = listBoxStorages.SelectedIndex;
|
||||
listBoxStorages.Items.Clear();
|
||||
for (int i = 0; i < _storage.Keys.Count; i++)
|
||||
{
|
||||
listBoxStorages.Items.Add(_storage.Keys[i]);
|
||||
}
|
||||
if (listBoxStorages.Items.Count > 0 && (index == -1 || index
|
||||
>= listBoxStorages.Items.Count))
|
||||
{
|
||||
listBoxStorages.SelectedIndex = 0;
|
||||
}
|
||||
else if (listBoxStorages.Items.Count > 0 && index > -1 &&
|
||||
index < listBoxStorages.Items.Count)
|
||||
{
|
||||
listBoxStorages.SelectedIndex = index;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление набора в коллекцию
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
///
|
||||
private void ButtonAddObject_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(textBoxStorageName.Text))
|
||||
{
|
||||
MessageBox.Show("Не все данные заполнены", "Ошибка",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
_storage.AddSet(textBoxStorageName.Text);
|
||||
ReloadObjects();
|
||||
}
|
||||
/// <summary>
|
||||
/// Выбор набора
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void listBoxStorages_SelectedIndexChanged(object sender,
|
||||
EventArgs e)
|
||||
{
|
||||
pictureBoxCollection.Image =
|
||||
_storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowTractors();
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление набора
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonDelObject_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (MessageBox.Show($"Удалить объект {listBoxStorages.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
{
|
||||
_storage.DelSet(listBoxStorages.SelectedItem.ToString() ?? string.Empty);
|
||||
ReloadObjects();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonAddTractor_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
FormTractor form = new();
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (obj + form.SelectedTractor)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBoxCollection.Image = obj.ShowTractors();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Удаление объекта из набора
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonRemoveTractor_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
|
||||
string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (MessageBox.Show("Удалить объект?", "Удаление",
|
||||
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
||||
if (obj - pos != null)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBoxCollection.Image = obj.ShowTractors();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Обновление рисунка по набору
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
|
||||
string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
pictureBoxCollection.Image = obj.ShowTractors();
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.pictureBoxCollection = new System.Windows.Forms.PictureBox();
|
||||
this.groupBox = new System.Windows.Forms.GroupBox();
|
||||
this.groupBox1 = new System.Windows.Forms.GroupBox();
|
||||
this.ButtonDelObject = new System.Windows.Forms.Button();
|
||||
this.listBoxStorages = new System.Windows.Forms.ListBox();
|
||||
this.ButtonAddObject = new System.Windows.Forms.Button();
|
||||
this.textBoxStorageName = new System.Windows.Forms.MaskedTextBox();
|
||||
this.ButtonRefreshCollection = new System.Windows.Forms.Button();
|
||||
this.ButtonRemoveTractor = new System.Windows.Forms.Button();
|
||||
this.ButtonAddTractor = new System.Windows.Forms.Button();
|
||||
this.maskedTextBoxNumber = new System.Windows.Forms.MaskedTextBox();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).BeginInit();
|
||||
this.groupBox.SuspendLayout();
|
||||
this.groupBox1.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// pictureBoxCollection
|
||||
//
|
||||
this.pictureBoxCollection.Dock = System.Windows.Forms.DockStyle.Left;
|
||||
this.pictureBoxCollection.Location = new System.Drawing.Point(0, 0);
|
||||
this.pictureBoxCollection.Name = "pictureBoxCollection";
|
||||
this.pictureBoxCollection.Size = new System.Drawing.Size(675, 536);
|
||||
this.pictureBoxCollection.TabIndex = 1;
|
||||
this.pictureBoxCollection.TabStop = false;
|
||||
//
|
||||
// groupBox
|
||||
//
|
||||
this.groupBox.Controls.Add(this.groupBox1);
|
||||
this.groupBox.Controls.Add(this.ButtonRefreshCollection);
|
||||
this.groupBox.Controls.Add(this.ButtonRemoveTractor);
|
||||
this.groupBox.Controls.Add(this.ButtonAddTractor);
|
||||
this.groupBox.Controls.Add(this.maskedTextBoxNumber);
|
||||
this.groupBox.Location = new System.Drawing.Point(681, 12);
|
||||
this.groupBox.Name = "groupBox";
|
||||
this.groupBox.Size = new System.Drawing.Size(255, 522);
|
||||
this.groupBox.TabIndex = 2;
|
||||
this.groupBox.TabStop = false;
|
||||
this.groupBox.Text = "Инструменты";
|
||||
//
|
||||
// groupBox1
|
||||
//
|
||||
this.groupBox1.Controls.Add(this.ButtonDelObject);
|
||||
this.groupBox1.Controls.Add(this.listBoxStorages);
|
||||
this.groupBox1.Controls.Add(this.ButtonAddObject);
|
||||
this.groupBox1.Controls.Add(this.textBoxStorageName);
|
||||
this.groupBox1.Location = new System.Drawing.Point(16, 29);
|
||||
this.groupBox1.Name = "groupBox1";
|
||||
this.groupBox1.Size = new System.Drawing.Size(224, 279);
|
||||
this.groupBox1.TabIndex = 9;
|
||||
this.groupBox1.TabStop = false;
|
||||
this.groupBox1.Text = "Наборы";
|
||||
//
|
||||
// ButtonDelObject
|
||||
//
|
||||
this.ButtonDelObject.Location = new System.Drawing.Point(12, 227);
|
||||
this.ButtonDelObject.Name = "ButtonDelObject";
|
||||
this.ButtonDelObject.Size = new System.Drawing.Size(203, 35);
|
||||
this.ButtonDelObject.TabIndex = 3;
|
||||
this.ButtonDelObject.Text = "Удалить набор";
|
||||
this.ButtonDelObject.UseVisualStyleBackColor = true;
|
||||
this.ButtonDelObject.Click += new System.EventHandler(this.ButtonDelObject_Click);
|
||||
//
|
||||
// listBoxStorages
|
||||
//
|
||||
this.listBoxStorages.FormattingEnabled = true;
|
||||
this.listBoxStorages.ItemHeight = 20;
|
||||
this.listBoxStorages.Location = new System.Drawing.Point(12, 116);
|
||||
this.listBoxStorages.Name = "listBoxStorages";
|
||||
this.listBoxStorages.Size = new System.Drawing.Size(203, 84);
|
||||
this.listBoxStorages.TabIndex = 2;
|
||||
this.listBoxStorages.SelectedIndexChanged += new System.EventHandler(this.listBoxStorages_SelectedIndexChanged);
|
||||
//
|
||||
// ButtonAddObject
|
||||
//
|
||||
this.ButtonAddObject.Location = new System.Drawing.Point(12, 59);
|
||||
this.ButtonAddObject.Name = "ButtonAddObject";
|
||||
this.ButtonAddObject.Size = new System.Drawing.Size(203, 29);
|
||||
this.ButtonAddObject.TabIndex = 1;
|
||||
this.ButtonAddObject.Text = "Добавить набор";
|
||||
this.ButtonAddObject.UseVisualStyleBackColor = true;
|
||||
this.ButtonAddObject.Click += new System.EventHandler(this.ButtonAddObject_Click);
|
||||
//
|
||||
// textBoxStorageName
|
||||
//
|
||||
this.textBoxStorageName.Location = new System.Drawing.Point(12, 26);
|
||||
this.textBoxStorageName.Name = "textBoxStorageName";
|
||||
this.textBoxStorageName.Size = new System.Drawing.Size(203, 27);
|
||||
this.textBoxStorageName.TabIndex = 0;
|
||||
//
|
||||
// ButtonRefreshCollection
|
||||
//
|
||||
this.ButtonRefreshCollection.Location = new System.Drawing.Point(28, 464);
|
||||
this.ButtonRefreshCollection.Name = "ButtonRefreshCollection";
|
||||
this.ButtonRefreshCollection.Size = new System.Drawing.Size(203, 35);
|
||||
this.ButtonRefreshCollection.TabIndex = 8;
|
||||
this.ButtonRefreshCollection.Text = "Обновить коллекцию";
|
||||
this.ButtonRefreshCollection.UseVisualStyleBackColor = true;
|
||||
this.ButtonRefreshCollection.Click += new System.EventHandler(this.ButtonRefreshCollection_Click);
|
||||
//
|
||||
// ButtonRemoveTractor
|
||||
//
|
||||
this.ButtonRemoveTractor.Location = new System.Drawing.Point(28, 390);
|
||||
this.ButtonRemoveTractor.Name = "ButtonRemoveTractor";
|
||||
this.ButtonRemoveTractor.Size = new System.Drawing.Size(203, 33);
|
||||
this.ButtonRemoveTractor.TabIndex = 7;
|
||||
this.ButtonRemoveTractor.Text = "Удалить трактор";
|
||||
this.ButtonRemoveTractor.UseVisualStyleBackColor = true;
|
||||
this.ButtonRemoveTractor.Click += new System.EventHandler(this.ButtonRemoveTractor_Click);
|
||||
//
|
||||
// ButtonAddTractor
|
||||
//
|
||||
this.ButtonAddTractor.Location = new System.Drawing.Point(28, 317);
|
||||
this.ButtonAddTractor.Name = "ButtonAddTractor";
|
||||
this.ButtonAddTractor.Size = new System.Drawing.Size(203, 34);
|
||||
this.ButtonAddTractor.TabIndex = 6;
|
||||
this.ButtonAddTractor.Text = "Добавить трактор";
|
||||
this.ButtonAddTractor.UseVisualStyleBackColor = true;
|
||||
this.ButtonAddTractor.Click += new System.EventHandler(this.ButtonAddTractor_Click);
|
||||
//
|
||||
// maskedTextBoxNumber
|
||||
//
|
||||
this.maskedTextBoxNumber.Location = new System.Drawing.Point(28, 357);
|
||||
this.maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||
this.maskedTextBoxNumber.Size = new System.Drawing.Size(203, 27);
|
||||
this.maskedTextBoxNumber.TabIndex = 5;
|
||||
//
|
||||
// FormTractorCollection
|
||||
//
|
||||
this.ClientSize = new System.Drawing.Size(948, 536);
|
||||
this.Controls.Add(this.groupBox);
|
||||
this.Controls.Add(this.pictureBoxCollection);
|
||||
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
|
||||
this.MinimizeBox = false;
|
||||
this.Name = "FormTractorCollection";
|
||||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
||||
this.Text = "Набор тракторов";
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).EndInit();
|
||||
this.groupBox.ResumeLayout(false);
|
||||
this.groupBox.PerformLayout();
|
||||
this.groupBox1.ResumeLayout(false);
|
||||
this.groupBox1.PerformLayout();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
private GroupBox groupBox;
|
||||
private Button ButtonRefreshCollection;
|
||||
private Button ButtonRemoveTractor;
|
||||
private Button ButtonAddTractor;
|
||||
private MaskedTextBox maskedTextBoxNumber;
|
||||
private GroupBox groupBox1;
|
||||
private Button ButtonDelObject;
|
||||
private ListBox listBoxStorages;
|
||||
private Button ButtonAddObject;
|
||||
private MaskedTextBox textBoxStorageName;
|
||||
private PictureBox pictureBoxCollection;
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
<root>
|
||||
<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 ProjectTractor
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new FormTractor());
|
||||
Application.Run(new FormTractorCollection());
|
||||
}
|
||||
}
|
||||
}
|
107
RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/SetGeneric.cs
Normal file
107
RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/SetGeneric.cs
Normal file
@ -0,0 +1,107 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectTractor.Generics
|
||||
{
|
||||
internal class SetGeneric<T>
|
||||
where T : class
|
||||
{
|
||||
/// <summary>
|
||||
/// Массив объектов, которые храним
|
||||
/// </summary>
|
||||
private readonly List<T?> _places;
|
||||
/// <summary>
|
||||
/// Количество объектов в массиве
|
||||
/// </summary>
|
||||
public int Count => _places.Count;
|
||||
/// <summary>
|
||||
/// Максимальное количество объектов в списке
|
||||
/// </summary>
|
||||
private readonly int _maxCount;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="count"></param>
|
||||
public SetGeneric(int count)
|
||||
{
|
||||
_maxCount = count;
|
||||
_places = new List<T?>(count);
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор
|
||||
/// </summary>
|
||||
/// <param name="tractor">Добавляемый трактор</param>
|
||||
/// <returns></returns>
|
||||
public bool Insert(T tractor)
|
||||
{
|
||||
if (_places.Count == _maxCount)
|
||||
return false;
|
||||
Insert(tractor, 0);
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор на конкретную позицию
|
||||
/// </summary>
|
||||
/// <param name="tractor">Добавляемый автомобиль</param>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns></returns>
|
||||
public bool Insert(T tractor, int position)
|
||||
{
|
||||
if (!(position >= 0 && position <= Count && _places.Count < _maxCount))
|
||||
return false;
|
||||
_places.Insert(position, tractor);
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление объекта из набора с конкретной позиции
|
||||
/// </summary>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public bool Remove(int position)
|
||||
{
|
||||
if (!(position >= 0 && position < Count))
|
||||
return false;
|
||||
_places.RemoveAt(position);
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение объекта из набора по позиции
|
||||
/// </summary>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public T? this[int position]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!(position >= 0 && position <= Count))
|
||||
return null;
|
||||
return _places[position];
|
||||
}
|
||||
set
|
||||
{
|
||||
if (!(position >= 0 && position <= Count))
|
||||
return;
|
||||
_places.Insert(position, value);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Проход по списку
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public IEnumerable<T?> GetTractors(int? maxTractors = null)
|
||||
{
|
||||
for (int i = 0; i < _places.Count; ++i)
|
||||
{
|
||||
yield return _places[i];
|
||||
if (maxTractors.HasValue && i == maxTractors.Value)
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,145 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ProjectTractor.DrawningObjects;
|
||||
using ProjectTractor.MovementStrategy;
|
||||
|
||||
namespace ProjectTractor.Generics
|
||||
{
|
||||
/// <summary>
|
||||
/// Параметризованный класс для набора объектов DrawningTractor
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <typeparam name="U"></typeparam>
|
||||
internal class TractorsGenericCollection<T, U>
|
||||
where T : DrawningTractor
|
||||
where U : IMoveableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Ширина окна прорисовки
|
||||
/// </summary>
|
||||
private readonly int _pictureWidth;
|
||||
/// <summary>
|
||||
/// Высота окна прорисовки
|
||||
/// </summary>
|
||||
private readonly int _pictureHeight;
|
||||
/// <summary>
|
||||
/// Размер занимаемого объектом места (ширина)
|
||||
/// </summary>
|
||||
private readonly int _placeSizeWidth = 210;
|
||||
/// <summary>
|
||||
/// Размер занимаемого объектом места (высота)
|
||||
/// </summary>
|
||||
private readonly int _placeSizeHeight = 90;
|
||||
/// <summary>
|
||||
/// Набор объектов
|
||||
/// </summary>
|
||||
private readonly SetGeneric<T> _collection;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="picWidth"></param>
|
||||
/// <param name="picHeight"></param>
|
||||
public TractorsGenericCollection(int picWidth, int picHeight)
|
||||
{
|
||||
int width = picWidth / _placeSizeWidth;
|
||||
int height = picHeight / _placeSizeHeight;
|
||||
_pictureWidth = picWidth;
|
||||
_pictureHeight = picHeight;
|
||||
_collection = new SetGeneric<T>(width * height);
|
||||
}
|
||||
/// <summary>
|
||||
/// Перегрузка оператора сложения
|
||||
/// </summary>
|
||||
/// <param name="collect"></param>
|
||||
/// <param name="obj"></param>
|
||||
/// <returns></returns>
|
||||
public static bool operator +(TractorsGenericCollection<T, U> collect, T?
|
||||
obj)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return collect?._collection.Insert(obj) ?? false;
|
||||
}
|
||||
/// <summary>
|
||||
/// Перегрузка оператора вычитания
|
||||
/// </summary>
|
||||
/// <param name="collect"></param>
|
||||
/// <param name="pos"></param>
|
||||
/// <returns></returns>
|
||||
public static bool operator -(TractorsGenericCollection<T, U> collect, int
|
||||
pos)
|
||||
{
|
||||
T? obj = collect._collection[pos];
|
||||
if (obj != null)
|
||||
{
|
||||
collect._collection.Remove(pos);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение объекта IMoveableObject
|
||||
/// </summary>
|
||||
/// <param name="pos"></param>
|
||||
/// <returns></returns>
|
||||
public U? GetU(int pos)
|
||||
{
|
||||
return (U?)_collection[pos]?.GetMoveableObject;
|
||||
}
|
||||
/// <summary>
|
||||
/// Вывод всего набора объектов
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Bitmap ShowTractors()
|
||||
{
|
||||
Bitmap bmp = new(_pictureWidth, _pictureHeight);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
DrawBackground(gr);
|
||||
DrawObjects(gr);
|
||||
return bmp;
|
||||
}
|
||||
/// <summary>
|
||||
/// Метод отрисовки фона
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
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 +
|
||||
1; ++j)
|
||||
{//линия рамзетки места
|
||||
g.DrawLine(pen, i * _placeSizeWidth, j *
|
||||
_placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j *
|
||||
_placeSizeHeight);
|
||||
}
|
||||
g.DrawLine(pen, i * _placeSizeWidth, 0, i *
|
||||
_placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Метод прорисовки объектов
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
private void DrawObjects(Graphics g)
|
||||
{
|
||||
int i = 0;
|
||||
foreach (var tractor in _collection.GetTractors())
|
||||
{
|
||||
if (tractor != null)
|
||||
{
|
||||
int countRows = _pictureWidth / _placeSizeWidth;
|
||||
tractor.SetPosition(_pictureWidth - _placeSizeWidth * 2 - (i % countRows * _placeSizeWidth) + 190, _pictureHeight - i / countRows * _placeSizeHeight - 160);
|
||||
tractor.DrawTransport(g);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,81 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ProjectTractor.DrawningObjects;
|
||||
using ProjectTractor.MovementStrategy;
|
||||
using ProjectTractor.Generics;
|
||||
|
||||
namespace ProjectTractor
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс для хранения коллекции
|
||||
/// </summary>
|
||||
internal class TractorsGenericStorage
|
||||
{
|
||||
/// <summary>
|
||||
/// Словарь (хранилище)
|
||||
/// </summary>
|
||||
readonly Dictionary<string, TractorsGenericCollection<DrawningTractor, DrawningObjectTractor>> _tractorStorages;
|
||||
/// <summary>
|
||||
/// Возвращение списка названий наборов
|
||||
/// </summary>
|
||||
public List<string> Keys => _tractorStorages.Keys.ToList();
|
||||
/// <summary>
|
||||
/// Ширина окна отрисовки
|
||||
/// </summary>
|
||||
private readonly int _pictureWidth;
|
||||
/// <summary>
|
||||
/// Высота окна отрисовки
|
||||
/// </summary>
|
||||
private readonly int _pictureHeight;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="pictureWidth"></param>
|
||||
/// <param name="pictureHeight"></param>
|
||||
public TractorsGenericStorage(int pictureWidth, int pictureHeight)
|
||||
{
|
||||
_tractorStorages = new Dictionary<string,
|
||||
TractorsGenericCollection<DrawningTractor, DrawningObjectTractor>>();
|
||||
_pictureWidth = pictureWidth;
|
||||
_pictureHeight = pictureHeight;
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление набора
|
||||
/// </summary>
|
||||
/// <param name="name">Название набора</param>
|
||||
public void AddSet(string name)
|
||||
{
|
||||
_tractorStorages.Add(name,
|
||||
new TractorsGenericCollection<DrawningTractor,
|
||||
DrawningObjectTractor>(_pictureWidth, _pictureHeight));
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление набора
|
||||
/// </summary>
|
||||
/// <param name="name">Название набора</param>
|
||||
public void DelSet(string name)
|
||||
{
|
||||
if (!_tractorStorages.ContainsKey(name))
|
||||
return;
|
||||
_tractorStorages.Remove(name);
|
||||
}
|
||||
/// <summary>
|
||||
/// Доступ к набору
|
||||
/// </summary>
|
||||
/// <param name="ind"></param>
|
||||
/// <returns></returns>
|
||||
public TractorsGenericCollection<DrawningTractor, DrawningObjectTractor>?
|
||||
this[string ind]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_tractorStorages.ContainsKey(ind))
|
||||
return _tractorStorages[ind];
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user