Lab 4
This commit is contained in:
parent
08fc6e78cd
commit
3a6b043a1b
@ -70,7 +70,7 @@ namespace Bulldozer.Generics
|
|||||||
public static bool operator -(BulldozerGenericCollection<T, U> collect, int
|
public static bool operator -(BulldozerGenericCollection<T, U> collect, int
|
||||||
pos)
|
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);
|
||||||
@ -84,7 +84,7 @@ namespace Bulldozer.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>
|
||||||
/// Вывод всего набора объектов
|
/// Вывод всего набора объектов
|
||||||
@ -126,32 +126,31 @@ namespace Bulldozer.Generics
|
|||||||
{
|
{
|
||||||
int c = 11;
|
int c = 11;
|
||||||
int k = 3;
|
int k = 3;
|
||||||
for (int i = 0; i < _collection.Count; i++)
|
foreach (var tractor in _collection.GetBulldozer())
|
||||||
{
|
{
|
||||||
if (i % 3 == 0 && i != 0)
|
if (tractor != null)
|
||||||
{
|
{
|
||||||
c = c - 3;
|
int i = _collection.GetBulldozer().ToList().IndexOf(tractor);
|
||||||
}
|
if (i % 3 == 0 && i != 0)
|
||||||
|
{
|
||||||
|
c = c - 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (k != 0)
|
||||||
|
{
|
||||||
|
k--;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
k = 2;
|
||||||
|
}
|
||||||
|
|
||||||
if (k != 0)
|
|
||||||
{
|
|
||||||
k--;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
k = 2;
|
|
||||||
}
|
|
||||||
T? obj = _collection.Get(i);
|
|
||||||
if (obj != null)
|
|
||||||
{
|
|
||||||
// Получение объекта
|
|
||||||
IMoveableObject moveableObject = obj.GetMoveableObject;
|
|
||||||
// Установка позиции
|
// Установка позиции
|
||||||
int x = k % (_pictureWidth / _placeSizeWidth) * _placeSizeWidth;
|
int x = k % (_pictureWidth / _placeSizeWidth) * _placeSizeWidth;
|
||||||
int y = c / (_pictureWidth / _placeSizeWidth) * _placeSizeHeight + 10;
|
int y = c / (_pictureWidth / _placeSizeWidth) * _placeSizeHeight + 10;
|
||||||
moveableObject.SetPosition(x, y);
|
tractor.SetPosition(x, y);
|
||||||
// Прорисовка объекта
|
// Прорисовка объекта
|
||||||
moveableObject.Draw(g);
|
tractor.DrawTrasport(g);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
87
Bulldozer/Bulldozer/BulldozersGenericStorage.cs
Normal file
87
Bulldozer/Bulldozer/BulldozersGenericStorage.cs
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Bulldozer.DrawningObjects;
|
||||||
|
using Bulldozer.Generics;
|
||||||
|
using Bulldozer.MovementStrategy;
|
||||||
|
using Bulldozer.Drawnings;
|
||||||
|
|
||||||
|
namespace Bulldozer.Generics
|
||||||
|
{
|
||||||
|
internal class BulldozersGenericStorage
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Словарь (хранилище)
|
||||||
|
/// </summary>
|
||||||
|
readonly Dictionary<string, BulldozerGenericCollection<DrawningBulldozer,
|
||||||
|
DrawningObjectBulldozer>> _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 BulldozersGenericStorage(int pictureWidth, int pictureHeight)
|
||||||
|
{
|
||||||
|
_tractorStorages = new Dictionary<string,
|
||||||
|
BulldozerGenericCollection<DrawningBulldozer, DrawningObjectBulldozer>>();
|
||||||
|
_pictureWidth = pictureWidth;
|
||||||
|
_pictureHeight = pictureHeight;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление набора
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">Название набора</param>
|
||||||
|
public void AddSet(string name)
|
||||||
|
{
|
||||||
|
// TODO Прописать логику для добавления
|
||||||
|
if (!_tractorStorages.ContainsKey(name))
|
||||||
|
{
|
||||||
|
var tractorCollection = new BulldozerGenericCollection<DrawningBulldozer, DrawningObjectBulldozer>(_pictureWidth, _pictureHeight);
|
||||||
|
_tractorStorages.Add(name, tractorCollection);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Удаление набора
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">Название набора</param>
|
||||||
|
public void DelSet(string name)
|
||||||
|
{
|
||||||
|
// TODO Прописать логику для удаления
|
||||||
|
if (_tractorStorages.ContainsKey(name))
|
||||||
|
{
|
||||||
|
_tractorStorages.Remove(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Доступ к набору
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ind"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public BulldozerGenericCollection<DrawningBulldozer, DrawningObjectBulldozer>? this[string ind]
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
// TODO Продумать логику получения набора
|
||||||
|
if (_tractorStorages.ContainsKey(ind))
|
||||||
|
{
|
||||||
|
return _tractorStorages[ind];
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
100
Bulldozer/Bulldozer/FormBulldozerCollection.Designer.cs
generated
100
Bulldozer/Bulldozer/FormBulldozerCollection.Designer.cs
generated
@ -34,14 +34,21 @@
|
|||||||
pictureBoxCollection = new PictureBox();
|
pictureBoxCollection = new PictureBox();
|
||||||
maskedTextBoxNumber = new MaskedTextBox();
|
maskedTextBoxNumber = new MaskedTextBox();
|
||||||
groupBox1 = new GroupBox();
|
groupBox1 = new GroupBox();
|
||||||
|
groupBox2 = new GroupBox();
|
||||||
|
listBoxStorage = new ListBox();
|
||||||
|
ButtonDelObject = new Button();
|
||||||
|
ButtonAddObject = new Button();
|
||||||
|
textBoxStorageName = new TextBox();
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
|
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
|
||||||
|
groupBox1.SuspendLayout();
|
||||||
|
groupBox2.SuspendLayout();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
// ButtonAddBulldozer
|
// ButtonAddBulldozer
|
||||||
//
|
//
|
||||||
ButtonAddBulldozer.Location = new Point(668, 45);
|
ButtonAddBulldozer.Location = new Point(26, 314);
|
||||||
ButtonAddBulldozer.Name = "ButtonAddBulldozer";
|
ButtonAddBulldozer.Name = "ButtonAddBulldozer";
|
||||||
ButtonAddBulldozer.Size = new Size(166, 31);
|
ButtonAddBulldozer.Size = new Size(166, 40);
|
||||||
ButtonAddBulldozer.TabIndex = 0;
|
ButtonAddBulldozer.TabIndex = 0;
|
||||||
ButtonAddBulldozer.Text = "Добавить трактор";
|
ButtonAddBulldozer.Text = "Добавить трактор";
|
||||||
ButtonAddBulldozer.UseVisualStyleBackColor = true;
|
ButtonAddBulldozer.UseVisualStyleBackColor = true;
|
||||||
@ -49,9 +56,9 @@
|
|||||||
//
|
//
|
||||||
// ButtonRemoveBulldozer
|
// ButtonRemoveBulldozer
|
||||||
//
|
//
|
||||||
ButtonRemoveBulldozer.Location = new Point(668, 129);
|
ButtonRemoveBulldozer.Location = new Point(26, 400);
|
||||||
ButtonRemoveBulldozer.Name = "ButtonRemoveBulldozer";
|
ButtonRemoveBulldozer.Name = "ButtonRemoveBulldozer";
|
||||||
ButtonRemoveBulldozer.Size = new Size(166, 31);
|
ButtonRemoveBulldozer.Size = new Size(166, 39);
|
||||||
ButtonRemoveBulldozer.TabIndex = 1;
|
ButtonRemoveBulldozer.TabIndex = 1;
|
||||||
ButtonRemoveBulldozer.Text = "Удалить трактор";
|
ButtonRemoveBulldozer.Text = "Удалить трактор";
|
||||||
ButtonRemoveBulldozer.UseVisualStyleBackColor = true;
|
ButtonRemoveBulldozer.UseVisualStyleBackColor = true;
|
||||||
@ -59,9 +66,9 @@
|
|||||||
//
|
//
|
||||||
// ButtonRefreshCollection
|
// ButtonRefreshCollection
|
||||||
//
|
//
|
||||||
ButtonRefreshCollection.Location = new Point(668, 215);
|
ButtonRefreshCollection.Location = new Point(26, 478);
|
||||||
ButtonRefreshCollection.Name = "ButtonRefreshCollection";
|
ButtonRefreshCollection.Name = "ButtonRefreshCollection";
|
||||||
ButtonRefreshCollection.Size = new Size(166, 31);
|
ButtonRefreshCollection.Size = new Size(166, 40);
|
||||||
ButtonRefreshCollection.TabIndex = 2;
|
ButtonRefreshCollection.TabIndex = 2;
|
||||||
ButtonRefreshCollection.Text = "Обновить коллекцию";
|
ButtonRefreshCollection.Text = "Обновить коллекцию";
|
||||||
ButtonRefreshCollection.UseVisualStyleBackColor = true;
|
ButtonRefreshCollection.UseVisualStyleBackColor = true;
|
||||||
@ -71,7 +78,7 @@
|
|||||||
//
|
//
|
||||||
pictureBoxCollection.Location = new Point(0, 0);
|
pictureBoxCollection.Location = new Point(0, 0);
|
||||||
pictureBoxCollection.Name = "pictureBoxCollection";
|
pictureBoxCollection.Name = "pictureBoxCollection";
|
||||||
pictureBoxCollection.Size = new Size(624, 457);
|
pictureBoxCollection.Size = new Size(637, 530);
|
||||||
pictureBoxCollection.SizeMode = PictureBoxSizeMode.Zoom;
|
pictureBoxCollection.SizeMode = PictureBoxSizeMode.Zoom;
|
||||||
pictureBoxCollection.TabIndex = 3;
|
pictureBoxCollection.TabIndex = 3;
|
||||||
pictureBoxCollection.TabStop = false;
|
pictureBoxCollection.TabStop = false;
|
||||||
@ -79,7 +86,7 @@
|
|||||||
// maskedTextBoxNumber
|
// maskedTextBoxNumber
|
||||||
//
|
//
|
||||||
maskedTextBoxNumber.Font = new Font("Showcard Gothic", 9F, FontStyle.Regular, GraphicsUnit.Point);
|
maskedTextBoxNumber.Font = new Font("Showcard Gothic", 9F, FontStyle.Regular, GraphicsUnit.Point);
|
||||||
maskedTextBoxNumber.Location = new Point(698, 100);
|
maskedTextBoxNumber.Location = new Point(56, 371);
|
||||||
maskedTextBoxNumber.Mask = "00";
|
maskedTextBoxNumber.Mask = "00";
|
||||||
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||||
maskedTextBoxNumber.Size = new Size(100, 22);
|
maskedTextBoxNumber.Size = new Size(100, 22);
|
||||||
@ -88,29 +95,83 @@
|
|||||||
//
|
//
|
||||||
// groupBox1
|
// groupBox1
|
||||||
//
|
//
|
||||||
groupBox1.Location = new Point(646, 12);
|
groupBox1.Controls.Add(groupBox2);
|
||||||
|
groupBox1.Controls.Add(ButtonAddBulldozer);
|
||||||
|
groupBox1.Controls.Add(ButtonRefreshCollection);
|
||||||
|
groupBox1.Controls.Add(maskedTextBoxNumber);
|
||||||
|
groupBox1.Controls.Add(ButtonRemoveBulldozer);
|
||||||
|
groupBox1.Location = new Point(643, 12);
|
||||||
groupBox1.Name = "groupBox1";
|
groupBox1.Name = "groupBox1";
|
||||||
groupBox1.Size = new Size(209, 412);
|
groupBox1.Size = new Size(209, 533);
|
||||||
groupBox1.TabIndex = 5;
|
groupBox1.TabIndex = 5;
|
||||||
groupBox1.TabStop = false;
|
groupBox1.TabStop = false;
|
||||||
groupBox1.Text = "Инструменты";
|
groupBox1.Text = "Инструменты";
|
||||||
//
|
//
|
||||||
|
// groupBox2
|
||||||
|
//
|
||||||
|
groupBox2.Controls.Add(listBoxStorage);
|
||||||
|
groupBox2.Controls.Add(ButtonDelObject);
|
||||||
|
groupBox2.Controls.Add(ButtonAddObject);
|
||||||
|
groupBox2.Controls.Add(textBoxStorageName);
|
||||||
|
groupBox2.Location = new Point(6, 22);
|
||||||
|
groupBox2.Name = "groupBox2";
|
||||||
|
groupBox2.Size = new Size(197, 274);
|
||||||
|
groupBox2.TabIndex = 6;
|
||||||
|
groupBox2.TabStop = false;
|
||||||
|
groupBox2.Text = "Наборы";
|
||||||
|
//
|
||||||
|
// listBoxStorage
|
||||||
|
//
|
||||||
|
listBoxStorage.FormattingEnabled = true;
|
||||||
|
listBoxStorage.ItemHeight = 15;
|
||||||
|
listBoxStorage.Location = new Point(20, 106);
|
||||||
|
listBoxStorage.Name = "listBoxStorage";
|
||||||
|
listBoxStorage.Size = new Size(158, 109);
|
||||||
|
listBoxStorage.TabIndex = 9;
|
||||||
|
listBoxStorage.SelectedIndexChanged += listBoxStorage_SelectedIndexChanged;
|
||||||
|
//
|
||||||
|
// ButtonDelObject
|
||||||
|
//
|
||||||
|
ButtonDelObject.Location = new Point(33, 235);
|
||||||
|
ButtonDelObject.Name = "ButtonDelObject";
|
||||||
|
ButtonDelObject.Size = new Size(136, 33);
|
||||||
|
ButtonDelObject.TabIndex = 8;
|
||||||
|
ButtonDelObject.Text = "Удалить набор";
|
||||||
|
ButtonDelObject.UseVisualStyleBackColor = true;
|
||||||
|
ButtonDelObject.Click += ButtonDelObject_Click;
|
||||||
|
//
|
||||||
|
// ButtonAddObject
|
||||||
|
//
|
||||||
|
ButtonAddObject.Location = new Point(33, 54);
|
||||||
|
ButtonAddObject.Name = "ButtonAddObject";
|
||||||
|
ButtonAddObject.Size = new Size(136, 33);
|
||||||
|
ButtonAddObject.TabIndex = 7;
|
||||||
|
ButtonAddObject.Text = "Добавить набор";
|
||||||
|
ButtonAddObject.UseVisualStyleBackColor = true;
|
||||||
|
ButtonAddObject.Click += ButtonAddObject_Click;
|
||||||
|
//
|
||||||
|
// textBoxStorageName
|
||||||
|
//
|
||||||
|
textBoxStorageName.Location = new Point(20, 22);
|
||||||
|
textBoxStorageName.Name = "textBoxStorageName";
|
||||||
|
textBoxStorageName.Size = new Size(158, 23);
|
||||||
|
textBoxStorageName.TabIndex = 0;
|
||||||
|
//
|
||||||
// FormBulldozerCollection
|
// FormBulldozerCollection
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(877, 469);
|
ClientSize = new Size(867, 584);
|
||||||
Controls.Add(ButtonRefreshCollection);
|
|
||||||
Controls.Add(ButtonRemoveBulldozer);
|
|
||||||
Controls.Add(maskedTextBoxNumber);
|
|
||||||
Controls.Add(ButtonAddBulldozer);
|
|
||||||
Controls.Add(groupBox1);
|
Controls.Add(groupBox1);
|
||||||
Controls.Add(pictureBoxCollection);
|
Controls.Add(pictureBoxCollection);
|
||||||
Name = "FormBulldozerCollection";
|
Name = "FormBulldozerCollection";
|
||||||
Text = "Набор трактористов";
|
Text = "Набор тракторов";
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
|
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
|
||||||
|
groupBox1.ResumeLayout(false);
|
||||||
|
groupBox1.PerformLayout();
|
||||||
|
groupBox2.ResumeLayout(false);
|
||||||
|
groupBox2.PerformLayout();
|
||||||
ResumeLayout(false);
|
ResumeLayout(false);
|
||||||
PerformLayout();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@ -121,5 +182,10 @@
|
|||||||
private PictureBox pictureBoxCollection;
|
private PictureBox pictureBoxCollection;
|
||||||
private MaskedTextBox maskedTextBoxNumber;
|
private MaskedTextBox maskedTextBoxNumber;
|
||||||
private GroupBox groupBox1;
|
private GroupBox groupBox1;
|
||||||
|
private GroupBox groupBox2;
|
||||||
|
private TextBox textBoxStorageName;
|
||||||
|
private ListBox listBoxStorage;
|
||||||
|
private Button ButtonDelObject;
|
||||||
|
private Button ButtonAddObject;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,37 +1,121 @@
|
|||||||
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 Bulldozer.DrawningObjects;
|
using Bulldozer.DrawningObjects;
|
||||||
using Bulldozer.Drawnings;
|
using Bulldozer.Drawnings;
|
||||||
using Bulldozer.Generics;
|
using Bulldozer.Generics;
|
||||||
using Bulldozer.MovementStrategy;
|
using Bulldozer.MovementStrategy;
|
||||||
|
|
||||||
|
|
||||||
namespace Bulldozer
|
namespace Bulldozer
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Форма для работы с набором объектов класса DrawningCar
|
||||||
|
/// </summary>
|
||||||
public partial class FormBulldozerCollection : Form
|
public partial class FormBulldozerCollection : Form
|
||||||
{
|
{
|
||||||
private readonly BulldozerGenericCollection<DrawningBulldozer, DrawningObjectBulldozer> _tractor;
|
/// <summary>
|
||||||
|
/// Набор объектов
|
||||||
|
/// </summary>
|
||||||
|
private readonly BulldozersGenericStorage _storage;
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
public FormBulldozerCollection()
|
public FormBulldozerCollection()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
_tractor = new BulldozerGenericCollection<DrawningBulldozer, DrawningObjectBulldozer>(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
_storage = new BulldozersGenericStorage(pictureBoxCollection.Width,
|
||||||
|
pictureBoxCollection.Height);
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Заполнение listBoxObjects
|
||||||
|
/// </summary>
|
||||||
|
private void ReloadObjects()
|
||||||
|
{
|
||||||
|
int index = listBoxStorage.SelectedIndex;
|
||||||
|
listBoxStorage.Items.Clear();
|
||||||
|
for (int i = 0; i < _storage.Keys.Count; i++)
|
||||||
|
{
|
||||||
|
listBoxStorage.Items.Add(_storage.Keys[i]);
|
||||||
|
}
|
||||||
|
if (listBoxStorage.Items.Count > 0 && (index == -1 || index
|
||||||
|
>= listBoxStorage.Items.Count))
|
||||||
|
{
|
||||||
|
listBoxStorage.SelectedIndex = 0;
|
||||||
|
}
|
||||||
|
else if (listBoxStorage.Items.Count > 0 && index > -1 &&
|
||||||
|
index < listBoxStorage.Items.Count)
|
||||||
|
{
|
||||||
|
listBoxStorage.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 listBoxStorage_SelectedIndexChanged(object sender,
|
||||||
|
EventArgs e)
|
||||||
|
{
|
||||||
|
pictureBoxCollection.Image =
|
||||||
|
_storage[listBoxStorage.SelectedItem?.ToString() ?? string.Empty]?.ShowBulldozer();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Удаление набора
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ButtonDelObject_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listBoxStorage.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (MessageBox.Show($"Удалить объект {listBoxStorage.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||||
|
|
||||||
|
{
|
||||||
|
_storage.DelSet(listBoxStorage.SelectedItem.ToString()
|
||||||
|
?? string.Empty);
|
||||||
|
ReloadObjects();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление объекта в набор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
private void ButtonAddBulldozer_Click(object sender, EventArgs e)
|
private void ButtonAddBulldozer_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
if (listBoxStorage.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var obj = _storage[listBoxStorage.SelectedItem.ToString() ??
|
||||||
|
string.Empty];
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
FastBulldozer form = new();
|
FastBulldozer form = new();
|
||||||
if (form.ShowDialog() == DialogResult.OK)
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
{
|
{
|
||||||
if (_tractor + form.SelectedTractor > -1)
|
if (obj + form.SelectedTractor > -1)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Объект добавлен");
|
MessageBox.Show("Объект добавлен");
|
||||||
pictureBoxCollection.Image = _tractor.ShowBulldozer();
|
pictureBoxCollection.Image = obj.ShowBulldozer();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -39,27 +123,59 @@ namespace Bulldozer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Удаление объекта из набора
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
private void ButtonRemoveBulldozer_Click(object sender, EventArgs e)
|
private void ButtonRemoveBulldozer_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
if (listBoxStorage.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var obj = _storage[listBoxStorage.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 (_tractor - pos != null)
|
if (obj - pos != null)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Объект удален");
|
MessageBox.Show("Объект удален");
|
||||||
pictureBoxCollection.Image = _tractor.ShowBulldozer();
|
pictureBoxCollection.Image = obj.ShowBulldozer();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
MessageBox.Show("Не удалось удалить объект");
|
MessageBox.Show("Не удалось удалить объект");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
|
/// <summary>
|
||||||
|
/// Обновление рисунка по набору
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ButtonRefreshCollection_Click(object sender, EventArgs
|
||||||
|
e)
|
||||||
{
|
{
|
||||||
pictureBoxCollection.Image = _tractor.ShowBulldozer();
|
if (listBoxStorage.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var obj = _storage[listBoxStorage.SelectedItem.ToString() ??
|
||||||
|
string.Empty];
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pictureBoxCollection.Image = obj.ShowBulldozer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,18 +10,23 @@
|
|||||||
/// <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>
|
||||||
/// Добавление объекта в набор
|
/// Добавление объекта в набор
|
||||||
@ -41,32 +46,14 @@
|
|||||||
public int Insert(T tractor, int position)
|
public int Insert(T tractor, int position)
|
||||||
{
|
{
|
||||||
// TODO проверка позиции
|
// TODO проверка позиции
|
||||||
if (position < 0 || position >= Count)
|
if (position < 0 || position >= _maxCount)
|
||||||
{
|
{
|
||||||
// Позиция недопустима
|
// Позиция недопустима
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (_places[position] != null)
|
if (Count >= _maxCount)
|
||||||
{
|
return -1;
|
||||||
int d = 0;
|
_places.Insert(position, tractor);
|
||||||
for(int j = 1; j < Count; j++)
|
|
||||||
{
|
|
||||||
if (_places[position + j] == null)
|
|
||||||
{
|
|
||||||
d = position + j;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(d == 0)
|
|
||||||
{
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
for(int j = d; j > position; j--)
|
|
||||||
{
|
|
||||||
_places[j] = _places[j - 1];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_places[position] = tractor;
|
|
||||||
return position;
|
return position;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -79,13 +66,13 @@
|
|||||||
{
|
{
|
||||||
// TODO проверка позиции
|
// TODO проверка позиции
|
||||||
// Проверка позиции
|
// Проверка позиции
|
||||||
if (position < 0 || position >= _places.Length)
|
if ((position < 0) || (position > _maxCount))
|
||||||
{
|
{
|
||||||
// Позиция недопустима
|
// Позиция недопустима
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// TODO удаление объекта из массива, присвоив элементу массива значение null
|
// TODO удаление объекта из массива, присвоив элементу массива значение null
|
||||||
_places[position] = null;
|
_places.RemoveAt(position);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -93,15 +80,36 @@
|
|||||||
/// </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 проверка позиции
|
// TODO проверка позиции
|
||||||
if (position < 0 || position >= _places.Length)
|
get
|
||||||
{
|
{
|
||||||
// Позиция недопустима
|
if (position < 0 || position > _maxCount)
|
||||||
return null;
|
return null;
|
||||||
|
return _places[position];
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (position < 0 || position > _maxCount)
|
||||||
|
return;
|
||||||
|
_places[position] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Проход по списку
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public IEnumerable<T?> GetBulldozer(int? maxTractor = null)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < _places.Count; ++i)
|
||||||
|
{
|
||||||
|
yield return _places[i];
|
||||||
|
if (maxTractor.HasValue && i == maxTractor.Value)
|
||||||
|
{
|
||||||
|
yield break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return _places[position];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user