Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9323704e05 |
@@ -1,37 +1,37 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/>
|
||||
</startup>
|
||||
<runtime>
|
||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
|
||||
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
|
||||
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0"/>
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="Microsoft.Extensions.Primitives" publicKeyToken="adb9793829ddae60" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0" />
|
||||
<assemblyIdentity name="Microsoft.Extensions.Primitives" publicKeyToken="adb9793829ddae60" culture="neutral"/>
|
||||
<bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0"/>
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="Microsoft.Extensions.Logging.Abstractions" publicKeyToken="adb9793829ddae60" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0" />
|
||||
<assemblyIdentity name="Microsoft.Extensions.Logging.Abstractions" publicKeyToken="adb9793829ddae60" culture="neutral"/>
|
||||
<bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0"/>
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="Microsoft.Extensions.Logging" publicKeyToken="adb9793829ddae60" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0" />
|
||||
<assemblyIdentity name="Microsoft.Extensions.Logging" publicKeyToken="adb9793829ddae60" culture="neutral"/>
|
||||
<bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0"/>
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="Microsoft.Extensions.DependencyInjection.Abstractions" publicKeyToken="adb9793829ddae60" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0" />
|
||||
<assemblyIdentity name="Microsoft.Extensions.DependencyInjection.Abstractions" publicKeyToken="adb9793829ddae60" culture="neutral"/>
|
||||
<bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0"/>
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="Microsoft.Extensions.Configuration.Abstractions" publicKeyToken="adb9793829ddae60" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0" />
|
||||
<assemblyIdentity name="Microsoft.Extensions.Configuration.Abstractions" publicKeyToken="adb9793829ddae60" culture="neutral"/>
|
||||
<bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0"/>
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Diagnostics.DiagnosticSource" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0" />
|
||||
<assemblyIdentity name="System.Diagnostics.DiagnosticSource" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral"/>
|
||||
<bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0"/>
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ProjectBomber.DrawningObjects;
|
||||
using ProjectBomber.Entities;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace ProjectBomber.Generics
|
||||
{
|
||||
internal class DrawiningPlaneEqutables : IEqualityComparer<DrawningBomber>
|
||||
{
|
||||
public bool Equals(DrawningBomber x, DrawningBomber y)
|
||||
{
|
||||
if (x == null || x.EntityBomber == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(x));
|
||||
}
|
||||
if (y == null || y.EntityBomber == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(y));
|
||||
}
|
||||
if (x.GetType().Name != y.GetType().Name)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x.EntityBomber.Speed != y.EntityBomber.Speed)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x.EntityBomber.Weight != y.EntityBomber.Weight)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x.EntityBomber.BodyColor != y.EntityBomber.BodyColor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x is DrawningBomberAdvanced && y is DrawningBomberAdvanced)
|
||||
{
|
||||
EntityBomberAdvanced EntityX = (EntityBomberAdvanced)x.EntityBomber;
|
||||
EntityBomberAdvanced EntityY = (EntityBomberAdvanced)y.EntityBomber;
|
||||
if (EntityX.Bombs != EntityY.Bombs)
|
||||
return false;
|
||||
if (EntityX.FuelTanks != EntityY.FuelTanks)
|
||||
return false;
|
||||
if (EntityX.Line != EntityY.Line)
|
||||
return false;
|
||||
if (EntityX.AdditionalColor != EntityY.AdditionalColor)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public int GetHashCode(DrawningBomber obj)
|
||||
{
|
||||
return obj.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -29,8 +29,6 @@
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.groupBox1 = new System.Windows.Forms.GroupBox();
|
||||
this.ButtonSortByColor = new System.Windows.Forms.Button();
|
||||
this.ButtonSortByType = new System.Windows.Forms.Button();
|
||||
this.groupBoxSet = new System.Windows.Forms.GroupBox();
|
||||
this.ButtonDelObject = new System.Windows.Forms.Button();
|
||||
this.ListBoxStorages = new System.Windows.Forms.ListBox();
|
||||
@@ -49,13 +47,12 @@
|
||||
this.saveFileDialog = new System.Windows.Forms.SaveFileDialog();
|
||||
this.groupBox1.SuspendLayout();
|
||||
this.groupBoxSet.SuspendLayout();
|
||||
this.menuStrip.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// groupBox1
|
||||
//
|
||||
this.groupBox1.Controls.Add(this.ButtonSortByColor);
|
||||
this.groupBox1.Controls.Add(this.ButtonSortByType);
|
||||
this.groupBox1.Controls.Add(this.groupBoxSet);
|
||||
this.groupBox1.Controls.Add(this.ButtonRefreshCollection);
|
||||
this.groupBox1.Controls.Add(this.ButtonRemovePlane);
|
||||
@@ -69,35 +66,15 @@
|
||||
this.groupBox1.TabStop = false;
|
||||
this.groupBox1.Text = "Инструменты";
|
||||
//
|
||||
// ButtonSortByColor
|
||||
//
|
||||
this.ButtonSortByColor.Location = new System.Drawing.Point(20, 333);
|
||||
this.ButtonSortByColor.Name = "ButtonSortByColor";
|
||||
this.ButtonSortByColor.Size = new System.Drawing.Size(181, 28);
|
||||
this.ButtonSortByColor.TabIndex = 7;
|
||||
this.ButtonSortByColor.Text = "Сортировка по цвету";
|
||||
this.ButtonSortByColor.UseVisualStyleBackColor = true;
|
||||
this.ButtonSortByColor.Click += new System.EventHandler(this.ButtonSortByColor_Click);
|
||||
//
|
||||
// ButtonSortByType
|
||||
//
|
||||
this.ButtonSortByType.Location = new System.Drawing.Point(20, 294);
|
||||
this.ButtonSortByType.Name = "ButtonSortByType";
|
||||
this.ButtonSortByType.Size = new System.Drawing.Size(180, 33);
|
||||
this.ButtonSortByType.TabIndex = 6;
|
||||
this.ButtonSortByType.Text = "Сортировка по типу";
|
||||
this.ButtonSortByType.UseVisualStyleBackColor = true;
|
||||
this.ButtonSortByType.Click += new System.EventHandler(this.ButtonSortByType_Click);
|
||||
//
|
||||
// groupBoxSet
|
||||
//
|
||||
this.groupBoxSet.Controls.Add(this.ButtonDelObject);
|
||||
this.groupBoxSet.Controls.Add(this.ListBoxStorages);
|
||||
this.groupBoxSet.Controls.Add(this.ButtonAddObject);
|
||||
this.groupBoxSet.Controls.Add(this.textBoxStorageName);
|
||||
this.groupBoxSet.Location = new System.Drawing.Point(21, 19);
|
||||
this.groupBoxSet.Location = new System.Drawing.Point(21, 25);
|
||||
this.groupBoxSet.Name = "groupBoxSet";
|
||||
this.groupBoxSet.Size = new System.Drawing.Size(180, 269);
|
||||
this.groupBoxSet.Size = new System.Drawing.Size(180, 274);
|
||||
this.groupBoxSet.TabIndex = 4;
|
||||
this.groupBoxSet.TabStop = false;
|
||||
this.groupBoxSet.Text = "Наборы";
|
||||
@@ -140,9 +117,9 @@
|
||||
//
|
||||
// ButtonRefreshCollection
|
||||
//
|
||||
this.ButtonRefreshCollection.Location = new System.Drawing.Point(21, 492);
|
||||
this.ButtonRefreshCollection.Location = new System.Drawing.Point(20, 492);
|
||||
this.ButtonRefreshCollection.Name = "ButtonRefreshCollection";
|
||||
this.ButtonRefreshCollection.Size = new System.Drawing.Size(177, 41);
|
||||
this.ButtonRefreshCollection.Size = new System.Drawing.Size(178, 41);
|
||||
this.ButtonRefreshCollection.TabIndex = 3;
|
||||
this.ButtonRefreshCollection.Text = "Обновить коллекцию";
|
||||
this.ButtonRefreshCollection.UseVisualStyleBackColor = true;
|
||||
@@ -160,16 +137,16 @@
|
||||
//
|
||||
// maskedTextBoxNumber
|
||||
//
|
||||
this.maskedTextBoxNumber.Location = new System.Drawing.Point(21, 413);
|
||||
this.maskedTextBoxNumber.Location = new System.Drawing.Point(18, 351);
|
||||
this.maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||
this.maskedTextBoxNumber.Size = new System.Drawing.Size(180, 20);
|
||||
this.maskedTextBoxNumber.TabIndex = 1;
|
||||
//
|
||||
// ButtonAddPlane
|
||||
//
|
||||
this.ButtonAddPlane.Location = new System.Drawing.Point(21, 367);
|
||||
this.ButtonAddPlane.Location = new System.Drawing.Point(18, 305);
|
||||
this.ButtonAddPlane.Name = "ButtonAddPlane";
|
||||
this.ButtonAddPlane.Size = new System.Drawing.Size(180, 40);
|
||||
this.ButtonAddPlane.Size = new System.Drawing.Size(185, 40);
|
||||
this.ButtonAddPlane.TabIndex = 0;
|
||||
this.ButtonAddPlane.Text = "Добавить самолет";
|
||||
this.ButtonAddPlane.UseVisualStyleBackColor = true;
|
||||
@@ -178,6 +155,8 @@
|
||||
// menuStrip
|
||||
//
|
||||
this.menuStrip.Dock = System.Windows.Forms.DockStyle.Bottom;
|
||||
this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.fileToolStripMenuItem});
|
||||
this.menuStrip.Location = new System.Drawing.Point(3, 536);
|
||||
this.menuStrip.Name = "menuStrip";
|
||||
this.menuStrip.Size = new System.Drawing.Size(204, 24);
|
||||
@@ -196,23 +175,23 @@
|
||||
// saveToolStripMenuItem
|
||||
//
|
||||
this.saveToolStripMenuItem.Name = "saveToolStripMenuItem";
|
||||
this.saveToolStripMenuItem.Size = new System.Drawing.Size(100, 22);
|
||||
this.saveToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
|
||||
this.saveToolStripMenuItem.Text = "Save";
|
||||
this.saveToolStripMenuItem.Click += new System.EventHandler(this.SaveToolStripMenuItem_Click);
|
||||
//
|
||||
// loadToolStripMenuItem
|
||||
//
|
||||
this.loadToolStripMenuItem.Name = "loadToolStripMenuItem";
|
||||
this.loadToolStripMenuItem.Size = new System.Drawing.Size(100, 22);
|
||||
this.loadToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
|
||||
this.loadToolStripMenuItem.Text = "Load";
|
||||
this.loadToolStripMenuItem.Click += new System.EventHandler(this.LoadToolStripMenuItem_Click);
|
||||
//
|
||||
// pictureBoxCollection
|
||||
//
|
||||
this.pictureBoxCollection.Location = new System.Drawing.Point(1, 2);
|
||||
this.pictureBoxCollection.Location = new System.Drawing.Point(0, 2);
|
||||
this.pictureBoxCollection.Name = "pictureBoxCollection";
|
||||
this.pictureBoxCollection.Size = new System.Drawing.Size(600, 565);
|
||||
this.pictureBoxCollection.TabIndex = 0;
|
||||
this.pictureBoxCollection.TabIndex = 1;
|
||||
this.pictureBoxCollection.TabStop = false;
|
||||
//
|
||||
// openFileDialog
|
||||
@@ -238,6 +217,8 @@
|
||||
this.groupBox1.PerformLayout();
|
||||
this.groupBoxSet.ResumeLayout(false);
|
||||
this.groupBoxSet.PerformLayout();
|
||||
this.menuStrip.ResumeLayout(false);
|
||||
this.menuStrip.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
@@ -262,7 +243,5 @@
|
||||
private System.Windows.Forms.ToolStripMenuItem loadToolStripMenuItem;
|
||||
private System.Windows.Forms.OpenFileDialog openFileDialog;
|
||||
private System.Windows.Forms.SaveFileDialog saveFileDialog;
|
||||
private System.Windows.Forms.Button ButtonSortByColor;
|
||||
private System.Windows.Forms.Button ButtonSortByType;
|
||||
}
|
||||
}
|
||||
@@ -46,7 +46,7 @@ namespace ProjectBomber
|
||||
ListBoxStorages.Items.Clear();
|
||||
for (int i = 0; i < _storage.Keys.Count; i++)
|
||||
{
|
||||
ListBoxStorages.Items.Add(_storage.Keys[i].Name);
|
||||
ListBoxStorages.Items.Add(_storage.Keys[i]);
|
||||
}
|
||||
if (ListBoxStorages.Items.Count > 0 && (index == -1 || index
|
||||
>= ListBoxStorages.Items.Count))
|
||||
@@ -268,25 +268,5 @@ _storage[ListBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowPlanes()
|
||||
}
|
||||
}
|
||||
}
|
||||
private void ButtonSortByType_Click(object sender, EventArgs e) => ComparePlanes(new PlaneCompareByType());
|
||||
private void ButtonSortByColor_Click(object sender, EventArgs e) => ComparePlanes(new PlaneCompareByColor());
|
||||
/// <summary>
|
||||
/// Сортировка по сравнителю
|
||||
/// </summary>
|
||||
/// <param name="comparer"></param>
|
||||
private void ComparePlanes(IComparer<DrawningBomber> comparer)
|
||||
{
|
||||
if (ListBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var obj = _storage[ListBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
obj.Sort(comparer);
|
||||
pictureBoxCollection.Image = obj.ShowPlanes();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,9 +120,6 @@
|
||||
<metadata name="menuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
<metadata name="menuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
<metadata name="openFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>132, 17</value>
|
||||
</metadata>
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ProjectBomber.Entities;
|
||||
using ProjectBomber.DrawningObjects;
|
||||
|
||||
namespace ProjectBomber
|
||||
{
|
||||
internal class PlaneCompareByColor : IComparer<DrawningBomber>
|
||||
{
|
||||
public int Compare(DrawningBomber x, DrawningBomber y)
|
||||
{
|
||||
if (x == null || x.EntityBomber == null)
|
||||
throw new ArgumentNullException(nameof(x));
|
||||
if (y == null || y.EntityBomber == null)
|
||||
throw new ArgumentNullException(nameof(y));
|
||||
if (x.EntityBomber.BodyColor.Name != y.EntityBomber.BodyColor.Name)
|
||||
{
|
||||
return x.EntityBomber.BodyColor.Name.CompareTo(y.EntityBomber.BodyColor.Name);
|
||||
}
|
||||
if (x.GetType().Name != y.GetType().Name)
|
||||
{
|
||||
if (x is DrawningBomber)
|
||||
return -1;
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
if (x.GetType().Name == y.GetType().Name && x is DrawningBomberAdvanced)
|
||||
{
|
||||
EntityBomberAdvanced EntityX = (EntityBomberAdvanced)x.EntityBomber;
|
||||
EntityBomberAdvanced EntityY = (EntityBomberAdvanced)y.EntityBomber;
|
||||
if (EntityX.AdditionalColor.Name != EntityY.AdditionalColor.Name)
|
||||
{
|
||||
return EntityX.AdditionalColor.Name.CompareTo(EntityY.AdditionalColor.Name);
|
||||
}
|
||||
}
|
||||
var speedCompare = x.EntityBomber.Speed.CompareTo(y.EntityBomber.Speed);
|
||||
if (speedCompare != 0)
|
||||
return speedCompare;
|
||||
return x.EntityBomber.Weight.CompareTo(y.EntityBomber.Weight);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ProjectBomber.Entities;
|
||||
using ProjectBomber.DrawningObjects;
|
||||
|
||||
namespace ProjectBomber.Generics
|
||||
{
|
||||
internal class PlaneCompareByType : IComparer<DrawningBomber>
|
||||
{
|
||||
public int Compare(DrawningBomber x, DrawningBomber y)
|
||||
{
|
||||
if (x == null || x.EntityBomber == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(x));
|
||||
}
|
||||
if (y == null || y.EntityBomber == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(y));
|
||||
}
|
||||
if (x.GetType().Name != y.GetType().Name)
|
||||
{
|
||||
return x.GetType().Name.CompareTo(y.GetType().Name);
|
||||
}
|
||||
var speedCompare = x.EntityBomber.Speed.CompareTo(y.EntityBomber.Speed);
|
||||
if (speedCompare != 0)
|
||||
{
|
||||
return speedCompare;
|
||||
}
|
||||
return x.EntityBomber.Weight.CompareTo(y.EntityBomber.Weight);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectBomber
|
||||
{
|
||||
internal class PlanesCollectionInfo : IEquatable<PlanesCollectionInfo>
|
||||
{
|
||||
public string Name { get; private set; }
|
||||
public string Description { get; private set; }
|
||||
public PlanesCollectionInfo(string name, string description)
|
||||
{
|
||||
Name = name;
|
||||
Description = description;
|
||||
}
|
||||
public bool Equals(PlanesCollectionInfo other)
|
||||
{
|
||||
return Name == other.Name;
|
||||
/* throw new NotImplementedException();*/
|
||||
}
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return this.Name.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -52,11 +52,6 @@ namespace ProjectBomber.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> GetPlanes => _collection.GetPlanes();
|
||||
@@ -73,7 +68,7 @@ namespace ProjectBomber.Generics
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return collect?._collection.Insert(obj, new DrawiningPlaneEqutables()) ?? -1;
|
||||
return collect?._collection.Insert(obj) ?? -1;
|
||||
}
|
||||
/// <summary>
|
||||
/// Перегрузка оператора вычитания
|
||||
|
||||
@@ -4,7 +4,6 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using ProjectBomber.DrawningObjects;
|
||||
using ProjectBomber.MovementStrategy;
|
||||
|
||||
@@ -18,12 +17,12 @@ namespace ProjectBomber.Generics
|
||||
/// <summary>
|
||||
/// Словарь (хранилище)
|
||||
/// </summary>
|
||||
readonly Dictionary<PlanesCollectionInfo, PlanesGenericCollection<DrawningBomber,
|
||||
readonly Dictionary<string, PlanesGenericCollection<DrawningBomber,
|
||||
DrawningObjectBomber>> _planeStorages;
|
||||
/// <summary>
|
||||
/// Возвращение списка названий наборов
|
||||
/// </summary>
|
||||
public List<PlanesCollectionInfo> Keys => _planeStorages.Keys.ToList();
|
||||
public List<string> Keys => _planeStorages.Keys.ToList();
|
||||
/// <summary>
|
||||
/// Ширина окна отрисовки
|
||||
/// </summary>
|
||||
@@ -39,7 +38,7 @@ namespace ProjectBomber.Generics
|
||||
/// <param name="pictureHeight"></param>
|
||||
public PlanesGenericStorage(int pictureWidth, int pictureHeight)
|
||||
{
|
||||
_planeStorages = new Dictionary<PlanesCollectionInfo,
|
||||
_planeStorages = new Dictionary<string,
|
||||
PlanesGenericCollection<DrawningBomber, DrawningObjectBomber>>();
|
||||
_pictureWidth = pictureWidth;
|
||||
_pictureHeight = pictureHeight;
|
||||
@@ -62,14 +61,14 @@ namespace ProjectBomber.Generics
|
||||
/// <param name="name">Название набора</param>
|
||||
public void AddSet(string name)
|
||||
{
|
||||
if (_planeStorages.ContainsKey(new PlanesCollectionInfo(name, string.Empty)))
|
||||
// Создаем новый набор и добавляем его в словарь
|
||||
if (!_planeStorages.ContainsKey(name))
|
||||
{
|
||||
MessageBox.Show("Словарь уже содержит набор с таким названием", "Ошибка",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
_planeStorages[name] = new PlanesGenericCollection<DrawningBomber, DrawningObjectBomber>(_pictureWidth, _pictureHeight);
|
||||
}
|
||||
else
|
||||
{
|
||||
_planeStorages.Add(new PlanesCollectionInfo(name, string.Empty), new PlanesGenericCollection<DrawningBomber, DrawningObjectBomber>(_pictureWidth, _pictureHeight));
|
||||
throw new ArgumentException("Набор с таким именем уже существует");
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
@@ -78,9 +77,15 @@ namespace ProjectBomber.Generics
|
||||
/// <param name="name">Название набора</param>
|
||||
public void DelSet(string name)
|
||||
{
|
||||
if (!_planeStorages.ContainsKey(new PlanesCollectionInfo(name, string.Empty)))
|
||||
return;
|
||||
_planeStorages.Remove(new PlanesCollectionInfo(name, string.Empty));
|
||||
// Удаляем набор из словаря по имени
|
||||
if (_planeStorages.ContainsKey(name))
|
||||
{
|
||||
_planeStorages.Remove(name);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ArgumentException("Набор с таким именем не найден.");
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Доступ к набору
|
||||
@@ -91,10 +96,14 @@ namespace ProjectBomber.Generics
|
||||
{
|
||||
get
|
||||
{
|
||||
PlanesCollectionInfo indObj = new PlanesCollectionInfo(ind, string.Empty);
|
||||
if (_planeStorages.ContainsKey(indObj))
|
||||
return _planeStorages[indObj];
|
||||
return null;
|
||||
if (_planeStorages.ContainsKey(ind))
|
||||
{
|
||||
return _planeStorages[ind];
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new KeyNotFoundException($"Набор с именем '{ind}' не найден.");
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
@@ -111,7 +120,7 @@ namespace ProjectBomber.Generics
|
||||
File.Delete(filename);
|
||||
}
|
||||
StringBuilder data = new StringBuilder();
|
||||
foreach (KeyValuePair<PlanesCollectionInfo,
|
||||
foreach (KeyValuePair<string,
|
||||
PlanesGenericCollection<DrawningBomber, DrawningObjectBomber>> record in _planeStorages)
|
||||
{
|
||||
StringBuilder records = new StringBuilder();
|
||||
@@ -119,7 +128,7 @@ namespace ProjectBomber.Generics
|
||||
{
|
||||
records.Append($"{elem?.GetDataForSave(_separatorForObject)}{_separatorRecords}");
|
||||
}
|
||||
data.AppendLine($"{record.Key.Name}{_separatorForKeyValue}{records}");
|
||||
data.AppendLine($"{record.Key}{_separatorForKeyValue}{records}");
|
||||
}
|
||||
if (data.Length == 0)
|
||||
{
|
||||
@@ -138,34 +147,40 @@ namespace ProjectBomber.Generics
|
||||
public void LoadData(string filename)
|
||||
{
|
||||
if (!File.Exists(filename))
|
||||
throw new FileNotFoundException("Файл не найден");
|
||||
|
||||
using (StreamReader sr = new StreamReader(filename))
|
||||
{
|
||||
if (sr.ReadLine() != "PlanesStorage")
|
||||
throw new FormatException("Неверный формат данных");
|
||||
|
||||
string str = sr.ReadLine();
|
||||
var strs = str.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (strs == null || strs.Length == 0)
|
||||
throw new FileNotFoundException("Файл не найден");
|
||||
}
|
||||
using (StreamReader reader = new StreamReader(filename))
|
||||
{
|
||||
string cheker = reader.ReadLine();
|
||||
if (cheker == null || cheker.Length == 0)
|
||||
{
|
||||
throw new NullReferenceException("Нет данных для загрузки");
|
||||
}
|
||||
if (!cheker.StartsWith("PlanesStorage"))
|
||||
{
|
||||
//если нет такой записи, то это не те данные
|
||||
throw new InvalidDataException("Неверный формат данных");
|
||||
}
|
||||
_planeStorages.Clear();
|
||||
string strs;
|
||||
bool firstinit = true;
|
||||
while ((strs = reader.ReadLine()) != null)
|
||||
{
|
||||
if (strs == null && firstinit)
|
||||
{
|
||||
throw new Exception("Нет данных для загрузки");
|
||||
}
|
||||
_planeStorages.Clear();
|
||||
do
|
||||
if (strs == null)
|
||||
{
|
||||
string[] record = str.Split(new[] { _separatorForKeyValue }, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (record.Length != 2)
|
||||
{
|
||||
str = sr.ReadLine();
|
||||
continue;
|
||||
break;
|
||||
}
|
||||
PlanesGenericCollection<DrawningBomber, DrawningObjectBomber>
|
||||
collection = new PlanesGenericCollection<DrawningBomber, DrawningObjectBomber>(_pictureWidth, _pictureHeight);
|
||||
string[] set = record[1].Split(new[] { _separatorRecords, }, StringSplitOptions.RemoveEmptyEntries);
|
||||
foreach (string elem in set)
|
||||
firstinit = false;
|
||||
string name = strs.Split(_separatorForKeyValue)[0];
|
||||
PlanesGenericCollection<DrawningBomber, DrawningObjectBomber> collection = new PlanesGenericCollection<DrawningBomber, DrawningObjectBomber>(_pictureWidth, _pictureHeight);
|
||||
foreach (string data in strs.Split(_separatorForKeyValue)[1].Split(_separatorRecords))
|
||||
{
|
||||
DrawningBomber plane = elem?.CreateDrawningPlane(_separatorForObject, _pictureWidth, _pictureHeight);
|
||||
DrawningBomber plane = data?.CreateDrawningPlane(_separatorForObject, _pictureWidth, _pictureHeight);
|
||||
if (plane != null)
|
||||
{
|
||||
try { _ = collection + plane; }
|
||||
@@ -179,9 +194,8 @@ namespace ProjectBomber.Generics
|
||||
}
|
||||
}
|
||||
}
|
||||
_planeStorages.Add(new PlanesCollectionInfo(record[0], string.Empty), collection);
|
||||
str = sr.ReadLine();
|
||||
} while (str != null);
|
||||
_planeStorages.Add(name, collection);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,9 +49,6 @@
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="JetBrains.Annotations, Version=4242.42.42.42, Culture=neutral, PublicKeyToken=1010a0d8d6380325, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\JetBrains.Annotations.2023.3.0\lib\net20\JetBrains.Annotations.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Bcl.AsyncInterfaces, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Bcl.AsyncInterfaces.8.0.0\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll</HintPath>
|
||||
</Reference>
|
||||
@@ -165,7 +162,6 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="AbstractStrategy.cs" />
|
||||
<Compile Include="Direction.cs" />
|
||||
<Compile Include="DrawiningPlaneEqutables.cs" />
|
||||
<Compile Include="DrawningBomber.cs" />
|
||||
<Compile Include="DrawningBomberAdvanced.cs" />
|
||||
<Compile Include="DrawningObjectBomber.cs" />
|
||||
@@ -194,10 +190,7 @@
|
||||
<Compile Include="MoveToBottomRight.cs" />
|
||||
<Compile Include="MoveToCenter.cs" />
|
||||
<Compile Include="ObjectParameters.cs" />
|
||||
<Compile Include="PlaneCompareByColor.cs" />
|
||||
<Compile Include="PlaneCompareByType.cs" />
|
||||
<Compile Include="PlaneNotFoundException.cs" />
|
||||
<Compile Include="PlanesCollectionInfo.cs" />
|
||||
<Compile Include="PlanesGenericCollection.cs" />
|
||||
<Compile Include="PlanesGenericStorage.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
|
||||
@@ -35,42 +35,69 @@ namespace ProjectBomber.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="plane">Добавляемый самолет</param>
|
||||
/// <returns></returns>
|
||||
public int Insert(T plane, IEqualityComparer<T> equal = null)
|
||||
public int Insert(T plane)
|
||||
{
|
||||
if (_places.Count == _maxCount)
|
||||
throw new StorageOverflowException(_maxCount);
|
||||
Insert(plane, 0, equal);
|
||||
if (_places.Count == 0)
|
||||
{
|
||||
_places.Add(plane);
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_places.Count < _maxCount)
|
||||
{
|
||||
_places.Add(plane);
|
||||
for (int i = 0; i < _places.Count; i++)
|
||||
{
|
||||
T temp = _places[i];
|
||||
_places[i] = _places[_places.Count - 1];
|
||||
_places[_places.Count - 1] = temp;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
throw new StorageOverflowException(_places.Count);
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор на конкретную позицию
|
||||
/// </summary>
|
||||
/// <param name="plane">Добавляемый самолет</param>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns></returns>
|
||||
public bool Insert(T plane, int position, IEqualityComparer<T> equal = null)
|
||||
public bool Insert(T plane, int position)
|
||||
{
|
||||
if (position < 0 || position >= _maxCount)
|
||||
{
|
||||
if (_places.Count == _maxCount)
|
||||
throw new StorageOverflowException(_maxCount);
|
||||
if (!(position >= 0 && position <= Count))
|
||||
return false;
|
||||
if (equal != null)
|
||||
{
|
||||
if (_places.Contains(plane, equal))
|
||||
throw new ArgumentException(nameof(plane));
|
||||
}
|
||||
_places.Insert(position, plane);
|
||||
if (_places[position] == null)
|
||||
{
|
||||
_places[position] = plane;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (_places.Count < _maxCount)
|
||||
{
|
||||
_places.Add(plane);
|
||||
for (int i = position; i < _places.Count; i++)
|
||||
{
|
||||
T temp = _places[i];
|
||||
_places[i] = _places[_places.Count - 1];
|
||||
_places[_places.Count - 1] = temp;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new StorageOverflowException();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление объекта из набора с конкретной позиции
|
||||
/// </summary>
|
||||
@@ -79,7 +106,7 @@ namespace ProjectBomber.Generics
|
||||
public bool Remove(int position)
|
||||
{
|
||||
if (position < 0 || position > _maxCount || position >= Count)
|
||||
throw new PlaneNotFoundException(position);
|
||||
throw new PlaneNotFoundException();
|
||||
if (_places[position] == null)
|
||||
{
|
||||
throw new PlaneNotFoundException();
|
||||
@@ -98,7 +125,7 @@ namespace ProjectBomber.Generics
|
||||
{
|
||||
if (position < 0 || position >= _maxCount)
|
||||
return null;
|
||||
return _places[position] ?? default;
|
||||
return _places[position];
|
||||
}
|
||||
set
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user