This commit is contained in:
Дима 2024-05-23 01:42:17 +04:00
parent 52ac4d0b2f
commit 3354a226f8
25 changed files with 521 additions and 160 deletions

View File

@ -61,7 +61,7 @@ namespace ProjectArtilleryUnit.CollectionGenericObjects
/// <returns></returns>
public static int operator +(AbstractCompany company, DrawningArtilleryUnit сruiser)
{
return company._collection.Insert(сruiser);
return company._collection.Insert(сruiser, new DrawiningArtilleryUnitEqutables());
}
/// <summary>
@ -109,6 +109,13 @@ namespace ProjectArtilleryUnit.CollectionGenericObjects
}
return bitmap;
}
/// <summary>
/// Сортировка
/// </summary>
/// <param name="comparer">Сравнитель объектов</param>
public void Sort(IComparer<DrawningArtilleryUnit?> comparer) => _collection?.CollectionSort(comparer);
/// <summary>
/// Вывод заднего фона
/// </summary>

View File

@ -0,0 +1,75 @@
namespace ProjectArtilleryUnit.CollectionGenericObjects;
public class CollectionInfo : IEquatable<CollectionInfo>
{
/// <summary>
/// Название
/// </summary>
public string Name { get; private set; }
/// <summary>
/// Тип
/// </summary>
public CollectionType CollectionType { get; private set; }
/// <summary>
/// Описание
/// </summary>
public string Description { get; private set; }
/// <summary>
/// Разделитель для записи информации по объекту в файл
/// </summary>
private static readonly string _separator = "-";
/// <summary>
/// Конструктор
/// </summary>
/// <param name="name">Название</param>
/// <param name="collectionType">Тип</param>
/// <param name="description">Описание</param>
public CollectionInfo(string name, CollectionType collectionType, string
description)
{
Name = name;
CollectionType = collectionType;
Description = description;
}
/// <summary>
/// Создание объекта из строки
/// </summary>
/// <param name="data">Строка</param>
/// <returns>Объект или null</returns>
public static CollectionInfo? GetCollectionInfo(string data)
{
string[] strs = data.Split(_separator, StringSplitOptions.RemoveEmptyEntries);
if (strs.Length < 1 || strs.Length > 3)
{
return null;
}
return new CollectionInfo(strs[0], (CollectionType)Enum.Parse(typeof(CollectionType), strs[1]), strs.Length > 2 ? strs[2] : string.Empty);
}
public override string ToString()
{
return Name + _separator + CollectionType + _separator + Description;
}
public bool Equals(CollectionInfo? other)
{
return Name == other?.Name;
}
public override bool Equals(object? obj)
{
return Equals(obj as CollectionInfo);
}
public override int GetHashCode()
{
return Name.GetHashCode();
}
}

View File

@ -1,4 +1,6 @@
namespace ProjectArtilleryUnit.CollectionGenericObjects
using ProjectArtilleryUnit.Drawnings;
namespace ProjectArtilleryUnit.CollectionGenericObjects
{
/// <summary>
/// Интерфейс описания действий для набора хранимых объектов
@ -21,8 +23,9 @@
/// Добавление объекта в коллекцию
/// </summary>
/// <param name="obj">Добавляемый объект</param>
/// /// <param name="comparer">Cравнение двух объектов</param>
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
int Insert(T obj);
int Insert(T obj, IEqualityComparer<DrawningArtilleryUnit?>? comparer = null);
/// <summary>
/// Добавление объекта в коллекцию на конкретную позицию
@ -30,7 +33,7 @@
/// <param name="obj">Добавляемый объект</param>
/// <param name="position">Позиция</param>
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
int Insert(T obj, int position);
int Insert(T obj, int position, IEqualityComparer<DrawningArtilleryUnit?>? comparer = null);
/// <summary>
/// Удаление объекта из коллекции с конкретной позиции
@ -56,6 +59,12 @@
/// <returns>Поэлементый вывод элементов коллекции</returns>
IEnumerable<T?> GetItems();
/// <summary>
/// Сортировка коллекции
/// </summary>
/// <param name="comparer">Сравнитель объектов</param>
void CollectionSort(IComparer<T?> comparer);
}
}

View File

@ -1,4 +1,5 @@
using ProjectArtilleryUnit.Exceptions;
using ProjectArtilleryUnit.Drawnings;
using ProjectArtilleryUnit.Exceptions;
namespace ProjectArtilleryUnit.CollectionGenericObjects
{
@ -47,23 +48,38 @@ namespace ProjectArtilleryUnit.CollectionGenericObjects
return _collection[position];
}
public int Insert(T obj)
public int Insert(T obj, IEqualityComparer<DrawningArtilleryUnit?>? comparer = null)
{
// TODO проверка, что не превышено максимальное количество элементов
// TODO выбром позиций, если переполнение
// TODO выброc позиций, если такой объект есть в коллекции
// TODO вставка в конец набора
for (int i = 0; i < Count; i++)
{
if (comparer.Equals((_collection[i] as DrawningArtilleryUnit), (obj as DrawningArtilleryUnit))) throw new ObjectAlreadyInCollectionException(i);
}
if (Count == _maxCount) throw new CollectionOverflowException(Count);
_collection.Add(obj);
return Count;
}
public int Insert(T obj, int position)
public int Insert(T obj, int position, IEqualityComparer<DrawningArtilleryUnit?>? comparer = null)
{
// TODO проверка, что не превышено максимальное количество элементов
// TODO выброc позиций, если такой объект есть в коллекции
// TODO проверка позиции
// TODO вставка по позиции
for (int i = 0; i < Count; i++)
{
if (comparer.Equals((_collection[i] as DrawningArtilleryUnit), (obj as DrawningArtilleryUnit))) throw new ObjectAlreadyInCollectionException(i);
}
if (Count == _maxCount) throw new CollectionOverflowException(Count);
if (position >= Count || position < 0) throw new PositionOutOfCollectionException(position);
_collection.Insert(position, obj);
return position;
@ -72,9 +88,10 @@ namespace ProjectArtilleryUnit.CollectionGenericObjects
public T Remove(int position)
{
// TODO проверка позиции
// TODO удаление объекта из списка
// TODO выбром позиций, если выход за границы массива
// TODO удаление объекта из списка
if (position >= _collection.Count || position < 0) throw new PositionOutOfCollectionException(position);
T obj = _collection[position];
_collection.RemoveAt(position);
return obj;
@ -87,5 +104,10 @@ namespace ProjectArtilleryUnit.CollectionGenericObjects
yield return _collection[i];
}
}
public void CollectionSort(IComparer<T?> comparer)
{
_collection.Sort(comparer);
}
}
}

View File

@ -1,4 +1,5 @@
using ProjectArtilleryUnit.Exceptions;
using ProjectArtilleryUnit.Drawnings;
using ProjectArtilleryUnit.Exceptions;
namespace ProjectArtilleryUnit.CollectionGenericObjects
{
@ -55,34 +56,44 @@ namespace ProjectArtilleryUnit.CollectionGenericObjects
return _collection[position];
}
public int Insert(T obj)
public int Insert(T obj, IEqualityComparer<DrawningArtilleryUnit?>? comparer = null)
{
// TODO вставка в свободное место набора
// TODO выброc позиций, если переполнение
int index = 0;
while (index < Count && _collection[index] != null)
// TODO выброc позиций, если такой объект есть в коллекции
for (int i = 0; i < Count; i++)
{
index++;
if (comparer.Equals((_collection[i] as DrawningArtilleryUnit), (obj as DrawningArtilleryUnit))) throw new ObjectAlreadyInCollectionException(i);
}
if (index < Count)
for (int i = 0; i < Count; i++)
{
_collection[index] = obj;
return index;
if (_collection[i] == null)
{
_collection[i] = obj;
return i;
}
}
throw new CollectionOverflowException(Count);
}
public int Insert(T obj, int position)
public int Insert(T obj, int position, IEqualityComparer<DrawningArtilleryUnit?>? comparer = null)
{
// TODO выброc позиций, если такой объект есть в коллекции
// TODO проверка позиции
// TODO выбром позиций, если выход за границы массива
// TODO проверка, что элемент массива по этой позиции пустой, если нет, то
// ищется свободное место после этой позиции и идет вставка туда
// если нет после, ищем до
// TODO вставка
// TODO выбром позиций, если переполнение
// TODO выбром позиций, если выход за границы массива
// TODO вставка
for (int i = 0; i < Count; i++)
{
if (comparer.Equals((_collection[i] as DrawningArtilleryUnit), (obj as DrawningArtilleryUnit))) throw new ObjectAlreadyInCollectionException(i);
}
if (position < 0 || position >= Count) throw new PositionOutOfCollectionException(position);
if (_collection[position] != null)
@ -143,5 +154,10 @@ namespace ProjectArtilleryUnit.CollectionGenericObjects
yield return _collection[i];
}
}
public void CollectionSort(IComparer<T?> comparer)
{
Array.Sort(_collection, comparer);
}
}
}

View File

@ -13,12 +13,12 @@ namespace ProjectArtilleryUnit.CollectionGenericObjects
/// <summary>
/// Словарь (хранилище) с коллекциями
/// </summary>
readonly Dictionary<string, ICollectionGenericObjects<T>> _storages;
readonly Dictionary<CollectionInfo, ICollectionGenericObjects<T>> _storages;
/// <summary>
/// Возвращение списка названий коллекций
/// </summary>
public List<string> Keys => _storages.Keys.ToList();
public List<CollectionInfo> Keys => _storages.Keys.ToList();
/// <summary>
/// Ключевое слово, с которого должен начинаться файл
@ -40,7 +40,7 @@ namespace ProjectArtilleryUnit.CollectionGenericObjects
/// </summary>
public StorageCollection()
{
_storages = new Dictionary<string, ICollectionGenericObjects<T>>();
_storages = new Dictionary<CollectionInfo, ICollectionGenericObjects<T>>();
}
/// <summary>
@ -48,29 +48,40 @@ namespace ProjectArtilleryUnit.CollectionGenericObjects
/// </summary>
/// <param name="name">Название коллекции</param>
/// <param name="collectionType">тип коллекции</param>
public void AddCollection(string name, CollectionType collectionType)
public void AddCollection(CollectionInfo name)
{
// TODO проверка, что name не пустой и нет в словаре записи с таким ключом
// TODO Прописать логику для добавления
if (_storages.ContainsKey(name)) return;
if (name == null || _storages.ContainsKey(name))
{
return;
}
if (collectionType == CollectionType.None) return;
else if (collectionType == CollectionType.Massive)
_storages[name] = new MassiveGenericObjects<T>();
else if (collectionType == CollectionType.List)
_storages[name] = new ListGenericObjects<T>();
if (name.CollectionType == CollectionType.Massive)
{
_storages.Add(name, new MassiveGenericObjects<T>());
}
if (name.CollectionType == CollectionType.List)
{
_storages.Add(name, new ListGenericObjects<T>());
}
}
/// <summary>
/// Удаление коллекции
/// </summary>
/// <param name="name">Название коллекции</param>
public void DelCollection(string name)
public void DelCollection(CollectionInfo name)
{
// TODO Прописать логику для удаления коллекции
if (_storages.ContainsKey(name))
_storages.Remove(name);
if (name == null || !_storages.ContainsKey(name))
{
return;
}
_storages.Remove(name);
}
/// <summary>
@ -78,13 +89,16 @@ namespace ProjectArtilleryUnit.CollectionGenericObjects
/// </summary>
/// <param name="name">Название коллекции</param>
/// <returns></returns>
public ICollectionGenericObjects<T>? this[string name]
public ICollectionGenericObjects<T>? this[CollectionInfo name]
{
get
{
// TODO Продумать логику получения объекта
if (_storages.ContainsKey(name))
{
return _storages[name];
}
return null;
}
}
@ -111,7 +125,7 @@ namespace ProjectArtilleryUnit.CollectionGenericObjects
using StreamWriter streamWriter = new StreamWriter(fs);
streamWriter.Write(_collectionKey);
foreach (KeyValuePair<string, ICollectionGenericObjects<T>> value in _storages)
foreach (KeyValuePair<CollectionInfo, ICollectionGenericObjects<T>> value in _storages)
{
streamWriter.Write(Environment.NewLine);
@ -122,8 +136,6 @@ namespace ProjectArtilleryUnit.CollectionGenericObjects
streamWriter.Write(value.Key);
streamWriter.Write(_separatorForKeyValue);
streamWriter.Write(value.Value.GetCollectionType);
streamWriter.Write(_separatorForKeyValue);
streamWriter.Write(value.Value.MaxCount);
streamWriter.Write(_separatorForKeyValue);
@ -164,27 +176,25 @@ namespace ProjectArtilleryUnit.CollectionGenericObjects
while ((str = sr.ReadLine()) != null)
{
string[] record = str.Split(_separatorForKeyValue);
if (record.Length != 4)
if (record.Length != 3)
{
continue;
}
CollectionType collectionType = (CollectionType)Enum.Parse(typeof(CollectionType), record[1]);
ICollectionGenericObjects<T>? collection = StorageCollection<T>.CreateCollection(collectionType);
if (collection == null)
{
throw new InvalidOperationException("Не удалось определить тип коллекции:" + record[1]);
}
collection.MaxCount = Convert.ToInt32(record[2]);
CollectionInfo? collectionInfo = CollectionInfo.GetCollectionInfo(record[0]) ??
throw new Exception("Не удалось определить информацию коллекции: " + record[0]);
ICollectionGenericObjects<T>? collection = StorageCollection<T>.CreateCollection(collectionInfo.CollectionType) ??
throw new Exception("Не удалось создать коллекцию");
collection.MaxCount = Convert.ToInt32(record[1]);
string[] set = record[3].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries);
string[] set = record[2].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries);
foreach (string elem in set)
{
if (elem?.CreateDrawningArtilleryUnit() is T aircraft)
if (elem?.CreateDrawningArtilleryUnit() is T artilleryUnit)
{
try
{
if (collection.Insert(aircraft) == -1)
if (collection.Insert(artilleryUnit, new DrawiningArtilleryUnitEqutables()) == -1)
{
throw new InvalidOperationException("Объект не удалось добавить в коллекцию: " + record[3]);
}
@ -193,9 +203,13 @@ namespace ProjectArtilleryUnit.CollectionGenericObjects
{
throw new CollectionOverflowException("Коллекция переполнена", ex);
}
catch (ObjectAlreadyInCollectionException ex)
{
throw new InvalidOperationException("Объект уже присутствует в коллекции", ex);
}
}
}
_storages.Add(record[0], collection);
_storages.Add(collectionInfo, collection);
}
}
}

View File

@ -0,0 +1,54 @@
using System.Diagnostics.CodeAnalysis;
namespace ProjectArtilleryUnit.Drawnings;
/// <summary>
/// Реализация сравнения двух объектов класса-прорисовки
/// </summary>
public class DrawiningArtilleryUnitEqutables : IEqualityComparer<DrawningArtilleryUnit?>
{
public bool Equals(DrawningArtilleryUnit? x, DrawningArtilleryUnit? y)
{
if (x == null || x.EntityArtilleryUnit == null)
{
return false;
}
if (y == null || y.EntityArtilleryUnit == null)
{
return false;
}
if (x.GetType().Name != y.GetType().Name)
{
return false;
}
if (x.EntityArtilleryUnit.Speed != y.EntityArtilleryUnit.Speed)
{
return false;
}
if (x.EntityArtilleryUnit.Weight != y.EntityArtilleryUnit.Weight)
{
return false;
}
if (x.EntityArtilleryUnit.BodyColor != y.EntityArtilleryUnit.BodyColor)
{
return false;
}
if (x is DrawningMilitaryArtilleryUnit && y is DrawningMilitaryArtilleryUnit)
{
// TODO доделать логику сравнения дополнительных параметров
}
return true;
}
public int GetHashCode([DisallowNull] DrawningArtilleryUnit obj)
{
return obj.GetHashCode();
}
}

View File

@ -32,7 +32,7 @@ public class DrawningArtilleryUnit
/// </summary>
private readonly int _drawningArtilleryUnitWidth = 150;
/// <summary>
/// Высота прорисовки артиллерийской установки
/// Высота прорисовки артиллерийской установки
/// </summary>
private readonly int _drawningArtilleryUnitHeight = 50;
private readonly int _drawningEnginesWidth = 3;
@ -204,32 +204,27 @@ public class DrawningArtilleryUnit
{
return;
}
Pen pen = new(Color.Black, 2);
Pen pen2 = new(Color.Black, 3);
Brush Brush = new SolidBrush(EntityArtilleryUnit.BodyColor);
Pen pen = new(EntityArtilleryUnit.BodyColor, 2);
Brush additionalBrush = new SolidBrush(Color.Black);
//границы танка
Point[] points = { new Point(_startPosX.Value + 60, _startPosY.Value + 6), new Point(_startPosX.Value + 110, _startPosY.Value + 6), new Point(_startPosX.Value + 110, _startPosY.Value + 11), new Point(_startPosX.Value + 80, _startPosY.Value + 21), new Point(_startPosX.Value + 60, _startPosY.Value + 21), new Point(_startPosX.Value + 45, _startPosY.Value + 16), new Point(_startPosX.Value + 45, _startPosY.Value + 11) };
g.FillPolygon(Brush, points);
g.DrawPolygon(pen, points);
//границы круисера
g.DrawLine(pen, _startPosX.Value, _startPosY.Value, _startPosX.Value + 105, _startPosY.Value);
g.DrawLine(pen, _startPosX.Value + 105, _startPosY.Value, _startPosX.Value + 147, _startPosY.Value + 24);
g.FillRectangle(Brush, _startPosX.Value + 7, _startPosY.Value + 21, 132, 10);
g.DrawRectangle(pen, _startPosX.Value + 7, _startPosY.Value + 21, 132, 10);
g.DrawLine(pen, _startPosX.Value, _startPosY.Value + 49, _startPosX.Value + 105, _startPosY.Value + 49);
g.DrawLine(pen, _startPosX.Value + 105, _startPosY.Value + 49, _startPosX.Value + 147, _startPosY.Value + 24);
g.DrawLine(pen, _startPosX.Value, _startPosY.Value, _startPosX.Value, _startPosY.Value + 49);
g.DrawArc(pen, _startPosX.Value, _startPosY.Value + 6 + 22, 25, 25, 70, 200);
g.DrawArc(pen, _startPosX.Value + 122, _startPosY.Value + 28, 25, 25, 260, 200);
g.DrawLine(pen, _startPosX.Value + 10, _startPosY.Value + 29, _startPosX.Value + 135, _startPosY.Value + 29);
g.DrawLine(pen, _startPosX.Value + 10, _startPosY.Value + 53, _startPosX.Value + 135, _startPosY.Value + 53);
g.DrawEllipse(pen2, _startPosX.Value + 5, _startPosY.Value + 31, 18, 18);
g.DrawEllipse(pen2, _startPosX.Value + 125, _startPosY.Value + 31, 18, 18);
g.DrawEllipse(pen2, _startPosX.Value + 103, _startPosY.Value + 37, 12, 12);
g.DrawEllipse(pen2, _startPosX.Value + 34, _startPosY.Value + 37, 12, 12);
g.DrawEllipse(pen2, _startPosX.Value + 57, _startPosY.Value + 37, 12, 12);
g.DrawEllipse(pen2, _startPosX.Value + 80, _startPosY.Value + 37, 12, 12);
g.DrawArc(pen, _startPosX.Value + 47, _startPosY.Value + 24, 10, 10, 0, 170);
g.DrawArc(pen, _startPosX.Value + 70, _startPosY.Value + 24, 10, 10, 0, 170);
g.DrawArc(pen, _startPosX.Value + 93, _startPosY.Value + 24, 10, 10, 0, 170);
//внутренности круисера
g.DrawEllipse(pen, _startPosX.Value + 94, _startPosY.Value + 14, 19, 19);
g.DrawRectangle(pen, _startPosX.Value + 63, _startPosY.Value + 11, 21, 28);
g.DrawRectangle(pen, _startPosX.Value + 35, _startPosY.Value + 17, 28, 14);
//зад
g.FillRectangle(additionalBrush, _startPosX.Value - 3, _startPosY.Value + 7, 3, 14);
g.FillRectangle(additionalBrush, _startPosX.Value - 3, _startPosY.Value + 26, 3, 14);
}
}

View File

@ -0,0 +1,34 @@
using ProjectArtilleryUnit.Entities;
namespace ProjectArtilleryUnit.Drawnings;
/// <summary>
/// Сравнение по цвету, скорости, весу
/// </summary>
public class DrawningArtilleryUnitCompareByColor : IComparer<DrawningArtilleryUnit?>
{
public int Compare(DrawningArtilleryUnit? x, DrawningArtilleryUnit? y)
{
// TODO прописать логику сравения по цветам, скорости, весу
if (x == null || x.EntityArtilleryUnit == null)
{
return 1;
}
if (y == null || y.EntityArtilleryUnit == null)
{
return -1;
}
var bodycolorCompare = x.EntityArtilleryUnit.BodyColor.Name.CompareTo(y.EntityArtilleryUnit.BodyColor.Name);
if (bodycolorCompare != 0)
{
return bodycolorCompare;
}
var speedCompare = x.EntityArtilleryUnit.Speed.CompareTo(y.EntityArtilleryUnit.Speed);
if (speedCompare != 0)
{
return speedCompare;
}
return x.EntityArtilleryUnit.Weight.CompareTo(y.EntityArtilleryUnit.Weight);
}
}

View File

@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectArtilleryUnit.Drawnings;
/// <summary>
/// Сравнение по типу, скорости, весу
/// </summary>
public class DrawningArtilleryUnitCompareByType : IComparer<DrawningArtilleryUnit?>
{
public int Compare(DrawningArtilleryUnit? x, DrawningArtilleryUnit? y)
{
if (x == null || x.EntityArtilleryUnit == null)
{
return 1;
}
if (y == null || y.EntityArtilleryUnit == null)
{
return -1;
}
if (x.GetType().Name != y.GetType().Name)
{
return x.GetType().Name.CompareTo(y.GetType().Name);
}
var speedCompare = x.EntityArtilleryUnit.Speed.CompareTo(y.EntityArtilleryUnit.Speed);
if (speedCompare != 0)
{
return speedCompare;
}
return x.EntityArtilleryUnit.Weight.CompareTo(y.EntityArtilleryUnit.Weight);
}
}

View File

@ -38,36 +38,36 @@ namespace ProjectArtilleryUnit.Drawnings
return;
}
Pen pen = new(entityMilitaryArtilleryUnit.AdditionalColor, 2);
Pen pen2 = new(Color.Black, 2);
Pen pen3 = new(Color.Red, 4);
Brush additionalBrush = new SolidBrush(entityMilitaryArtilleryUnit.AdditionalColor);
//внутренности танка
Pen pen = new(entityMilitaryArtilleryUnit.BodyColor, 2);
Brush additionalBrush = new SolidBrush(Color.Black);
Brush lukeBrush = new SolidBrush(Color.Black);
Brush lukeBrush2 = new SolidBrush(entityMilitaryArtilleryUnit.AdditionalColor);
Brush muzzleBrush = new HatchBrush(HatchStyle.ZigZag, entityMilitaryArtilleryUnit.AdditionalColor, Color.FromArgb(163, 163, 163));
Brush gunBrush = new SolidBrush(entityMilitaryArtilleryUnit.AdditionalColor);
base.DrawTransport(g);
if (entityMilitaryArtilleryUnit.Muzzle)
{
g.FillRectangle(additionalBrush, _startPosX.Value + 10, _startPosY.Value + 11, 35, 3);
g.DrawRectangle(pen2, _startPosX.Value + 10, _startPosY.Value + 11, 35, 3);
g.FillEllipse(muzzleBrush, _startPosX.Value + 5, _startPosY.Value + 9, 25, 30);
g.DrawEllipse(pen, _startPosX.Value + 5, _startPosY.Value + 9, 25, 30);
}
if (entityMilitaryArtilleryUnit.Gun)
{
g.DrawLine(pen3, _startPosX.Value + 113, _startPosY.Value + 11, _startPosX.Value + 119, _startPosY.Value + 13);
g.DrawLine(pen3, _startPosX.Value + 115, _startPosY.Value + 6, _startPosX.Value + 121, _startPosY.Value + 8);
g.DrawLine(pen3, _startPosX.Value + 117, _startPosY.Value + 1, _startPosX.Value + 123, _startPosY.Value + 4);
Point[] points2 = { new Point(_startPosX.Value + 122, _startPosY.Value - 1), new Point(_startPosX.Value + 147, _startPosY.Value + 6), new Point(_startPosX.Value + 142, _startPosY.Value + 21), new Point(_startPosX.Value + 117, _startPosY.Value + 16) };
g.FillPolygon(additionalBrush, points2);
g.DrawPolygon(pen2, points2);
g.DrawEllipse(pen, _startPosX.Value + 34, _startPosY.Value + 2, 30, 7);
g.FillEllipse(gunBrush, _startPosX.Value + 34, _startPosY.Value + 2, 30, 7);
g.DrawEllipse(pen, _startPosX.Value + 34, _startPosY.Value + 39, 30, 7);
g.FillEllipse(gunBrush, _startPosX.Value + 34, _startPosY.Value + 39, 30, 7);
}
if (entityMilitaryArtilleryUnit.Luke)
{
g.DrawRectangle(pen, _startPosX.Value + 60, _startPosY.Value + 4, 25, 2);
g.DrawEllipse(pen, _startPosX.Value + 97, _startPosY.Value + 36, 10, 10);
g.FillEllipse(lukeBrush2, _startPosX.Value + 97, _startPosY.Value + 36, 10, 10);
g.FillRectangle(lukeBrush, _startPosX.Value + 107, _startPosY.Value + 40, 15, 5);
}
}

View File

@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
namespace ProjectArtilleryUnit.Exceptions;
[Serializable]
internal class ObjectAlreadyInCollectionException : ApplicationException
{
public ObjectAlreadyInCollectionException(int index) : base("Такой объект уже присутствует в коллекции. Позиция " + index) { }
public ObjectAlreadyInCollectionException() : base() { }
public ObjectAlreadyInCollectionException(string message) : base(message) { }
public ObjectAlreadyInCollectionException(string message, Exception exception) : base(message, exception) { }
protected ObjectAlreadyInCollectionException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
}

View File

@ -41,7 +41,7 @@ namespace ProjectArtilleryUnit
}
/// <summary>
/// Метод прорисовки круисера
/// Метод прорисовки артиллерийской установки
/// </summary>
private void Draw()
{

View File

@ -167,9 +167,9 @@
checkBoxLuke.AutoSize = true;
checkBoxLuke.Location = new Point(6, 217);
checkBoxLuke.Name = "checkBoxLuke";
checkBoxLuke.Size = new Size(193, 24);
checkBoxLuke.Size = new Size(202, 24);
checkBoxLuke.TabIndex = 8;
checkBoxLuke.Text = "Признак наличие люка";
checkBoxLuke.Text = "Признак наличие пушки";
checkBoxLuke.UseVisualStyleBackColor = true;
//
// checkBoxGun
@ -177,20 +177,19 @@
checkBoxGun.AutoSize = true;
checkBoxGun.Location = new Point(6, 169);
checkBoxGun.Name = "checkBoxGun";
checkBoxGun.Size = new Size(297, 24);
checkBoxGun.Size = new Size(215, 24);
checkBoxGun.TabIndex = 7;
checkBoxGun.Text = "Признак наличие ракетной установки";
checkBoxGun.Text = "Признак наличие шлюпок";
checkBoxGun.UseVisualStyleBackColor = true;
checkBoxGun.CheckedChanged += checkBoxGun_CheckedChanged;
//
// checkBoxMuzzle
//
checkBoxMuzzle.AutoSize = true;
checkBoxMuzzle.Location = new Point(6, 123);
checkBoxMuzzle.Name = "checkBoxMuzzle";
checkBoxMuzzle.Size = new Size(189, 24);
checkBoxMuzzle.Size = new Size(321, 24);
checkBoxMuzzle.TabIndex = 6;
checkBoxMuzzle.Text = "Признак наличие дула";
checkBoxMuzzle.Text = "Признак наличие вертолетной площадки";
checkBoxMuzzle.UseVisualStyleBackColor = true;
//
// numericUpDownWeight

View File

@ -172,10 +172,5 @@ namespace ProjectArtilleryUnit
Close();
}
}
private void checkBoxGun_CheckedChanged(object sender, EventArgs e)
{
}
}
}

View File

@ -40,6 +40,8 @@
labelCollectionName = new Label();
comboBoxSelectorCompany = new ComboBox();
panelCompanyTools = new Panel();
buttonSortByColor = new Button();
buttonSortByType = new Button();
ButtonAddArtilleryUnit = new Button();
buttonRefresh = new Button();
ButtonRemoveArtilleryUnit = new Button();
@ -66,18 +68,21 @@
groupBoxTools.Controls.Add(comboBoxSelectorCompany);
groupBoxTools.Controls.Add(panelCompanyTools);
groupBoxTools.Dock = DockStyle.Right;
groupBoxTools.Location = new Point(631, 28);
groupBoxTools.Location = new Point(552, 24);
groupBoxTools.Margin = new Padding(3, 2, 3, 2);
groupBoxTools.Name = "groupBoxTools";
groupBoxTools.Size = new Size(222, 651);
groupBoxTools.Padding = new Padding(3, 2, 3, 2);
groupBoxTools.Size = new Size(194, 492);
groupBoxTools.TabIndex = 0;
groupBoxTools.TabStop = false;
groupBoxTools.Text = "инструменты";
//
// buttonCreateCompany
//
buttonCreateCompany.Location = new Point(21, 345);
buttonCreateCompany.Location = new Point(18, 259);
buttonCreateCompany.Margin = new Padding(3, 2, 3, 2);
buttonCreateCompany.Name = "buttonCreateCompany";
buttonCreateCompany.Size = new Size(186, 27);
buttonCreateCompany.Size = new Size(163, 20);
buttonCreateCompany.TabIndex = 7;
buttonCreateCompany.Text = "Создать компанию";
buttonCreateCompany.UseVisualStyleBackColor = true;
@ -93,16 +98,18 @@
panelStorage.Controls.Add(textBoxCollectionName);
panelStorage.Controls.Add(labelCollectionName);
panelStorage.Dock = DockStyle.Top;
panelStorage.Location = new Point(3, 23);
panelStorage.Location = new Point(3, 18);
panelStorage.Margin = new Padding(3, 2, 3, 2);
panelStorage.Name = "panelStorage";
panelStorage.Size = new Size(216, 283);
panelStorage.Size = new Size(188, 212);
panelStorage.TabIndex = 6;
//
// buttonCollectionDel
//
buttonCollectionDel.Location = new Point(17, 247);
buttonCollectionDel.Location = new Point(15, 185);
buttonCollectionDel.Margin = new Padding(3, 2, 3, 2);
buttonCollectionDel.Name = "buttonCollectionDel";
buttonCollectionDel.Size = new Size(186, 27);
buttonCollectionDel.Size = new Size(163, 20);
buttonCollectionDel.TabIndex = 6;
buttonCollectionDel.Text = "Удалить коллекцию";
buttonCollectionDel.UseVisualStyleBackColor = true;
@ -111,16 +118,19 @@
// listBoxCollection
//
listBoxCollection.FormattingEnabled = true;
listBoxCollection.Location = new Point(17, 137);
listBoxCollection.ItemHeight = 15;
listBoxCollection.Location = new Point(15, 103);
listBoxCollection.Margin = new Padding(3, 2, 3, 2);
listBoxCollection.Name = "listBoxCollection";
listBoxCollection.Size = new Size(186, 104);
listBoxCollection.Size = new Size(163, 79);
listBoxCollection.TabIndex = 5;
//
// buttonCollecctionAdd
//
buttonCollecctionAdd.Location = new Point(17, 104);
buttonCollecctionAdd.Location = new Point(15, 78);
buttonCollecctionAdd.Margin = new Padding(3, 2, 3, 2);
buttonCollecctionAdd.Name = "buttonCollecctionAdd";
buttonCollecctionAdd.Size = new Size(186, 27);
buttonCollecctionAdd.Size = new Size(163, 20);
buttonCollecctionAdd.TabIndex = 4;
buttonCollecctionAdd.Text = "Добавить коллекцию";
buttonCollecctionAdd.UseVisualStyleBackColor = true;
@ -129,9 +139,10 @@
// radioButtonList
//
radioButtonList.AutoSize = true;
radioButtonList.Location = new Point(123, 75);
radioButtonList.Location = new Point(108, 56);
radioButtonList.Margin = new Padding(3, 2, 3, 2);
radioButtonList.Name = "radioButtonList";
radioButtonList.Size = new Size(80, 24);
radioButtonList.Size = new Size(66, 19);
radioButtonList.TabIndex = 3;
radioButtonList.TabStop = true;
radioButtonList.Text = "Список";
@ -140,9 +151,10 @@
// radioButtonMassive
//
radioButtonMassive.AutoSize = true;
radioButtonMassive.Location = new Point(17, 75);
radioButtonMassive.Location = new Point(15, 56);
radioButtonMassive.Margin = new Padding(3, 2, 3, 2);
radioButtonMassive.Name = "radioButtonMassive";
radioButtonMassive.Size = new Size(82, 24);
radioButtonMassive.Size = new Size(67, 19);
radioButtonMassive.TabIndex = 2;
radioButtonMassive.TabStop = true;
radioButtonMassive.Text = "Массив";
@ -150,17 +162,18 @@
//
// textBoxCollectionName
//
textBoxCollectionName.Location = new Point(17, 32);
textBoxCollectionName.Location = new Point(15, 24);
textBoxCollectionName.Margin = new Padding(3, 2, 3, 2);
textBoxCollectionName.Name = "textBoxCollectionName";
textBoxCollectionName.Size = new Size(186, 27);
textBoxCollectionName.Size = new Size(163, 23);
textBoxCollectionName.TabIndex = 1;
//
// labelCollectionName
//
labelCollectionName.AutoSize = true;
labelCollectionName.Location = new Point(26, 9);
labelCollectionName.Location = new Point(23, 7);
labelCollectionName.Name = "labelCollectionName";
labelCollectionName.Size = new Size(155, 20);
labelCollectionName.Size = new Size(122, 15);
labelCollectionName.TabIndex = 0;
labelCollectionName.Text = "Название коллекции";
//
@ -169,43 +182,73 @@
comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxSelectorCompany.FormattingEnabled = true;
comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" });
comboBoxSelectorCompany.Location = new Point(21, 311);
comboBoxSelectorCompany.Location = new Point(18, 233);
comboBoxSelectorCompany.Margin = new Padding(3, 2, 3, 2);
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
comboBoxSelectorCompany.Size = new Size(186, 28);
comboBoxSelectorCompany.Size = new Size(163, 23);
comboBoxSelectorCompany.TabIndex = 0;
comboBoxSelectorCompany.SelectedIndexChanged += comboBoxSelectorCompany_SelectedIndexChanged_1;
//
// panelCompanyTools
//
panelCompanyTools.Controls.Add(buttonSortByColor);
panelCompanyTools.Controls.Add(buttonSortByType);
panelCompanyTools.Controls.Add(ButtonAddArtilleryUnit);
panelCompanyTools.Controls.Add(buttonRefresh);
panelCompanyTools.Controls.Add(ButtonRemoveArtilleryUnit);
panelCompanyTools.Controls.Add(maskedTextBoxPosision);
panelCompanyTools.Controls.Add(buttonGetToTest);
panelCompanyTools.Enabled = false;
panelCompanyTools.Location = new Point(3, 379);
panelCompanyTools.Location = new Point(3, 284);
panelCompanyTools.Margin = new Padding(3, 2, 3, 2);
panelCompanyTools.Name = "panelCompanyTools";
panelCompanyTools.Size = new Size(216, 274);
panelCompanyTools.Size = new Size(189, 206);
panelCompanyTools.TabIndex = 8;
//
// buttonSortByColor
//
buttonSortByColor.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonSortByColor.Location = new Point(17, 181);
buttonSortByColor.Margin = new Padding(3, 2, 3, 2);
buttonSortByColor.Name = "buttonSortByColor";
buttonSortByColor.Size = new Size(163, 23);
buttonSortByColor.TabIndex = 7;
buttonSortByColor.Text = "Сортировка по цвету";
buttonSortByColor.UseVisualStyleBackColor = true;
buttonSortByColor.Click += ButtonSortByColor_Click;
//
// buttonSortByType
//
buttonSortByType.Anchor = AnchorStyles.Right;
buttonSortByType.Location = new Point(17, 149);
buttonSortByType.Margin = new Padding(3, 2, 3, 2);
buttonSortByType.Name = "buttonSortByType";
buttonSortByType.Size = new Size(163, 28);
buttonSortByType.TabIndex = 6;
buttonSortByType.Text = "Сортировка по типу";
buttonSortByType.UseVisualStyleBackColor = true;
buttonSortByType.Click += ButtonSortByType_Click;
//
// ButtonAddArtilleryUnit
//
ButtonAddArtilleryUnit.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
ButtonAddArtilleryUnit.BackgroundImageLayout = ImageLayout.Center;
ButtonAddArtilleryUnit.Location = new Point(18, 3);
ButtonAddArtilleryUnit.Location = new Point(16, 2);
ButtonAddArtilleryUnit.Margin = new Padding(3, 2, 3, 2);
ButtonAddArtilleryUnit.Name = "ButtonAddArtilleryUnit";
ButtonAddArtilleryUnit.Size = new Size(186, 40);
ButtonAddArtilleryUnit.Size = new Size(163, 39);
ButtonAddArtilleryUnit.TabIndex = 1;
ButtonAddArtilleryUnit.Text = "добваление установки";
ButtonAddArtilleryUnit.Text = "добваление артиллерийской установки";
ButtonAddArtilleryUnit.UseVisualStyleBackColor = true;
ButtonAddArtilleryUnit.Click += ButtonAddArtilleryUnit_Click;
//
// buttonRefresh
//
buttonRefresh.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonRefresh.Location = new Point(18, 227);
buttonRefresh.Location = new Point(17, 123);
buttonRefresh.Margin = new Padding(3, 2, 3, 2);
buttonRefresh.Name = "buttonRefresh";
buttonRefresh.Size = new Size(186, 41);
buttonRefresh.Size = new Size(163, 22);
buttonRefresh.TabIndex = 5;
buttonRefresh.Text = "обновить";
buttonRefresh.UseVisualStyleBackColor = true;
@ -214,9 +257,10 @@
// ButtonRemoveArtilleryUnit
//
ButtonRemoveArtilleryUnit.Anchor = AnchorStyles.Right;
ButtonRemoveArtilleryUnit.Location = new Point(18, 138);
ButtonRemoveArtilleryUnit.Location = new Point(17, 74);
ButtonRemoveArtilleryUnit.Margin = new Padding(3, 2, 3, 2);
ButtonRemoveArtilleryUnit.Name = "ButtonRemoveArtilleryUnit";
ButtonRemoveArtilleryUnit.Size = new Size(186, 40);
ButtonRemoveArtilleryUnit.Size = new Size(163, 21);
ButtonRemoveArtilleryUnit.TabIndex = 3;
ButtonRemoveArtilleryUnit.Text = "удалить установку";
ButtonRemoveArtilleryUnit.UseVisualStyleBackColor = true;
@ -224,19 +268,21 @@
//
// maskedTextBoxPosision
//
maskedTextBoxPosision.Location = new Point(17, 105);
maskedTextBoxPosision.Location = new Point(16, 45);
maskedTextBoxPosision.Margin = new Padding(3, 2, 3, 2);
maskedTextBoxPosision.Mask = "00";
maskedTextBoxPosision.Name = "maskedTextBoxPosision";
maskedTextBoxPosision.Size = new Size(187, 27);
maskedTextBoxPosision.Size = new Size(164, 23);
maskedTextBoxPosision.TabIndex = 2;
maskedTextBoxPosision.ValidatingType = typeof(int);
//
// buttonGetToTest
//
buttonGetToTest.Anchor = AnchorStyles.Right;
buttonGetToTest.Location = new Point(18, 184);
buttonGetToTest.Location = new Point(16, 99);
buttonGetToTest.Margin = new Padding(3, 2, 3, 2);
buttonGetToTest.Name = "buttonGetToTest";
buttonGetToTest.Size = new Size(186, 40);
buttonGetToTest.Size = new Size(163, 20);
buttonGetToTest.TabIndex = 4;
buttonGetToTest.Text = "передать на тесты";
buttonGetToTest.UseVisualStyleBackColor = true;
@ -245,12 +291,12 @@
// pictureBoxArtilleryUnit
//
pictureBoxArtilleryUnit.Dock = DockStyle.Fill;
pictureBoxArtilleryUnit.Location = new Point(0, 28);
pictureBoxArtilleryUnit.Location = new Point(0, 24);
pictureBoxArtilleryUnit.Margin = new Padding(3, 2, 3, 2);
pictureBoxArtilleryUnit.Name = "pictureBoxArtilleryUnit";
pictureBoxArtilleryUnit.Size = new Size(631, 651);
pictureBoxArtilleryUnit.Size = new Size(552, 492);
pictureBoxArtilleryUnit.TabIndex = 1;
pictureBoxArtilleryUnit.TabStop = false;
pictureBoxArtilleryUnit.Click += pictureBoxArtilleryUnit_Click;
//
// menuStrip
//
@ -258,7 +304,8 @@
menuStrip.Items.AddRange(new ToolStripItem[] { файлToolStripMenuItem });
menuStrip.Location = new Point(0, 0);
menuStrip.Name = "menuStrip";
menuStrip.Size = new Size(853, 28);
menuStrip.Padding = new Padding(5, 2, 0, 2);
menuStrip.Size = new Size(746, 24);
menuStrip.TabIndex = 2;
menuStrip.Text = "menuStrip1";
//
@ -266,14 +313,14 @@
//
файлToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { saveToolStripMenuItem, loadToolStripMenuItem });
файлToolStripMenuItem.Name = айлToolStripMenuItem";
файлToolStripMenuItem.Size = new Size(59, 24);
файлToolStripMenuItem.Size = new Size(48, 20);
файлToolStripMenuItem.Text = "Файл";
//
// saveToolStripMenuItem
//
saveToolStripMenuItem.Name = "saveToolStripMenuItem";
saveToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.S;
saveToolStripMenuItem.Size = new Size(227, 26);
saveToolStripMenuItem.Size = new Size(181, 22);
saveToolStripMenuItem.Text = "Сохранение";
saveToolStripMenuItem.Click += SaveToolStripMenuItem_Click;
//
@ -281,7 +328,7 @@
//
loadToolStripMenuItem.Name = "loadToolStripMenuItem";
loadToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.L;
loadToolStripMenuItem.Size = new Size(227, 26);
loadToolStripMenuItem.Size = new Size(181, 22);
loadToolStripMenuItem.Text = "Загрузка";
loadToolStripMenuItem.Click += LoadToolStripMenuItem_Click;
//
@ -295,15 +342,17 @@
//
// FormArtilleryUnitsCollection
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(853, 679);
ClientSize = new Size(746, 516);
Controls.Add(pictureBoxArtilleryUnit);
Controls.Add(groupBoxTools);
Controls.Add(menuStrip);
MainMenuStrip = menuStrip;
Margin = new Padding(3, 2, 3, 2);
Name = "FormArtilleryUnitsCollection";
Text = "FormArtilleryUnitsCollection";
Load += FormArtilleryUnitsCollection_Load;
groupBoxTools.ResumeLayout(false);
panelStorage.ResumeLayout(false);
panelStorage.PerformLayout();
@ -342,5 +391,7 @@
private ToolStripMenuItem loadToolStripMenuItem;
private SaveFileDialog saveFileDialog;
private OpenFileDialog openFileDialog;
private Button buttonSortByColor;
private Button buttonSortByType;
}
}

View File

@ -1,6 +1,7 @@
using Microsoft.Extensions.Logging;
using ProjectArtilleryUnit.CollectionGenericObjects;
using ProjectArtilleryUnit.Drawnings;
using System.Windows.Forms;
namespace ProjectArtilleryUnit
{
@ -174,17 +175,11 @@ namespace ProjectArtilleryUnit
collectionType = CollectionType.List;
}
try
{
_storageCollection.AddCollection(textBoxCollectionName.Text, collectionType);
_logger.LogInformation("Добавление коллекции");
RerfreshListBoxItems();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
_logger.LogError($"Ошибка: {ex.Message}", ex.Message);
}
CollectionInfo collectionInfo = new CollectionInfo(textBoxCollectionName.Text, collectionType, string.Empty);
_storageCollection.AddCollection(collectionInfo);
_logger.LogInformation("Добавление коллекции");
RerfreshListBoxItems();
}
/// <summary>
@ -203,7 +198,10 @@ namespace ProjectArtilleryUnit
{
return;
}
_storageCollection.DelCollection(listBoxCollection.SelectedItem.ToString());
CollectionInfo collectionInfo = new CollectionInfo(listBoxCollection.SelectedItem.ToString(), CollectionType.None, string.Empty);
_storageCollection.DelCollection(collectionInfo);
_logger.LogInformation("Коллекция удалена");
RerfreshListBoxItems();
}
@ -216,7 +214,7 @@ namespace ProjectArtilleryUnit
listBoxCollection.Items.Clear();
for (int i = 0; i < _storageCollection.Keys?.Count; ++i)
{
string? colName = _storageCollection.Keys?[i];
string? colName = _storageCollection.Keys?[i].Name;
if (!string.IsNullOrEmpty(colName))
{
listBoxCollection.Items.Add(colName);
@ -237,8 +235,8 @@ namespace ProjectArtilleryUnit
return;
}
ICollectionGenericObjects<DrawningArtilleryUnit>? collection =
_storageCollection[listBoxCollection.SelectedItem.ToString() ?? string.Empty];
CollectionInfo collectionInfo = new CollectionInfo(listBoxCollection.SelectedItem.ToString(), CollectionType.None, string.Empty);
ICollectionGenericObjects<DrawningArtilleryUnit>? collection = _storageCollection[collectionInfo];
if (collection == null)
{
MessageBox.Show("Коллекция не проинициализирована");
@ -253,6 +251,7 @@ namespace ProjectArtilleryUnit
break;
}
panelCompanyTools.Enabled = true;
RerfreshListBoxItems();
}
@ -303,7 +302,41 @@ namespace ProjectArtilleryUnit
}
}
private void pictureBoxArtilleryUnit_Click(object sender, EventArgs e)
/// <summary>
/// Сортировка по типу
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonSortByType_Click(object sender, EventArgs e)
{
CompareArtilleryUnits(new DrawningArtilleryUnitCompareByType());
}
/// <summary>
/// Сортировка по цвету
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonSortByColor_Click(object sender, EventArgs e)
{
CompareArtilleryUnits(new DrawningArtilleryUnitCompareByColor());
}
/// <summary>
/// Сортировка по сравнителю
/// </summary>
/// <param name="comparer">Сравнитель объектов</param>
private void CompareArtilleryUnits(IComparer<DrawningArtilleryUnit?> comparer)
{
if (_company == null)
{
return;
}
_company.Sort(comparer);
pictureBoxArtilleryUnit.Image = _company.Show();
}
private void FormArtilleryUnitsCollection_Load(object sender, EventArgs e)
{
}