Compare commits
No commits in common. "ff8cbd3ea60ae2bffa6085155ac108265deedb24" and "c156ce7b1f206ce226bd3424cd982489d1433c92" have entirely different histories.
ff8cbd3ea6
...
c156ce7b1f
@ -1,28 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace AirFighter.Generics
|
|
||||||
{
|
|
||||||
internal class AirFighterCollectionInfo : IEquatable<AirFighterCollectionInfo>
|
|
||||||
{
|
|
||||||
public string Name { get; private set; }
|
|
||||||
public string Description { get; private set; }
|
|
||||||
public AirFighterCollectionInfo(string name, string description)
|
|
||||||
{
|
|
||||||
Name = name;
|
|
||||||
Description = description;
|
|
||||||
}
|
|
||||||
public bool Equals(AirFighterCollectionInfo? other)
|
|
||||||
{
|
|
||||||
return Name == other.Name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override int GetHashCode()
|
|
||||||
{
|
|
||||||
return this.Name.GetHashCode();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,50 +0,0 @@
|
|||||||
using AirFighter.DrawningObjects;
|
|
||||||
using AirFighter.Entities;
|
|
||||||
using AirFighter.Generics;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace AirFighter
|
|
||||||
{
|
|
||||||
internal class fighterCompareByColor : IComparer<DrawningAirFighter?>
|
|
||||||
{
|
|
||||||
public int Compare(DrawningAirFighter? x, DrawningAirFighter? y)
|
|
||||||
{
|
|
||||||
if (x == null || x.EntityAirFighter == null)
|
|
||||||
throw new ArgumentNullException(nameof(x));
|
|
||||||
|
|
||||||
if (y == null || y.EntityAirFighter == null)
|
|
||||||
throw new ArgumentNullException(nameof(y));
|
|
||||||
|
|
||||||
if (x.EntityAirFighter.BodyColor.Name != y.EntityAirFighter.BodyColor.Name)
|
|
||||||
{
|
|
||||||
return x.EntityAirFighter.BodyColor.Name.CompareTo(y.EntityAirFighter.BodyColor.Name);
|
|
||||||
}
|
|
||||||
if (x.GetType().Name != y.GetType().Name)
|
|
||||||
{
|
|
||||||
if (x is EntityAirFighter)
|
|
||||||
return -1;
|
|
||||||
else
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (x.GetType().Name == y.GetType().Name && x is DrawningAirFighterMilitary)
|
|
||||||
{
|
|
||||||
EntityAirFighterMilitary EntityX = (EntityAirFighterMilitary)x.EntityAirFighter;
|
|
||||||
EntityAirFighterMilitary EntityY = (EntityAirFighterMilitary)y.EntityAirFighter;
|
|
||||||
if (EntityX.AdditionalColor.Name != EntityY.AdditionalColor.Name)
|
|
||||||
{
|
|
||||||
return EntityX.AdditionalColor.Name.CompareTo(EntityY.AdditionalColor.Name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var speedCompare = x.EntityAirFighter.Speed.CompareTo(y.EntityAirFighter.Speed);
|
|
||||||
|
|
||||||
if (speedCompare != 0)
|
|
||||||
return speedCompare;
|
|
||||||
|
|
||||||
return x.EntityAirFighter.Weight.CompareTo(y.EntityAirFighter.Weight);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,32 +0,0 @@
|
|||||||
using AirFighter.DrawningObjects;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace AirFighter
|
|
||||||
{
|
|
||||||
internal class AirFighterCompareByType : IComparer<DrawningAirFighter?>
|
|
||||||
{
|
|
||||||
public int Compare(DrawningAirFighter? x, DrawningAirFighter? y)
|
|
||||||
{
|
|
||||||
if (x == null || x.EntityAirFighter == null)
|
|
||||||
throw new ArgumentNullException(nameof(x));
|
|
||||||
|
|
||||||
if (y == null || y.EntityAirFighter == null)
|
|
||||||
throw new ArgumentNullException(nameof(y));
|
|
||||||
|
|
||||||
if (x.GetType().Name != y.GetType().Name)
|
|
||||||
{
|
|
||||||
return x.GetType().Name.CompareTo(y.GetType().Name);
|
|
||||||
}
|
|
||||||
var speedCompare = x.EntityAirFighter.Speed.CompareTo(y.EntityAirFighter.Speed);
|
|
||||||
|
|
||||||
if (speedCompare != 0)
|
|
||||||
return speedCompare;
|
|
||||||
|
|
||||||
return x.EntityAirFighter.Weight.CompareTo(y.EntityAirFighter.Weight);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -21,7 +21,6 @@ namespace AirFighter.Generics
|
|||||||
private readonly int _placeSizeHeight = 180;
|
private readonly int _placeSizeHeight = 180;
|
||||||
|
|
||||||
private readonly SetGeneric<T> _collection;
|
private readonly SetGeneric<T> _collection;
|
||||||
public void Sort(IComparer<T?> comparer) => _collection.SortSet(comparer);
|
|
||||||
public AirFighterGenericCollection(int picWidth, int picHeight)
|
public AirFighterGenericCollection(int picWidth, int picHeight)
|
||||||
{
|
{
|
||||||
int width = picWidth / _placeSizeWidth;
|
int width = picWidth / _placeSizeWidth;
|
||||||
@ -30,13 +29,13 @@ namespace AirFighter.Generics
|
|||||||
_pictureHeight = picHeight;
|
_pictureHeight = picHeight;
|
||||||
_collection = new SetGeneric<T>(width * height);
|
_collection = new SetGeneric<T>(width * height);
|
||||||
}
|
}
|
||||||
public static bool operator +(AirFighterGenericCollection<T, U> collect, T? obj)
|
public static int? operator +(AirFighterGenericCollection<T, U> collect, T? obj)
|
||||||
{
|
{
|
||||||
if (obj == null)
|
if (obj == null)
|
||||||
{
|
{
|
||||||
return false;
|
return -1;
|
||||||
}
|
}
|
||||||
return collect?._collection.Insert(obj, new DrawningAirFighterEqutables()) ?? false;
|
return collect?._collection.Insert(obj);
|
||||||
}
|
}
|
||||||
public static T operator -(AirFighterGenericCollection<T, U> collect, int pos)
|
public static T operator -(AirFighterGenericCollection<T, U> collect, int pos)
|
||||||
{
|
{
|
||||||
|
@ -3,82 +3,56 @@ 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 AirFighter.Drawnings;
|
|
||||||
using AirFighter.MovementStrategy;
|
|
||||||
using AirFighter.DrawningObjects;
|
using AirFighter.DrawningObjects;
|
||||||
|
using AirFighter.MovementStrategy;
|
||||||
|
using AirFighter.Generics;
|
||||||
|
using System.IO;
|
||||||
using AirFighter.Exceptions;
|
using AirFighter.Exceptions;
|
||||||
using AirFighter.Exceptions;
|
|
||||||
|
|
||||||
namespace AirFighter.Generics
|
namespace AirFighter.Generics
|
||||||
|
|
||||||
{
|
{
|
||||||
internal class AirFighterGenericStorage
|
internal class AirFighterGenericStorage
|
||||||
{
|
{
|
||||||
readonly Dictionary<AirFighterCollectionInfo, AirFighterGenericCollection<DrawningAirFighter,
|
readonly Dictionary<string, AirFighterGenericCollection<DrawningAirFighter, DrawningObjectAirFighter>> _fighterStorages;
|
||||||
DrawningObjectAirFighter>> _lincornStorages;
|
|
||||||
public List<AirFighterCollectionInfo> Keys => _lincornStorages.Keys.ToList();
|
public List<string> Keys => _fighterStorages.Keys.ToList();
|
||||||
|
|
||||||
private readonly int _pictureWidth;
|
private readonly int _pictureWidth;
|
||||||
private readonly int _pictureHeight;
|
private readonly int _pictureHeight;
|
||||||
private static readonly char _separatorForKeyValue = '|';
|
|
||||||
private readonly char _separatorRecords = ';';
|
|
||||||
private static readonly char _separatorForObject = ':';
|
|
||||||
public AirFighterGenericStorage(int pictureWidth, int pictureHeight)
|
public AirFighterGenericStorage(int pictureWidth, int pictureHeight)
|
||||||
{
|
{
|
||||||
_lincornStorages = new Dictionary<AirFighterCollectionInfo,
|
_fighterStorages = new Dictionary<string, AirFighterGenericCollection<DrawningAirFighter, DrawningObjectAirFighter>>();
|
||||||
AirFighterGenericCollection<DrawningAirFighter, DrawningObjectAirFighter>>();
|
|
||||||
_pictureWidth = pictureWidth;
|
_pictureWidth = pictureWidth;
|
||||||
_pictureHeight = pictureHeight;
|
_pictureHeight = pictureHeight;
|
||||||
}
|
}
|
||||||
/// <summary>
|
|
||||||
/// Добавление набора
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="name">Название набора</param>
|
|
||||||
public void AddSet(string name)
|
public void AddSet(string name)
|
||||||
{
|
{
|
||||||
// TODO Прописать логику для добавления
|
if (_fighterStorages.ContainsKey(name)) return;
|
||||||
if (!_lincornStorages.ContainsKey(new AirFighterCollectionInfo(name, string.Empty)))
|
_fighterStorages[name] = new AirFighterGenericCollection<DrawningAirFighter, DrawningObjectAirFighter>(_pictureWidth, _pictureHeight);
|
||||||
{
|
|
||||||
var lincornCollection = new AirFighterGenericCollection<DrawningAirFighter, DrawningObjectAirFighter>(_pictureWidth, _pictureHeight);
|
|
||||||
_lincornStorages.Add(new AirFighterCollectionInfo(name, string.Empty), lincornCollection);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/// <summary>
|
|
||||||
/// Удаление набора
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="name">Название набора</param>
|
|
||||||
public void DelSet(string name)
|
public void DelSet(string name)
|
||||||
{
|
{
|
||||||
// TODO Прописать логику для удаления
|
if (!_fighterStorages.ContainsKey(name)) return;
|
||||||
if (_lincornStorages.ContainsKey(new AirFighterCollectionInfo(name, string.Empty)))
|
_fighterStorages.Remove(name);
|
||||||
{
|
|
||||||
_lincornStorages.Remove(new AirFighterCollectionInfo(name, string.Empty));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/// <summary>
|
|
||||||
/// Доступ к набору
|
public AirFighterGenericCollection<DrawningAirFighter, DrawningObjectAirFighter>?
|
||||||
/// </summary>
|
this[string ind]
|
||||||
/// <param name="ind"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public AirFighterGenericCollection<DrawningAirFighter, DrawningObjectAirFighter>? this[string ind]
|
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
AirFighterCollectionInfo indObj = new AirFighterCollectionInfo(ind, string.Empty);
|
if (_fighterStorages.ContainsKey(ind)) return _fighterStorages[ind];
|
||||||
// TODO Продумать логику получения набора
|
|
||||||
if (_lincornStorages.ContainsKey(indObj))
|
|
||||||
{
|
|
||||||
return _lincornStorages[indObj];
|
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// <summary>
|
|
||||||
/// Сохранение информации по установкам в хранилище в файл
|
private static readonly char _separatorForKeyValue = '|';
|
||||||
/// </summary>
|
|
||||||
/// <param name="filename">Путь и имя файла</param>
|
private readonly char _separatorRecords = ';';
|
||||||
/// <returns>true - сохранение прошло успешно, false - ошибка при сохранении данных</returns>
|
|
||||||
|
private static readonly char _separatorForObject = ':';
|
||||||
public void SaveData(string filename)
|
public void SaveData(string filename)
|
||||||
{
|
{
|
||||||
if (File.Exists(filename))
|
if (File.Exists(filename))
|
||||||
@ -86,7 +60,7 @@ namespace AirFighter.Generics
|
|||||||
File.Delete(filename);
|
File.Delete(filename);
|
||||||
}
|
}
|
||||||
StringBuilder data = new();
|
StringBuilder data = new();
|
||||||
foreach (KeyValuePair<AirFighterCollectionInfo, AirFighterGenericCollection<DrawningAirFighter, DrawningObjectAirFighter>> record in _lincornStorages)
|
foreach (KeyValuePair<string, AirFighterGenericCollection<DrawningAirFighter, DrawningObjectAirFighter>> record in _fighterStorages)
|
||||||
{
|
{
|
||||||
StringBuilder records = new();
|
StringBuilder records = new();
|
||||||
foreach (DrawningAirFighter? elem in record.Value.GetAirFighter)
|
foreach (DrawningAirFighter? elem in record.Value.GetAirFighter)
|
||||||
@ -102,22 +76,15 @@ namespace AirFighter.Generics
|
|||||||
|
|
||||||
using (StreamWriter writer = new StreamWriter(filename))
|
using (StreamWriter writer = new StreamWriter(filename))
|
||||||
{
|
{
|
||||||
writer.Write($"lincornStorage{Environment.NewLine}{data}");
|
writer.Write($"fighterStorage{Environment.NewLine}{data}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// <summary>
|
|
||||||
/// Загрузка информации по установкам в хранилище из файла
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="filename">Путь и имя файла</param>
|
|
||||||
/// <returns>true - загрузка прошла успешно, false - ошибка при загрузке данных</returns>
|
|
||||||
public void LoadData(string filename)
|
public void LoadData(string filename)
|
||||||
{
|
{
|
||||||
if (!File.Exists(filename))
|
if (!File.Exists(filename))
|
||||||
{
|
{
|
||||||
throw new Exception("Файл не найден");
|
throw new Exception("Файл не найден");
|
||||||
}
|
}
|
||||||
|
|
||||||
using (StreamReader reader = new StreamReader(filename))
|
using (StreamReader reader = new StreamReader(filename))
|
||||||
{
|
{
|
||||||
string cheker = reader.ReadLine();
|
string cheker = reader.ReadLine();
|
||||||
@ -125,11 +92,11 @@ namespace AirFighter.Generics
|
|||||||
{
|
{
|
||||||
throw new Exception("Нет данных для загрузки");
|
throw new Exception("Нет данных для загрузки");
|
||||||
}
|
}
|
||||||
if (!cheker.StartsWith("lincornStorage"))
|
if (!cheker.StartsWith("fighterStorage"))
|
||||||
{
|
{
|
||||||
throw new Exception("Неверный формат ввода");
|
throw new Exception("Неверный формат ввода");
|
||||||
}
|
}
|
||||||
_lincornStorages.Clear();
|
_fighterStorages.Clear();
|
||||||
string strs;
|
string strs;
|
||||||
bool firstinit = true;
|
bool firstinit = true;
|
||||||
while ((strs = reader.ReadLine()) != null)
|
while ((strs = reader.ReadLine()) != null)
|
||||||
@ -147,11 +114,11 @@ namespace AirFighter.Generics
|
|||||||
AirFighterGenericCollection<DrawningAirFighter, DrawningObjectAirFighter> collection = new(_pictureWidth, _pictureHeight);
|
AirFighterGenericCollection<DrawningAirFighter, DrawningObjectAirFighter> collection = new(_pictureWidth, _pictureHeight);
|
||||||
foreach (string data in strs.Split(_separatorForKeyValue)[1].Split(_separatorRecords))
|
foreach (string data in strs.Split(_separatorForKeyValue)[1].Split(_separatorRecords))
|
||||||
{
|
{
|
||||||
DrawningAirFighter? lincorn =
|
DrawningAirFighter? fighter =
|
||||||
data?.CreateDrawningAirFighter(_separatorForObject, _pictureWidth, _pictureHeight);
|
data?.CreateDrawningAirFighter(_separatorForObject, _pictureWidth, _pictureHeight);
|
||||||
if (lincorn != null)
|
if (fighter != null)
|
||||||
{
|
{
|
||||||
try { _ = collection + lincorn; }
|
try { _ = collection + fighter; }
|
||||||
catch (AirFighterNotFoundException e)
|
catch (AirFighterNotFoundException e)
|
||||||
{
|
{
|
||||||
throw e;
|
throw e;
|
||||||
@ -162,10 +129,9 @@ namespace AirFighter.Generics
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_lincornStorages.Add(new AirFighterCollectionInfo(name, string.Empty), collection);
|
_fighterStorages.Add(name, collection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,59 +0,0 @@
|
|||||||
using AirFighter.DrawningObjects;
|
|
||||||
using AirFighter.Entities;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Diagnostics.CodeAnalysis;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace AirFighter
|
|
||||||
{
|
|
||||||
internal class DrawningAirFighterEqutables : IEqualityComparer<DrawningAirFighter?>
|
|
||||||
{
|
|
||||||
public bool Equals(DrawningAirFighter? x, DrawningAirFighter? y)
|
|
||||||
{
|
|
||||||
if (x == null || x.EntityAirFighter == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(x));
|
|
||||||
}
|
|
||||||
if (y == null || y.EntityAirFighter == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(y));
|
|
||||||
}
|
|
||||||
if (x.GetType().Name != y.GetType().Name)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (x.EntityAirFighter.Speed != y.EntityAirFighter.Speed)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (x.EntityAirFighter.Weight != y.EntityAirFighter.Weight)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (x.EntityAirFighter.BodyColor != y.EntityAirFighter.BodyColor)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (x is EntityAirFighterMilitary && y is EntityAirFighterMilitary)
|
|
||||||
{
|
|
||||||
EntityAirFighterMilitary EntityX = (EntityAirFighterMilitary)x.EntityAirFighter;
|
|
||||||
EntityAirFighterMilitary EntityY = (EntityAirFighterMilitary)y.EntityAirFighter;
|
|
||||||
if (EntityX.AdditionalColor != EntityY.AdditionalColor)
|
|
||||||
return false;
|
|
||||||
if (EntityX.Wing != EntityY.Wing)
|
|
||||||
return false;
|
|
||||||
if (EntityX.Rocket != EntityY.Rocket)
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int GetHashCode([DisallowNull] DrawningAirFighter obj)
|
|
||||||
{
|
|
||||||
return obj.GetHashCode();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -29,8 +29,6 @@
|
|||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
groupBox1 = new GroupBox();
|
groupBox1 = new GroupBox();
|
||||||
ButtonSortByType = new Button();
|
|
||||||
ButtonSortByColor = new Button();
|
|
||||||
groupBox2 = new GroupBox();
|
groupBox2 = new GroupBox();
|
||||||
buttonDelObject = new Button();
|
buttonDelObject = new Button();
|
||||||
listBoxStorage = new ListBox();
|
listBoxStorage = new ListBox();
|
||||||
@ -55,8 +53,6 @@
|
|||||||
//
|
//
|
||||||
// groupBox1
|
// groupBox1
|
||||||
//
|
//
|
||||||
groupBox1.Controls.Add(ButtonSortByType);
|
|
||||||
groupBox1.Controls.Add(ButtonSortByColor);
|
|
||||||
groupBox1.Controls.Add(groupBox2);
|
groupBox1.Controls.Add(groupBox2);
|
||||||
groupBox1.Controls.Add(maskedTextBoxNumber);
|
groupBox1.Controls.Add(maskedTextBoxNumber);
|
||||||
groupBox1.Controls.Add(buttonRemoveFighter);
|
groupBox1.Controls.Add(buttonRemoveFighter);
|
||||||
@ -69,26 +65,6 @@
|
|||||||
groupBox1.TabStop = false;
|
groupBox1.TabStop = false;
|
||||||
groupBox1.Text = "Инструменты";
|
groupBox1.Text = "Инструменты";
|
||||||
//
|
//
|
||||||
// ButtonSortByType
|
|
||||||
//
|
|
||||||
ButtonSortByType.Location = new Point(17, 251);
|
|
||||||
ButtonSortByType.Name = "ButtonSortByType";
|
|
||||||
ButtonSortByType.Size = new Size(166, 23);
|
|
||||||
ButtonSortByType.TabIndex = 3;
|
|
||||||
ButtonSortByType.Text = "Сортировка по типу";
|
|
||||||
ButtonSortByType.UseVisualStyleBackColor = true;
|
|
||||||
ButtonSortByType.Click += ButtonSortByType_Click;
|
|
||||||
//
|
|
||||||
// ButtonSortByColor
|
|
||||||
//
|
|
||||||
ButtonSortByColor.Location = new Point(17, 280);
|
|
||||||
ButtonSortByColor.Name = "ButtonSortByColor";
|
|
||||||
ButtonSortByColor.Size = new Size(166, 23);
|
|
||||||
ButtonSortByColor.TabIndex = 4;
|
|
||||||
ButtonSortByColor.Text = "Сортировка по цвету";
|
|
||||||
ButtonSortByColor.UseVisualStyleBackColor = true;
|
|
||||||
ButtonSortByColor.Click += ButtonSortByColor_Click;
|
|
||||||
//
|
|
||||||
// groupBox2
|
// groupBox2
|
||||||
//
|
//
|
||||||
groupBox2.Controls.Add(buttonDelObject);
|
groupBox2.Controls.Add(buttonDelObject);
|
||||||
@ -97,14 +73,14 @@
|
|||||||
groupBox2.Controls.Add(textBoxStorageName);
|
groupBox2.Controls.Add(textBoxStorageName);
|
||||||
groupBox2.Location = new Point(3, 19);
|
groupBox2.Location = new Point(3, 19);
|
||||||
groupBox2.Name = "groupBox2";
|
groupBox2.Name = "groupBox2";
|
||||||
groupBox2.Size = new Size(200, 226);
|
groupBox2.Size = new Size(200, 284);
|
||||||
groupBox2.TabIndex = 6;
|
groupBox2.TabIndex = 6;
|
||||||
groupBox2.TabStop = false;
|
groupBox2.TabStop = false;
|
||||||
groupBox2.Text = "Наборы";
|
groupBox2.Text = "Наборы";
|
||||||
//
|
//
|
||||||
// buttonDelObject
|
// buttonDelObject
|
||||||
//
|
//
|
||||||
buttonDelObject.Location = new Point(18, 188);
|
buttonDelObject.Location = new Point(18, 244);
|
||||||
buttonDelObject.Name = "buttonDelObject";
|
buttonDelObject.Name = "buttonDelObject";
|
||||||
buttonDelObject.Size = new Size(159, 34);
|
buttonDelObject.Size = new Size(159, 34);
|
||||||
buttonDelObject.TabIndex = 2;
|
buttonDelObject.TabIndex = 2;
|
||||||
@ -118,7 +94,7 @@
|
|||||||
listBoxStorage.ItemHeight = 15;
|
listBoxStorage.ItemHeight = 15;
|
||||||
listBoxStorage.Location = new Point(15, 88);
|
listBoxStorage.Location = new Point(15, 88);
|
||||||
listBoxStorage.Name = "listBoxStorage";
|
listBoxStorage.Name = "listBoxStorage";
|
||||||
listBoxStorage.Size = new Size(162, 94);
|
listBoxStorage.Size = new Size(162, 139);
|
||||||
listBoxStorage.TabIndex = 2;
|
listBoxStorage.TabIndex = 2;
|
||||||
listBoxStorage.SelectedIndexChanged += listBoxStorage_SelectedIndexChanged;
|
listBoxStorage.SelectedIndexChanged += listBoxStorage_SelectedIndexChanged;
|
||||||
//
|
//
|
||||||
@ -207,14 +183,14 @@
|
|||||||
// SaveToolStripMenuItem
|
// SaveToolStripMenuItem
|
||||||
//
|
//
|
||||||
SaveToolStripMenuItem.Name = "SaveToolStripMenuItem";
|
SaveToolStripMenuItem.Name = "SaveToolStripMenuItem";
|
||||||
SaveToolStripMenuItem.Size = new Size(133, 22);
|
SaveToolStripMenuItem.Size = new Size(180, 22);
|
||||||
SaveToolStripMenuItem.Text = "Сохранить";
|
SaveToolStripMenuItem.Text = "Сохранить";
|
||||||
SaveToolStripMenuItem.Click += SaveToolStripMenuItem_Click;
|
SaveToolStripMenuItem.Click += SaveToolStripMenuItem_Click;
|
||||||
//
|
//
|
||||||
// LoadToolStripMenuItem
|
// LoadToolStripMenuItem
|
||||||
//
|
//
|
||||||
LoadToolStripMenuItem.Name = "LoadToolStripMenuItem";
|
LoadToolStripMenuItem.Name = "LoadToolStripMenuItem";
|
||||||
LoadToolStripMenuItem.Size = new Size(133, 22);
|
LoadToolStripMenuItem.Size = new Size(180, 22);
|
||||||
LoadToolStripMenuItem.Text = "Загрузить";
|
LoadToolStripMenuItem.Text = "Загрузить";
|
||||||
LoadToolStripMenuItem.Click += LoadToolStripMenuItem_Click;
|
LoadToolStripMenuItem.Click += LoadToolStripMenuItem_Click;
|
||||||
//
|
//
|
||||||
@ -268,7 +244,5 @@
|
|||||||
private ToolStripMenuItem LoadToolStripMenuItem;
|
private ToolStripMenuItem LoadToolStripMenuItem;
|
||||||
private OpenFileDialog openFileDialog1;
|
private OpenFileDialog openFileDialog1;
|
||||||
private SaveFileDialog saveFileDialog1;
|
private SaveFileDialog saveFileDialog1;
|
||||||
private Button ButtonSortByType;
|
|
||||||
private Button ButtonSortByColor;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -38,7 +38,7 @@ namespace AirFighter
|
|||||||
listBoxStorage.Items.Clear();
|
listBoxStorage.Items.Clear();
|
||||||
for (int i = 0; i < _storage.Keys.Count; i++)
|
for (int i = 0; i < _storage.Keys.Count; i++)
|
||||||
{
|
{
|
||||||
listBoxStorage.Items.Add(_storage.Keys[i].Name);
|
listBoxStorage.Items.Add(_storage.Keys[i]);
|
||||||
}
|
}
|
||||||
if (listBoxStorage.Items.Count > 0 && (index == -1 || index
|
if (listBoxStorage.Items.Count > 0 && (index == -1 || index
|
||||||
>= listBoxStorage.Items.Count))
|
>= listBoxStorage.Items.Count))
|
||||||
@ -173,7 +173,7 @@ namespace AirFighter
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
MessageBox.Show("Не удалось удалить объект"); _logger.LogWarning($"Не удалось удалить объект из набора {listBoxStorage.SelectedItem.ToString()}");
|
MessageBox.Show("Не удалось удалить объект");
|
||||||
_logger.LogWarning($"Не удалось удалить объект из набора {listBoxStorage.SelectedItem.ToString()}");
|
_logger.LogWarning($"Не удалось удалить объект из набора {listBoxStorage.SelectedItem.ToString()}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -234,27 +234,6 @@ namespace AirFighter
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ButtonSortByType_Click(object sender, EventArgs e) => CompareAirFighter(new AirFighterCompareByType());
|
|
||||||
|
|
||||||
private void ButtonSortByColor_Click(object sender, EventArgs e) => CompareAirFighter(new fighterCompareByColor());
|
|
||||||
//сортировка
|
|
||||||
private void CompareAirFighter(IComparer<DrawningAirFighter?> comparer)
|
|
||||||
{
|
|
||||||
if (listBoxStorage.SelectedIndex == -1)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var obj = _storage[listBoxStorage.SelectedItem.ToString() ??
|
|
||||||
string.Empty];
|
|
||||||
if (obj == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
obj.Sort(comparer);
|
|
||||||
pictureBoxCollection.Image = obj.ShowAirFighter();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,26 +14,41 @@ namespace AirFighter.Generics
|
|||||||
_maxCount = count;
|
_maxCount = count;
|
||||||
_places = new List<T?>(count);
|
_places = new List<T?>(count);
|
||||||
}
|
}
|
||||||
public void SortSet(IComparer<T?> comparer) => _places.Sort(comparer);
|
public int Insert(T fighter)
|
||||||
public bool Insert(T fighter, IEqualityComparer<T>? equal = null)
|
|
||||||
{
|
{
|
||||||
Insert(fighter, 0, equal);
|
if (_places.Count == 0)
|
||||||
return true;
|
{
|
||||||
|
_places.Add(fighter);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (_places.Count < _maxCount)
|
||||||
|
{
|
||||||
|
_places.Add(fighter);
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
public bool Insert(T fighter, int position, IEqualityComparer<T>? equal = null)
|
public bool Insert(T fighter, int position)
|
||||||
{
|
{
|
||||||
if (position < 0 || position >= _maxCount)
|
if (position < 0 || position >= _maxCount)
|
||||||
throw new AirFighterNotFoundException(position);
|
throw new AirFighterNotFoundException(position);
|
||||||
|
|
||||||
if (Count >= _maxCount)
|
if (Count >= _maxCount)
|
||||||
throw new StorageOverflowException(position);
|
throw new StorageOverflowException(position);
|
||||||
if (equal != null)
|
_places.Insert(0, fighter);
|
||||||
{
|
|
||||||
if (_places.Contains(fighter, equal))
|
|
||||||
throw new ArgumentException(nameof(fighter));
|
|
||||||
}
|
|
||||||
_places.Insert(position, fighter);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
public bool Remove(int position)
|
public bool Remove(int position)
|
||||||
|
Loading…
Reference in New Issue
Block a user