ISEbd21 Zinovev V.V. Lab Work 08 #21
@ -30,6 +30,8 @@
|
||||
{
|
||||
this.components = new System.ComponentModel.Container();
|
||||
this.ArmoredTransportCollectionFormToolsGroup = new System.Windows.Forms.GroupBox();
|
||||
this.ButtonSortByType = new System.Windows.Forms.Button();
|
||||
this.ButtonSortByColor = new System.Windows.Forms.Button();
|
||||
this.groupBox1 = new System.Windows.Forms.GroupBox();
|
||||
this.textBoxStorageName = new System.Windows.Forms.TextBox();
|
||||
this.listBoxStorages = new System.Windows.Forms.ListBox();
|
||||
@ -57,6 +59,8 @@
|
||||
//
|
||||
this.ArmoredTransportCollectionFormToolsGroup.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.ArmoredTransportCollectionFormToolsGroup.Controls.Add(this.ButtonSortByType);
|
||||
this.ArmoredTransportCollectionFormToolsGroup.Controls.Add(this.ButtonSortByColor);
|
||||
this.ArmoredTransportCollectionFormToolsGroup.Controls.Add(this.groupBox1);
|
||||
this.ArmoredTransportCollectionFormToolsGroup.Controls.Add(this.ButtonRefreshCollection);
|
||||
this.ArmoredTransportCollectionFormToolsGroup.Controls.Add(this.ButtonRemoveArmoredTransport);
|
||||
@ -69,6 +73,28 @@
|
||||
this.ArmoredTransportCollectionFormToolsGroup.TabStop = false;
|
||||
this.ArmoredTransportCollectionFormToolsGroup.Text = "Инструменты";
|
||||
//
|
||||
// ButtonSortByType
|
||||
//
|
||||
this.ButtonSortByType.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.ButtonSortByType.Location = new System.Drawing.Point(41, 516);
|
||||
this.ButtonSortByType.Name = "ButtonSortByType";
|
||||
this.ButtonSortByType.Size = new System.Drawing.Size(353, 46);
|
||||
this.ButtonSortByType.TabIndex = 5;
|
||||
this.ButtonSortByType.Text = "Сортировка по типу";
|
||||
this.ButtonSortByType.UseVisualStyleBackColor = true;
|
||||
this.ButtonSortByType.Click += new System.EventHandler(this.ButtonSortByType_Click);
|
||||
//
|
||||
// ButtonSortByColor
|
||||
//
|
||||
this.ButtonSortByColor.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.ButtonSortByColor.Location = new System.Drawing.Point(41, 462);
|
||||
this.ButtonSortByColor.Name = "ButtonSortByColor";
|
||||
this.ButtonSortByColor.Size = new System.Drawing.Size(353, 46);
|
||||
this.ButtonSortByColor.TabIndex = 4;
|
||||
this.ButtonSortByColor.Text = "Сортировка по цвету";
|
||||
this.ButtonSortByColor.UseVisualStyleBackColor = true;
|
||||
this.ButtonSortByColor.Click += new System.EventHandler(this.ButtonSortByColor_Click);
|
||||
//
|
||||
// groupBox1
|
||||
//
|
||||
this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
@ -78,7 +104,7 @@
|
||||
this.groupBox1.Controls.Add(this.buttonAddObject);
|
||||
this.groupBox1.Location = new System.Drawing.Point(22, 38);
|
||||
this.groupBox1.Name = "groupBox1";
|
||||
this.groupBox1.Size = new System.Drawing.Size(391, 434);
|
||||
this.groupBox1.Size = new System.Drawing.Size(391, 412);
|
||||
this.groupBox1.TabIndex = 4;
|
||||
this.groupBox1.TabStop = false;
|
||||
this.groupBox1.Text = "Наборы";
|
||||
@ -96,7 +122,7 @@
|
||||
this.listBoxStorages.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.listBoxStorages.FormattingEnabled = true;
|
||||
this.listBoxStorages.ItemHeight = 32;
|
||||
this.listBoxStorages.Location = new System.Drawing.Point(19, 165);
|
||||
this.listBoxStorages.Location = new System.Drawing.Point(19, 148);
|
||||
this.listBoxStorages.Name = "listBoxStorages";
|
||||
this.listBoxStorages.Size = new System.Drawing.Size(353, 196);
|
||||
this.listBoxStorages.TabIndex = 2;
|
||||
@ -105,7 +131,7 @@
|
||||
// buttonDelObject
|
||||
//
|
||||
this.buttonDelObject.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonDelObject.Location = new System.Drawing.Point(19, 374);
|
||||
this.buttonDelObject.Location = new System.Drawing.Point(19, 352);
|
||||
this.buttonDelObject.Name = "buttonDelObject";
|
||||
this.buttonDelObject.Size = new System.Drawing.Size(353, 46);
|
||||
this.buttonDelObject.TabIndex = 1;
|
||||
@ -116,7 +142,7 @@
|
||||
// buttonAddObject
|
||||
//
|
||||
this.buttonAddObject.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonAddObject.Location = new System.Drawing.Point(19, 98);
|
||||
this.buttonAddObject.Location = new System.Drawing.Point(19, 82);
|
||||
this.buttonAddObject.Name = "buttonAddObject";
|
||||
this.buttonAddObject.Size = new System.Drawing.Size(353, 46);
|
||||
this.buttonAddObject.TabIndex = 0;
|
||||
@ -127,7 +153,7 @@
|
||||
// ButtonRefreshCollection
|
||||
//
|
||||
this.ButtonRefreshCollection.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.ButtonRefreshCollection.Location = new System.Drawing.Point(22, 773);
|
||||
this.ButtonRefreshCollection.Location = new System.Drawing.Point(22, 810);
|
||||
this.ButtonRefreshCollection.Name = "ButtonRefreshCollection";
|
||||
this.ButtonRefreshCollection.Size = new System.Drawing.Size(391, 47);
|
||||
this.ButtonRefreshCollection.TabIndex = 3;
|
||||
@ -138,7 +164,7 @@
|
||||
// ButtonRemoveArmoredTransport
|
||||
//
|
||||
this.ButtonRemoveArmoredTransport.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.ButtonRemoveArmoredTransport.Location = new System.Drawing.Point(22, 641);
|
||||
this.ButtonRemoveArmoredTransport.Location = new System.Drawing.Point(22, 717);
|
||||
this.ButtonRemoveArmoredTransport.Name = "ButtonRemoveArmoredTransport";
|
||||
this.ButtonRemoveArmoredTransport.Size = new System.Drawing.Size(391, 82);
|
||||
this.ButtonRemoveArmoredTransport.TabIndex = 2;
|
||||
@ -149,7 +175,7 @@
|
||||
// maskedTextBoxNumber
|
||||
//
|
||||
this.maskedTextBoxNumber.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.maskedTextBoxNumber.Location = new System.Drawing.Point(71, 589);
|
||||
this.maskedTextBoxNumber.Location = new System.Drawing.Point(71, 668);
|
||||
this.maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||
this.maskedTextBoxNumber.Size = new System.Drawing.Size(275, 39);
|
||||
this.maskedTextBoxNumber.TabIndex = 1;
|
||||
@ -159,7 +185,7 @@
|
||||
// ButtonAddArmoredTransport
|
||||
//
|
||||
this.ButtonAddArmoredTransport.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.ButtonAddArmoredTransport.Location = new System.Drawing.Point(22, 492);
|
||||
this.ButtonAddArmoredTransport.Location = new System.Drawing.Point(22, 573);
|
||||
this.ButtonAddArmoredTransport.Name = "ButtonAddArmoredTransport";
|
||||
this.ButtonAddArmoredTransport.Size = new System.Drawing.Size(391, 82);
|
||||
this.ButtonAddArmoredTransport.TabIndex = 0;
|
||||
@ -206,14 +232,14 @@
|
||||
// SaveToolStripMenuItem
|
||||
//
|
||||
this.SaveToolStripMenuItem.Name = "SaveToolStripMenuItem";
|
||||
this.SaveToolStripMenuItem.Size = new System.Drawing.Size(359, 44);
|
||||
this.SaveToolStripMenuItem.Size = new System.Drawing.Size(263, 44);
|
||||
this.SaveToolStripMenuItem.Text = "Сохранить";
|
||||
this.SaveToolStripMenuItem.Click += new System.EventHandler(this.SaveToolStripMenuItem_Click);
|
||||
//
|
||||
// LoadToolStripMenuItem
|
||||
//
|
||||
this.LoadToolStripMenuItem.Name = "LoadToolStripMenuItem";
|
||||
this.LoadToolStripMenuItem.Size = new System.Drawing.Size(359, 44);
|
||||
this.LoadToolStripMenuItem.Size = new System.Drawing.Size(263, 44);
|
||||
this.LoadToolStripMenuItem.Text = "Загрузить";
|
||||
this.LoadToolStripMenuItem.Click += new System.EventHandler(this.LoadToolStripMenuItem_Click);
|
||||
//
|
||||
@ -269,5 +295,7 @@
|
||||
private ToolStripMenuItem LoadToolStripMenuItem;
|
||||
private OpenFileDialog openFileDialog;
|
||||
private SaveFileDialog saveFileDialog;
|
||||
private Button ButtonSortByType;
|
||||
private Button ButtonSortByColor;
|
||||
}
|
||||
}
|
@ -41,15 +41,13 @@ namespace ProjectTank
|
||||
listBoxStorages.Items.Clear();
|
||||
for (int i = 0; i < _storage.Keys.Count; i++)
|
||||
{
|
||||
listBoxStorages.Items.Add(_storage.Keys[i]);
|
||||
listBoxStorages.Items.Add(_storage.Keys[i].Name);
|
||||
}
|
||||
if (listBoxStorages.Items.Count > 0 && (index == -1 || index
|
||||
>= listBoxStorages.Items.Count))
|
||||
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)
|
||||
else if (listBoxStorages.Items.Count > 0 && index > -1 && index < listBoxStorages.Items.Count)
|
||||
{
|
||||
listBoxStorages.SelectedIndex = index;
|
||||
}
|
||||
@ -94,11 +92,11 @@ namespace ProjectTank
|
||||
}
|
||||
string name = listBoxStorages.SelectedItem.ToString() ?? string.Empty;
|
||||
if (MessageBox.Show($"Удалить объект {name}?", "Удаление", MessageBoxButtons.YesNo,
|
||||
MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
{
|
||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||
_storage.DelSet(name);
|
||||
ReloadObjects();
|
||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
@ -139,6 +137,11 @@ namespace ProjectTank
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
_logger.LogWarning($"Не удалось добавить объект: {ex.Message}");
|
||||
}
|
||||
catch (ArgumentException ex)
|
||||
{
|
||||
_logger.LogWarning($"Добавляемый объект уже существует в коллекции {listBoxStorages.SelectedItem.ToString() ?? string.Empty}");
|
||||
MessageBox.Show("Добавляемый объект уже сущесвует в коллекции");
|
||||
}
|
||||
});
|
||||
form.AddEvent(armoredTransportDelegate);
|
||||
form.Show();
|
||||
@ -158,22 +161,15 @@ namespace ProjectTank
|
||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
_logger.LogWarning($"Не удалось удалить объект из набора {listBoxStorages.SelectedItem.ToString()}");
|
||||
return;
|
||||
}
|
||||
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrEmpty(maskedTextBoxNumber.Text) || maskedTextBoxNumber.Text == "_")
|
||||
{
|
||||
MessageBox.Show("Введите корректное значение для номера");
|
||||
_logger.LogWarning($"Не удалось удалить объект из набора {listBoxStorages.SelectedItem.ToString()}");
|
||||
return;
|
||||
}
|
||||
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
||||
if (obj - pos != null)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
@ -191,8 +187,6 @@ namespace ProjectTank
|
||||
MessageBox.Show(ex.Message);
|
||||
_logger.LogWarning($"{ex.Message} из набора {listBoxStorages.SelectedItem.ToString()}");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Обновление рисунка по набору
|
||||
@ -263,5 +257,35 @@ namespace ProjectTank
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Сортировка по сравнителю
|
||||
/// </summary>
|
||||
/// <param name="comparer"></param>
|
||||
private void CompareArmoredTransports(IComparer<DrawningArmoredTransport?> comparer)
|
||||
{
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
obj.Sort(comparer);
|
||||
pictureBoxCollection.Image = obj.ShowArmoredTransports();
|
||||
}
|
||||
/// <summary>
|
||||
/// Сортировка по типу
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonSortByType_Click(object sender, EventArgs e) => CompareArmoredTransports(new ArmoredTransportCompareByType());
|
||||
/// <summary>
|
||||
/// Сортировка по цвету
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonSortByColor_Click(object sender, EventArgs e) => CompareArmoredTransports(new ArmoredTransportCompareByColor());
|
||||
}
|
||||
}
|
||||
|
50
ProjectTank/ProjectTank/ArmoredTransportCompareByColor.cs
Normal file
50
ProjectTank/ProjectTank/ArmoredTransportCompareByColor.cs
Normal file
@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ProjectTank.DrawningObjects;
|
||||
using ProjectTank.Drawnings;
|
||||
using ProjectTank.Entities;
|
||||
|
||||
namespace ProjectTank.Generics
|
||||
{
|
||||
internal class ArmoredTransportCompareByColor : IComparer<DrawningArmoredTransport?>
|
||||
{
|
||||
public int Compare(DrawningArmoredTransport? x, DrawningArmoredTransport? y)
|
||||
{
|
||||
if (x == null || x.EntityArmoredTransport == null)
|
||||
throw new ArgumentNullException(nameof(x));
|
||||
|
||||
if (y == null || y.EntityArmoredTransport == null)
|
||||
throw new ArgumentNullException(nameof(y));
|
||||
|
||||
if (x.EntityArmoredTransport.BodyColor.Name != y.EntityArmoredTransport.BodyColor.Name)
|
||||
{
|
||||
return x.EntityArmoredTransport.BodyColor.GetBrightness().CompareTo(y.EntityArmoredTransport.BodyColor.GetBrightness());
|
||||
}
|
||||
if (x.GetType().Name != y.GetType().Name)
|
||||
|
||||
{
|
||||
if (x is DrawningArmoredTransport)
|
||||
return -1;
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
if (x.GetType().Name == y.GetType().Name && x is DrawningArmoredTransport)
|
||||
{
|
||||
EntityTank EntityX = (EntityTank)x.EntityArmoredTransport;
|
||||
EntityTank EntityY = (EntityTank)y.EntityArmoredTransport;
|
||||
if (EntityX.AdditionalColor.Name != EntityY.AdditionalColor.Name)
|
||||
{
|
||||
return EntityX.AdditionalColor.Name.CompareTo(EntityY.AdditionalColor.Name);
|
||||
}
|
||||
}
|
||||
var speedCompare = x.EntityArmoredTransport.Speed.CompareTo(y.EntityArmoredTransport.Speed);
|
||||
|
||||
if (speedCompare != 0)
|
||||
return speedCompare;
|
||||
|
||||
return x.EntityArmoredTransport.Weight.CompareTo(y.EntityArmoredTransport.Weight);
|
||||
}
|
||||
}
|
||||
}
|
36
ProjectTank/ProjectTank/ArmoredTransportCompareByType.cs
Normal file
36
ProjectTank/ProjectTank/ArmoredTransportCompareByType.cs
Normal file
@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ProjectTank.DrawningObjects;
|
||||
using ProjectTank.Drawnings;
|
||||
|
||||
namespace ProjectTank.Generics
|
||||
{
|
||||
internal class ArmoredTransportCompareByType : IComparer<DrawningArmoredTransport?>
|
||||
{
|
||||
public int Compare(DrawningArmoredTransport? x, DrawningArmoredTransport? y)
|
||||
{
|
||||
if (x == null || x.EntityArmoredTransport == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(x));
|
||||
}
|
||||
if (y == null || y.EntityArmoredTransport == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(y));
|
||||
}
|
||||
if (x.GetType().Name != y.GetType().Name)
|
||||
{
|
||||
return x.GetType().Name.CompareTo(y.GetType().Name);
|
||||
}
|
||||
var speedCompare =
|
||||
x.EntityArmoredTransport.Speed.CompareTo(y.EntityArmoredTransport.Speed);
|
||||
if (speedCompare != 0)
|
||||
{
|
||||
return speedCompare;
|
||||
}
|
||||
return x.EntityArmoredTransport.Weight.CompareTo(y.EntityArmoredTransport.Weight);
|
||||
}
|
||||
}
|
||||
}
|
28
ProjectTank/ProjectTank/ArmoredTransportsCollectionInfo.cs
Normal file
28
ProjectTank/ProjectTank/ArmoredTransportsCollectionInfo.cs
Normal file
@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectTank
|
||||
{
|
||||
internal class ArmoredTransportsCollectionInfo : IEquatable<ArmoredTransportsCollectionInfo>
|
||||
{
|
||||
public string Name { get; private set; }
|
||||
public string Description { get; private set; }
|
||||
public ArmoredTransportsCollectionInfo(string name, string description)
|
||||
{
|
||||
Name = name;
|
||||
Description = description;
|
||||
}
|
||||
public bool Equals(ArmoredTransportsCollectionInfo? other)
|
||||
{
|
||||
return this.Name == other.Name;
|
||||
eegov
commented
Нет проверки, что other не равен null Нет проверки, что other не равен null
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return this.Name.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
@ -51,6 +51,11 @@ namespace ProjectTank.Generics
|
||||
_collection = new SetGeneric<T>(width * height);
|
||||
}
|
||||
/// <summary>
|
||||
/// Сортировка
|
||||
/// </summary>
|
||||
/// <param name="comparer"></param>
|
||||
public void Sort(IComparer<T?> comparer) => _collection.SortSet(comparer);
|
||||
/// <summary>
|
||||
/// Получение объектов коллекции
|
||||
/// </summary>
|
||||
public IEnumerable<T?> GetArmoredTransports => _collection.GetArmoredTransports();
|
||||
@ -66,7 +71,7 @@ namespace ProjectTank.Generics
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return collect?._collection.Insert(obj)??false;
|
||||
return collect?._collection.Insert(obj, new DrawiningArmoredTransportEqutables()) ?? false;
|
||||
}
|
||||
/// <summary>
|
||||
/// Перегрузка оператора вычитания
|
||||
|
@ -15,11 +15,11 @@ namespace ProjectTank.Generics
|
||||
/// <summary>
|
||||
/// Словарь (хранилище)
|
||||
/// </summary>
|
||||
readonly Dictionary<string, ArmoredTransportsGenericCollection<DrawningArmoredTransport, DrawningObjectArmoredTransport>> _armoredTransportStorages;
|
||||
readonly Dictionary<ArmoredTransportsCollectionInfo, ArmoredTransportsGenericCollection<DrawningArmoredTransport, DrawningObjectArmoredTransport>> _armoredTransportStorages;
|
||||
/// <summary>
|
||||
/// Возвращение списка названий наборов
|
||||
/// </summary>
|
||||
public List<string> Keys => _armoredTransportStorages.Keys.ToList();
|
||||
public List<ArmoredTransportsCollectionInfo> Keys => _armoredTransportStorages.Keys.ToList();
|
||||
/// <summary>
|
||||
/// Ширина окна отрисовки
|
||||
/// </summary>
|
||||
@ -47,7 +47,7 @@ namespace ProjectTank.Generics
|
||||
/// <param name="pictureHeight"></param>
|
||||
public ArmoredTransportsGenericStorage(int pictureWidth, int pictureHeight)
|
||||
{
|
||||
_armoredTransportStorages = new Dictionary<string, ArmoredTransportsGenericCollection<DrawningArmoredTransport, DrawningObjectArmoredTransport>>();
|
||||
_armoredTransportStorages = new Dictionary<ArmoredTransportsCollectionInfo, ArmoredTransportsGenericCollection<DrawningArmoredTransport, DrawningObjectArmoredTransport>>();
|
||||
_pictureWidth = pictureWidth;
|
||||
_pictureHeight = pictureHeight;
|
||||
}
|
||||
@ -57,19 +57,25 @@ namespace ProjectTank.Generics
|
||||
/// <param name="name">Название набора</param>
|
||||
public void AddSet(string name)
|
||||
{
|
||||
_armoredTransportStorages.Add(name, new ArmoredTransportsGenericCollection<DrawningArmoredTransport, DrawningObjectArmoredTransport>(_pictureWidth, _pictureHeight));
|
||||
if (_armoredTransportStorages.ContainsKey(new ArmoredTransportsCollectionInfo(name, string.Empty)))
|
||||
{
|
||||
MessageBox.Show("Словарь уже имеет объект с таким названием", "Ошибка",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
_armoredTransportStorages.Add(new ArmoredTransportsCollectionInfo(name, string.Empty),
|
||||
new ArmoredTransportsGenericCollection<DrawningArmoredTransport,
|
||||
DrawningObjectArmoredTransport>(_pictureWidth, _pictureHeight));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Удаление набора
|
||||
/// </summary>
|
||||
/// <param name="name">Название набора</param>
|
||||
public void DelSet(string name)
|
||||
{
|
||||
if (!_armoredTransportStorages.ContainsKey(name))
|
||||
{
|
||||
if (_armoredTransportStorages[new ArmoredTransportsCollectionInfo(name, string.Empty)] == null)
|
||||
return;
|
||||
}
|
||||
_armoredTransportStorages.Remove(name);
|
||||
_armoredTransportStorages.Remove(new ArmoredTransportsCollectionInfo(name, string.Empty));
|
||||
}
|
||||
/// <summary>
|
||||
/// Доступ к набору
|
||||
@ -80,10 +86,9 @@ namespace ProjectTank.Generics
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_armoredTransportStorages.ContainsKey(ind))
|
||||
{
|
||||
return _armoredTransportStorages[ind];
|
||||
}
|
||||
ArmoredTransportsCollectionInfo indObj = new ArmoredTransportsCollectionInfo(ind, string.Empty);
|
||||
if (_armoredTransportStorages.ContainsKey(indObj))
|
||||
return _armoredTransportStorages[indObj];
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -99,14 +104,14 @@ namespace ProjectTank.Generics
|
||||
File.Delete(filename);
|
||||
}
|
||||
StringBuilder data = new();
|
||||
foreach (KeyValuePair<string,ArmoredTransportsGenericCollection<DrawningArmoredTransport, DrawningObjectArmoredTransport>> record in _armoredTransportStorages)
|
||||
foreach (KeyValuePair<ArmoredTransportsCollectionInfo, ArmoredTransportsGenericCollection<DrawningArmoredTransport, DrawningObjectArmoredTransport>> record in _armoredTransportStorages)
|
||||
{ //создается тип пара ключ значение, который представляет строку и на каждой итерации берется элемент record коллекции _armoredTransportStorages
|
||||
StringBuilder records = new();
|
||||
foreach (DrawningArmoredTransport? elem in record.Value.GetArmoredTransports) // проход по списку коллекции с получением значения объекта
|
||||
{
|
||||
records.Append($"{elem?.GetDataForSave(_separatorForObject)}{_separatorRecords}"); //добавление в стрингбилдер свойств объекта с разделителем : и в конце ;
|
||||
}
|
||||
data.AppendLine($"{record.Key}{_separatorForKeyValue}{records}"); // добавление значения словаря ключа в начало и разделение разделитем
|
||||
data.AppendLine($"{record.Key.Name}{_separatorForKeyValue}{records}"); // добавление значения словаря ключа в начало и разделение разделитем
|
||||
}
|
||||
if (data.Length == 0)
|
||||
{
|
||||
@ -170,7 +175,7 @@ namespace ProjectTank.Generics
|
||||
}
|
||||
}
|
||||
}
|
||||
_armoredTransportStorages.Add(record[0], collection);
|
||||
_armoredTransportStorages.Add(new ArmoredTransportsCollectionInfo(record[0],string.Empty), collection);
|
||||
str = sr.ReadLine();
|
||||
} while (str != null);
|
||||
}
|
||||
|
@ -0,0 +1,57 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ProjectTank.Drawnings;
|
||||
using ProjectTank.Entities;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using ProjectTank.DrawningObjects;
|
||||
|
||||
namespace ProjectTank.Generics
|
||||
{
|
||||
internal class DrawiningArmoredTransportEqutables : IEqualityComparer<DrawningArmoredTransport?>
|
||||
{
|
||||
public bool Equals(DrawningArmoredTransport? x, DrawningArmoredTransport? y)
|
||||
{
|
||||
if (x == null || x.EntityArmoredTransport == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(x));
|
||||
}
|
||||
if (y == null || y.EntityArmoredTransport == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(y));
|
||||
}
|
||||
if (x.GetType().Name != y.GetType().Name)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x.EntityArmoredTransport.Speed != y.EntityArmoredTransport.Speed)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x.EntityArmoredTransport.Weight != y.EntityArmoredTransport.Weight)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x.EntityArmoredTransport.BodyColor != y.EntityArmoredTransport.BodyColor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x is DrawningTank && y is DrawningTank)
|
||||
{
|
||||
EntityTank EntityX = (EntityTank)x.EntityArmoredTransport;
|
||||
EntityTank EntityY = (EntityTank)y.EntityArmoredTransport;
|
||||
eegov
commented
Нет сравнения по дополнительному цвету Нет сравнения по дополнительному цвету
|
||||
if (EntityX.MachineGun != EntityY.MachineGun)
|
||||
return false;
|
||||
if (EntityX.Gun != EntityY.Gun)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public int GetHashCode([DisallowNull] DrawningArmoredTransport obj)
|
||||
{
|
||||
return obj.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
@ -37,15 +37,20 @@ namespace ProjectTank.Generics
|
||||
_places = new List<T?>(count);
|
||||
}
|
||||
/// <summary>
|
||||
/// Сортировка набора объектов
|
||||
/// </summary>
|
||||
/// <param name="comparer"></param>
|
||||
public void SortSet(IComparer<T?> comparer) => _places.Sort(comparer);
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор
|
||||
/// </summary>
|
||||
/// <param name="armoredTransport">Добавляемый броне-транспорт</param>
|
||||
/// <returns></returns>
|
||||
public bool Insert(T armoredTransport)
|
||||
public bool Insert(T armoredTransport, IEqualityComparer<T>? equal = null)
|
||||
{
|
||||
if (_places.Count == _maxCount)
|
||||
throw new StorageOverflowException(_maxCount);
|
||||
Insert(armoredTransport, 0);
|
||||
Insert(armoredTransport, 0, equal);
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
@ -54,12 +59,17 @@ namespace ProjectTank.Generics
|
||||
/// <param name="car">Добавляемый броне-транспорт</param>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns></returns>
|
||||
public bool Insert(T armoredTransport, int position)
|
||||
public bool Insert(T armoredTransport, int position, IEqualityComparer<T>? equal = null)
|
||||
{
|
||||
if (_places.Count == _maxCount)
|
||||
throw new StorageOverflowException(_maxCount);
|
||||
if (!(position >= 0 && position <= Count))
|
||||
return false;
|
||||
if (equal != null)
|
||||
{
|
||||
if (_places.Contains(armoredTransport, equal))
|
||||
throw new ArgumentException(nameof(armoredTransport));
|
||||
}
|
||||
_places.Insert(position, armoredTransport);
|
||||
return true;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user
Требовалось сортировать по критериям: цвет, скорость, вес