lab4
This commit is contained in:
parent
9fa54b1913
commit
219fd8b30d
@ -3,7 +3,6 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using DumpTruck.DrawningObjects;
|
|
||||||
using DumpTruck.Entities;
|
using DumpTruck.Entities;
|
||||||
|
|
||||||
namespace DumpTruck.DrawningObjects
|
namespace DumpTruck.DrawningObjects
|
||||||
|
12
DumpTruck/DumpTruck/FormDumpTruck.Designer.cs
generated
12
DumpTruck/DumpTruck/FormDumpTruck.Designer.cs
generated
@ -65,7 +65,7 @@
|
|||||||
// buttonLeft
|
// buttonLeft
|
||||||
//
|
//
|
||||||
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
buttonLeft.BackgroundImage = Properties.Resources.arrowLeft;
|
//buttonLeft.BackgroundImage = Properties.Resources.arrowLeft;
|
||||||
buttonLeft.BackgroundImageLayout = ImageLayout.Zoom;
|
buttonLeft.BackgroundImageLayout = ImageLayout.Zoom;
|
||||||
buttonLeft.Location = new Point(770, 426);
|
buttonLeft.Location = new Point(770, 426);
|
||||||
buttonLeft.Name = "buttonLeft";
|
buttonLeft.Name = "buttonLeft";
|
||||||
@ -77,7 +77,7 @@
|
|||||||
// buttonUp
|
// buttonUp
|
||||||
//
|
//
|
||||||
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
buttonUp.BackgroundImage = Properties.Resources.arrowUp;
|
//buttonUp.BackgroundImage = Properties.Resources.arrowUp;
|
||||||
buttonUp.BackgroundImageLayout = ImageLayout.Zoom;
|
buttonUp.BackgroundImageLayout = ImageLayout.Zoom;
|
||||||
buttonUp.Location = new Point(806, 390);
|
buttonUp.Location = new Point(806, 390);
|
||||||
buttonUp.Name = "buttonUp";
|
buttonUp.Name = "buttonUp";
|
||||||
@ -89,7 +89,7 @@
|
|||||||
// buttonDown
|
// buttonDown
|
||||||
//
|
//
|
||||||
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
buttonDown.BackgroundImage = Properties.Resources.arrowDown;
|
//buttonDown.BackgroundImage = Properties.Resources.arrowDown;
|
||||||
buttonDown.BackgroundImageLayout = ImageLayout.Zoom;
|
buttonDown.BackgroundImageLayout = ImageLayout.Zoom;
|
||||||
buttonDown.Location = new Point(806, 426);
|
buttonDown.Location = new Point(806, 426);
|
||||||
buttonDown.Name = "buttonDown";
|
buttonDown.Name = "buttonDown";
|
||||||
@ -101,7 +101,7 @@
|
|||||||
// buttonRight
|
// buttonRight
|
||||||
//
|
//
|
||||||
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
buttonRight.BackgroundImage = Properties.Resources.arrowRight;
|
//buttonRight.BackgroundImage = Properties.Resources.arrowRight;
|
||||||
buttonRight.BackgroundImageLayout = ImageLayout.Zoom;
|
buttonRight.BackgroundImageLayout = ImageLayout.Zoom;
|
||||||
buttonRight.Location = new Point(842, 426);
|
buttonRight.Location = new Point(842, 426);
|
||||||
buttonRight.Name = "buttonRight";
|
buttonRight.Name = "buttonRight";
|
||||||
@ -145,9 +145,9 @@
|
|||||||
//
|
//
|
||||||
// buttonSelectTruck
|
// buttonSelectTruck
|
||||||
//
|
//
|
||||||
buttonSelectTruck.Location = new Point(12, 357);
|
buttonSelectTruck.Location = new Point(249, 406);
|
||||||
buttonSelectTruck.Name = "buttonSelectTruck";
|
buttonSelectTruck.Name = "buttonSelectTruck";
|
||||||
buttonSelectTruck.Size = new Size(231, 43);
|
buttonSelectTruck.Size = new Size(110, 43);
|
||||||
buttonSelectTruck.TabIndex = 9;
|
buttonSelectTruck.TabIndex = 9;
|
||||||
buttonSelectTruck.Text = "Выбрать";
|
buttonSelectTruck.Text = "Выбрать";
|
||||||
buttonSelectTruck.UseVisualStyleBackColor = true;
|
buttonSelectTruck.UseVisualStyleBackColor = true;
|
||||||
|
73
DumpTruck/DumpTruck/FormTruckCollection.Designer.cs
generated
73
DumpTruck/DumpTruck/FormTruckCollection.Designer.cs
generated
@ -29,17 +29,24 @@
|
|||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
groupBox1 = new GroupBox();
|
groupBox1 = new GroupBox();
|
||||||
|
groupBoxStorage = new GroupBox();
|
||||||
|
textBoxStorageName = new TextBox();
|
||||||
|
buttonDelObject = new Button();
|
||||||
|
listBoxStorages = new ListBox();
|
||||||
|
buttonAddObject = new Button();
|
||||||
maskedTextBoxNumber = new MaskedTextBox();
|
maskedTextBoxNumber = new MaskedTextBox();
|
||||||
buttonRefreshCollection = new Button();
|
buttonRefreshCollection = new Button();
|
||||||
buttonRemoveTruck = new Button();
|
buttonRemoveTruck = new Button();
|
||||||
buttonAddTruck = new Button();
|
buttonAddTruck = new Button();
|
||||||
pictureBoxCollection = new PictureBox();
|
pictureBoxCollection = new PictureBox();
|
||||||
groupBox1.SuspendLayout();
|
groupBox1.SuspendLayout();
|
||||||
|
groupBoxStorage.SuspendLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
|
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
// groupBox1
|
// groupBox1
|
||||||
//
|
//
|
||||||
|
groupBox1.Controls.Add(groupBoxStorage);
|
||||||
groupBox1.Controls.Add(maskedTextBoxNumber);
|
groupBox1.Controls.Add(maskedTextBoxNumber);
|
||||||
groupBox1.Controls.Add(buttonRefreshCollection);
|
groupBox1.Controls.Add(buttonRefreshCollection);
|
||||||
groupBox1.Controls.Add(buttonRemoveTruck);
|
groupBox1.Controls.Add(buttonRemoveTruck);
|
||||||
@ -50,18 +57,67 @@
|
|||||||
groupBox1.TabIndex = 0;
|
groupBox1.TabIndex = 0;
|
||||||
groupBox1.TabStop = false;
|
groupBox1.TabStop = false;
|
||||||
groupBox1.Text = "Инструменты";
|
groupBox1.Text = "Инструменты";
|
||||||
groupBox1.Enter += groupBox1_Enter;
|
//
|
||||||
|
// groupBoxStorage
|
||||||
|
//
|
||||||
|
groupBoxStorage.Controls.Add(textBoxStorageName);
|
||||||
|
groupBoxStorage.Controls.Add(buttonDelObject);
|
||||||
|
groupBoxStorage.Controls.Add(listBoxStorages);
|
||||||
|
groupBoxStorage.Controls.Add(buttonAddObject);
|
||||||
|
groupBoxStorage.Location = new Point(6, 22);
|
||||||
|
groupBoxStorage.Name = "groupBoxStorage";
|
||||||
|
groupBoxStorage.Size = new Size(188, 219);
|
||||||
|
groupBoxStorage.TabIndex = 5;
|
||||||
|
groupBoxStorage.TabStop = false;
|
||||||
|
groupBoxStorage.Text = "Наборы";
|
||||||
|
//
|
||||||
|
// textBoxStorageName
|
||||||
|
//
|
||||||
|
textBoxStorageName.Location = new Point(6, 22);
|
||||||
|
textBoxStorageName.Name = "textBoxStorageName";
|
||||||
|
textBoxStorageName.Size = new Size(176, 23);
|
||||||
|
textBoxStorageName.TabIndex = 5;
|
||||||
|
//
|
||||||
|
// buttonDelObject
|
||||||
|
//
|
||||||
|
buttonDelObject.Location = new Point(6, 190);
|
||||||
|
buttonDelObject.Name = "buttonDelObject";
|
||||||
|
buttonDelObject.Size = new Size(176, 23);
|
||||||
|
buttonDelObject.TabIndex = 4;
|
||||||
|
buttonDelObject.Text = "Удалить набор";
|
||||||
|
buttonDelObject.UseVisualStyleBackColor = true;
|
||||||
|
buttonDelObject.Click += buttonDelObject_Click;
|
||||||
|
//
|
||||||
|
// listBoxStorages
|
||||||
|
//
|
||||||
|
listBoxStorages.FormattingEnabled = true;
|
||||||
|
listBoxStorages.ItemHeight = 15;
|
||||||
|
listBoxStorages.Location = new Point(6, 80);
|
||||||
|
listBoxStorages.Name = "listBoxStorages";
|
||||||
|
listBoxStorages.Size = new Size(176, 94);
|
||||||
|
listBoxStorages.TabIndex = 3;
|
||||||
|
listBoxStorages.SelectedIndexChanged += listBoxStorages_SelectedIndexChanged;
|
||||||
|
//
|
||||||
|
// buttonAddObject
|
||||||
|
//
|
||||||
|
buttonAddObject.Location = new Point(6, 51);
|
||||||
|
buttonAddObject.Name = "buttonAddObject";
|
||||||
|
buttonAddObject.Size = new Size(176, 23);
|
||||||
|
buttonAddObject.TabIndex = 2;
|
||||||
|
buttonAddObject.Text = "Добавить набор";
|
||||||
|
buttonAddObject.UseVisualStyleBackColor = true;
|
||||||
|
buttonAddObject.Click += buttonAddObject_Click;
|
||||||
//
|
//
|
||||||
// maskedTextBoxNumber
|
// maskedTextBoxNumber
|
||||||
//
|
//
|
||||||
maskedTextBoxNumber.Location = new Point(52, 166);
|
maskedTextBoxNumber.Location = new Point(52, 284);
|
||||||
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||||
maskedTextBoxNumber.Size = new Size(100, 23);
|
maskedTextBoxNumber.Size = new Size(100, 23);
|
||||||
maskedTextBoxNumber.TabIndex = 4;
|
maskedTextBoxNumber.TabIndex = 4;
|
||||||
//
|
//
|
||||||
// buttonRefreshCollection
|
// buttonRefreshCollection
|
||||||
//
|
//
|
||||||
buttonRefreshCollection.Location = new Point(6, 382);
|
buttonRefreshCollection.Location = new Point(6, 387);
|
||||||
buttonRefreshCollection.Name = "buttonRefreshCollection";
|
buttonRefreshCollection.Name = "buttonRefreshCollection";
|
||||||
buttonRefreshCollection.Size = new Size(188, 33);
|
buttonRefreshCollection.Size = new Size(188, 33);
|
||||||
buttonRefreshCollection.TabIndex = 3;
|
buttonRefreshCollection.TabIndex = 3;
|
||||||
@ -71,7 +127,7 @@
|
|||||||
//
|
//
|
||||||
// buttonRemoveTruck
|
// buttonRemoveTruck
|
||||||
//
|
//
|
||||||
buttonRemoveTruck.Location = new Point(6, 195);
|
buttonRemoveTruck.Location = new Point(6, 313);
|
||||||
buttonRemoveTruck.Name = "buttonRemoveTruck";
|
buttonRemoveTruck.Name = "buttonRemoveTruck";
|
||||||
buttonRemoveTruck.Size = new Size(188, 34);
|
buttonRemoveTruck.Size = new Size(188, 34);
|
||||||
buttonRemoveTruck.TabIndex = 2;
|
buttonRemoveTruck.TabIndex = 2;
|
||||||
@ -81,7 +137,7 @@
|
|||||||
//
|
//
|
||||||
// buttonAddTruck
|
// buttonAddTruck
|
||||||
//
|
//
|
||||||
buttonAddTruck.Location = new Point(6, 22);
|
buttonAddTruck.Location = new Point(6, 247);
|
||||||
buttonAddTruck.Name = "buttonAddTruck";
|
buttonAddTruck.Name = "buttonAddTruck";
|
||||||
buttonAddTruck.Size = new Size(188, 31);
|
buttonAddTruck.Size = new Size(188, 31);
|
||||||
buttonAddTruck.TabIndex = 1;
|
buttonAddTruck.TabIndex = 1;
|
||||||
@ -108,6 +164,8 @@
|
|||||||
Text = "Набор грузовиков";
|
Text = "Набор грузовиков";
|
||||||
groupBox1.ResumeLayout(false);
|
groupBox1.ResumeLayout(false);
|
||||||
groupBox1.PerformLayout();
|
groupBox1.PerformLayout();
|
||||||
|
groupBoxStorage.ResumeLayout(false);
|
||||||
|
groupBoxStorage.PerformLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
|
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
|
||||||
ResumeLayout(false);
|
ResumeLayout(false);
|
||||||
}
|
}
|
||||||
@ -120,5 +178,10 @@
|
|||||||
private Button buttonRefreshCollection;
|
private Button buttonRefreshCollection;
|
||||||
private PictureBox pictureBoxCollection;
|
private PictureBox pictureBoxCollection;
|
||||||
private MaskedTextBox maskedTextBoxNumber;
|
private MaskedTextBox maskedTextBoxNumber;
|
||||||
|
private GroupBox groupBoxStorage;
|
||||||
|
private Button buttonDelObject;
|
||||||
|
private ListBox listBoxStorages;
|
||||||
|
private Button buttonAddObject;
|
||||||
|
private TextBox textBoxStorageName;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -19,43 +19,88 @@ namespace DumpTruck
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Набор объектов
|
/// Набор объектов
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly TrucksGenericCollection<DrawningTruck, DrawningObjectTruck> _trucks;
|
private readonly TrucksGenericStorage _storage;
|
||||||
|
|
||||||
|
|
||||||
public FormTruckCollection()
|
public FormTruckCollection()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
_trucks = new TrucksGenericCollection<DrawningTruck, DrawningObjectTruck>(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
_storage = new TrucksGenericStorage(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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private void buttonAddTruck_Click(object sender, EventArgs e)
|
private void buttonAddTruck_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
if (listBoxStorages.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
|
||||||
|
string.Empty];
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
FormDumpTruck form = new();
|
FormDumpTruck form = new();
|
||||||
if (form.ShowDialog() == DialogResult.OK)
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
{
|
{
|
||||||
if (_trucks + form.selectedTruck != -1)
|
if (obj + form.selectedTruck != -1)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Объект добавлен");
|
MessageBox.Show("Объект добавлен");
|
||||||
pictureBoxCollection.Image = _trucks.ShowTrucks();
|
pictureBoxCollection.Image = obj.ShowTrucks();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
MessageBox.Show("Не удалось добавить объект");
|
MessageBox.Show("Не удалось добавить объект");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buttonRemoveTruck_Click(object sender, EventArgs e)
|
private void buttonRemoveTruck_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
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;
|
return;
|
||||||
}
|
}
|
||||||
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
||||||
if (_trucks - pos)
|
if (obj - pos)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Объект удален");
|
MessageBox.Show("Объект удален");
|
||||||
pictureBoxCollection.Image = _trucks.ShowTrucks();
|
pictureBoxCollection.Image = obj.ShowTrucks();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -66,12 +111,60 @@ namespace DumpTruck
|
|||||||
|
|
||||||
private void buttonRefreshCollection_Click(object sender, EventArgs e)
|
private void buttonRefreshCollection_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
pictureBoxCollection.Image = _trucks.ShowTrucks();
|
if (listBoxStorages.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
|
||||||
|
string.Empty];
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pictureBoxCollection.Image = obj.ShowTrucks();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void groupBox1_Enter(object sender, EventArgs e)
|
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]?.ShowTrucks();
|
||||||
|
}
|
||||||
|
/// <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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,18 +17,23 @@ namespace DumpTruck.Generics
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Массив объектов, которые храним
|
/// Массив объектов, которые храним
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly T?[] _places;
|
private readonly List<T?> _places;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Количество объектов в массиве
|
/// Количество объектов в массиве
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int Count => _places.Length;
|
public int Count => _places.Count;
|
||||||
|
/// <summary>
|
||||||
|
/// Максимальное количество объектов в списке
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _maxCount;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Конструктор
|
/// Конструктор
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="count"></param>
|
/// <param name="count"></param>
|
||||||
public SetGeneric(int count)
|
public SetGeneric(int count)
|
||||||
{
|
{
|
||||||
_places = new T?[count];
|
_maxCount = count;
|
||||||
|
_places = new List<T?>(count);
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Добавление объекта в набор
|
/// Добавление объекта в набор
|
||||||
@ -47,39 +52,13 @@ namespace DumpTruck.Generics
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public int Insert(T truck, int position)
|
public int Insert(T truck, int position)
|
||||||
{
|
{
|
||||||
// TODO проверка позиции
|
// Проверка позиции
|
||||||
if (position < 0 || position > Count)
|
if (position < 0 || position >= _maxCount)
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
// TODO проверка, что элемент массива по этой позиции пустой, если нет, то
|
// Вставка по позиции
|
||||||
if (_places[position] != null)
|
_places.Insert(position, truck);
|
||||||
{
|
|
||||||
// проверка, что после вставляемого элемента в массиве есть пустой элемент
|
|
||||||
int nullIndex = -1;
|
|
||||||
for (int i = position + 1; i < Count; i++)
|
|
||||||
{
|
|
||||||
if (_places[i] == null)
|
|
||||||
{
|
|
||||||
nullIndex = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Если пустого элемента нет, то выходим
|
|
||||||
if (nullIndex < 0)
|
|
||||||
{
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
// сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента
|
|
||||||
int j = nullIndex - 1;
|
|
||||||
while (j >= position)
|
|
||||||
{
|
|
||||||
_places[j + 1] = _places[j];
|
|
||||||
j--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// TODO вставка по позиции
|
|
||||||
_places[position] = truck;
|
|
||||||
return position;
|
return position;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -100,11 +79,44 @@ namespace DumpTruck.Generics
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="position"></param>
|
/// <param name="position"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public T? Get(int position)
|
public T? this[int position]
|
||||||
{
|
{
|
||||||
// TODO проверка позиции
|
get
|
||||||
if ((position < 0) || (position > Count)) return null;
|
{
|
||||||
|
// Проверка позиции
|
||||||
|
if (position < 0 || position >= Count)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
return _places[position];
|
return _places[position];
|
||||||
}
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
// Проверка позиции
|
||||||
|
// Проверка свободных мест в списке
|
||||||
|
if (position < 0 || position >= _maxCount || Count == _maxCount)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Вставка в список по позиции
|
||||||
|
_places.Insert(position, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Проход по списку
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public IEnumerable<T?> GetTrucks(int? maxTrucks = null)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < _places.Count; ++i)
|
||||||
|
{
|
||||||
|
yield return _places[i];
|
||||||
|
if (maxTrucks.HasValue && i == maxTrucks.Value)
|
||||||
|
{
|
||||||
|
yield break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ namespace DumpTruck.Generics
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static bool operator -(TrucksGenericCollection<T, U> collect, int pos)
|
public static bool operator -(TrucksGenericCollection<T, U> collect, int pos)
|
||||||
{
|
{
|
||||||
T? obj = collect._collection.Get(pos);
|
T? obj = collect._collection[pos];
|
||||||
if (obj != null)
|
if (obj != null)
|
||||||
{
|
{
|
||||||
return collect._collection.Remove(pos);
|
return collect._collection.Remove(pos);
|
||||||
@ -82,7 +82,7 @@ namespace DumpTruck.Generics
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public U? GetU(int pos)
|
public U? GetU(int pos)
|
||||||
{
|
{
|
||||||
return (U?)_collection.Get(pos)?.GetMoveableObject;
|
return (U?)_collection[pos]?.GetMoveableObject;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Вывод всего набора объектов
|
/// Вывод всего набора объектов
|
||||||
@ -129,7 +129,7 @@ namespace DumpTruck.Generics
|
|||||||
// TODO получение объекта
|
// TODO получение объекта
|
||||||
// TODO установка позиции
|
// TODO установка позиции
|
||||||
// TODO прорисовка объекта
|
// TODO прорисовка объекта
|
||||||
DrawningTruck? truck = _collection.Get(i);
|
DrawningTruck? truck = _collection[i];
|
||||||
if (truck == null)
|
if (truck == null)
|
||||||
continue;
|
continue;
|
||||||
truck.SetPosition(i % width * _placeSizeWidth, i / width * _placeSizeHeight);
|
truck.SetPosition(i % width * _placeSizeWidth, i / width * _placeSizeHeight);
|
||||||
|
76
DumpTruck/DumpTruck/TrucksGenericStorage.cs
Normal file
76
DumpTruck/DumpTruck/TrucksGenericStorage.cs
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using DumpTruck.DrawningObjects;
|
||||||
|
using DumpTruck.MovementStrategy;
|
||||||
|
|
||||||
|
namespace DumpTruck.Generics
|
||||||
|
{
|
||||||
|
internal class TrucksGenericStorage
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Словарь (хранилище)
|
||||||
|
/// </summary>
|
||||||
|
readonly Dictionary<string, TrucksGenericCollection<DrawningTruck, DrawningObjectTruck>> _truckStorages;
|
||||||
|
/// <summary>
|
||||||
|
/// Возвращение списка названий наборов
|
||||||
|
/// </summary>
|
||||||
|
public List<string> Keys => _truckStorages.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 TrucksGenericStorage(int pictureWidth, int pictureHeight)
|
||||||
|
{
|
||||||
|
_truckStorages = new Dictionary<string, TrucksGenericCollection<DrawningTruck, DrawningObjectTruck>>();
|
||||||
|
_pictureWidth = pictureWidth;
|
||||||
|
_pictureHeight = pictureHeight;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление набора
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">Название набора</param>
|
||||||
|
public void AddSet(string name)
|
||||||
|
{
|
||||||
|
// TODO Прописать логику для добавления
|
||||||
|
_truckStorages.Add(name, new TrucksGenericCollection<DrawningTruck, DrawningObjectTruck>(_pictureWidth, _pictureHeight));
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Удаление набора
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">Название набора</param>
|
||||||
|
public void DelSet(string name)
|
||||||
|
{
|
||||||
|
// TODO Прописать логику для удаления
|
||||||
|
if (_truckStorages.ContainsKey(name))
|
||||||
|
_truckStorages.Remove(name);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Доступ к набору
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ind"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public TrucksGenericCollection<DrawningTruck, DrawningObjectTruck>? this[string ind]
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
// TODO Продумать логику получения набора
|
||||||
|
if (_truckStorages.ContainsKey(ind))
|
||||||
|
return _truckStorages[ind];
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user