diff --git a/ArtilleryUnit/ArtilleryUnit/CollectionGenericObjects/AbstractCompany.cs b/ArtilleryUnit/ArtilleryUnit/CollectionGenericObjects/AbstractCompany.cs index d244738..db83ea0 100644 --- a/ArtilleryUnit/ArtilleryUnit/CollectionGenericObjects/AbstractCompany.cs +++ b/ArtilleryUnit/ArtilleryUnit/CollectionGenericObjects/AbstractCompany.cs @@ -28,7 +28,7 @@ namespace ProjectArtilleryUnit.CollectionGenericObjects protected readonly int _pictureHeight; /// - /// Коллекция артиллирийских установок + /// Коллекция крейсеров /// protected ICollectionGenericObjects? _collection = null; @@ -49,7 +49,7 @@ namespace ProjectArtilleryUnit.CollectionGenericObjects _pictureWidth = picWidth; _pictureHeight = picHeight; _collection = collection; - _collection.SetMaxCount = GetMaxCount; + _collection.MaxCount = GetMaxCount; } /// diff --git a/ArtilleryUnit/ArtilleryUnit/CollectionGenericObjects/ArtilleryUnitDockingService.cs b/ArtilleryUnit/ArtilleryUnit/CollectionGenericObjects/CruiserDockingService.cs similarity index 96% rename from ArtilleryUnit/ArtilleryUnit/CollectionGenericObjects/ArtilleryUnitDockingService.cs rename to ArtilleryUnit/ArtilleryUnit/CollectionGenericObjects/CruiserDockingService.cs index 5b8e7bb..74991a8 100644 --- a/ArtilleryUnit/ArtilleryUnit/CollectionGenericObjects/ArtilleryUnitDockingService.cs +++ b/ArtilleryUnit/ArtilleryUnit/CollectionGenericObjects/CruiserDockingService.cs @@ -22,7 +22,7 @@ namespace ProjectArtilleryUnit.CollectionGenericObjects int width = _pictureWidth / _placeSizeWidth; int height = _pictureHeight / _placeSizeHeight; Pen pen = new(Color.Black, 2); - for (int i = 0; i < width + 1; i++) + for (int i = 0; i < width; i++) { for (int j = 0; j < height + 1; ++j) { @@ -47,7 +47,7 @@ namespace ProjectArtilleryUnit.CollectionGenericObjects _collection.Get(i).SetPosition(_placeSizeWidth * curWidth + 10, curHeight * _placeSizeHeight + 10); } - if (curWidth < width) + if (curWidth < width - 1) curWidth++; else { diff --git a/ArtilleryUnit/ArtilleryUnit/CollectionGenericObjects/ICollectionGenericObjects.cs b/ArtilleryUnit/ArtilleryUnit/CollectionGenericObjects/ICollectionGenericObjects.cs index 1b2405d..e9d9f1c 100644 --- a/ArtilleryUnit/ArtilleryUnit/CollectionGenericObjects/ICollectionGenericObjects.cs +++ b/ArtilleryUnit/ArtilleryUnit/CollectionGenericObjects/ICollectionGenericObjects.cs @@ -15,7 +15,7 @@ /// /// Установка максимального количества элементов /// - int SetMaxCount { set; } + int MaxCount { get; set; } /// /// Добавление объекта в коллекцию @@ -45,6 +45,17 @@ /// Позиция /// Объект T? Get(int position); + + /// + /// Получение типа коллекции + /// + CollectionType GetCollectionType { get; } + /// + /// Получение объектов коллекции по одному + /// + /// Поэлементый вывод элементов коллекции + IEnumerable GetItems(); + } } diff --git a/ArtilleryUnit/ArtilleryUnit/CollectionGenericObjects/ListGenericObjects.cs b/ArtilleryUnit/ArtilleryUnit/CollectionGenericObjects/ListGenericObjects.cs index 87474d7..429844a 100644 --- a/ArtilleryUnit/ArtilleryUnit/CollectionGenericObjects/ListGenericObjects.cs +++ b/ArtilleryUnit/ArtilleryUnit/CollectionGenericObjects/ListGenericObjects.cs @@ -16,7 +16,20 @@ /// private int _maxCount; public int Count => _collection.Count; - public int SetMaxCount { set { if (value > 0) { _maxCount = value; } } } + public int MaxCount + { + get => _maxCount; + set + { + if (value > 0) + { + _maxCount = value; + } + } + } + + public CollectionType GetCollectionType => CollectionType.List; + /// /// Конструктор /// @@ -61,5 +74,13 @@ _collection.RemoveAt(position); return obj; } + + public IEnumerable GetItems() + { + for (int i = 0; i < _collection.Count; ++i) + { + yield return _collection[i]; + } + } } } diff --git a/ArtilleryUnit/ArtilleryUnit/CollectionGenericObjects/MassiveGenericObjects.cs b/ArtilleryUnit/ArtilleryUnit/CollectionGenericObjects/MassiveGenericObjects.cs index 42ea920..17d0d1e 100644 --- a/ArtilleryUnit/ArtilleryUnit/CollectionGenericObjects/MassiveGenericObjects.cs +++ b/ArtilleryUnit/ArtilleryUnit/CollectionGenericObjects/MassiveGenericObjects.cs @@ -14,8 +14,12 @@ namespace ProjectArtilleryUnit.CollectionGenericObjects /// private T?[] _collection; public int Count => _collection.Length; - public int SetMaxCount + public int MaxCount { + get + { + return _collection.Length; + } set { if (value > 0) @@ -32,6 +36,8 @@ namespace ProjectArtilleryUnit.CollectionGenericObjects } } + public CollectionType GetCollectionType => CollectionType.Massive; + /// /// Конструктор /// @@ -111,5 +117,13 @@ namespace ProjectArtilleryUnit.CollectionGenericObjects _collection[position] = null; return obj; } + + public IEnumerable GetItems() + { + for (int i = 0; i < _collection.Length; ++i) + { + yield return _collection[i]; + } + } } } diff --git a/ArtilleryUnit/ArtilleryUnit/CollectionGenericObjects/StorageCollection.cs b/ArtilleryUnit/ArtilleryUnit/CollectionGenericObjects/StorageCollection.cs index ddbbc37..26be2c3 100644 --- a/ArtilleryUnit/ArtilleryUnit/CollectionGenericObjects/StorageCollection.cs +++ b/ArtilleryUnit/ArtilleryUnit/CollectionGenericObjects/StorageCollection.cs @@ -1,10 +1,13 @@ -namespace ProjectArtilleryUnit.CollectionGenericObjects +using ProjectArtilleryUnit.Drawnings; +using System.Text; + +namespace ProjectArtilleryUnit.CollectionGenericObjects { // Класс-хранилище коллекций /// /// public class StorageCollection - where T : class + where T : DrawningArtilleryUnit { /// /// Словарь (хранилище) с коллекциями @@ -16,6 +19,21 @@ /// public List Keys => _storages.Keys.ToList(); + /// + /// Ключевое слово, с которого должен начинаться файл + /// + private readonly string _collectionKey = "CollectionsStorage"; + + /// + /// Разделитель для записи ключа и значения элемента словаря + /// + private readonly string _separatorForKeyValue = "|"; + + /// + /// Разделитель для записей коллекции данных в файл + /// + private readonly string _separatorItems = ";"; + /// /// Конструктор /// @@ -69,5 +87,126 @@ return null; } } + + /// + /// Сохранение информации по автомобилям в хранилище в файл + /// + /// Путь и имя файла + /// true - сохранение прошло успешно, false - ошибка при сохранении данных + public bool SaveData(string filename) + { + if (_storages.Count == 0) + { + return false; + } + if (File.Exists(filename)) + { + File.Delete(filename); + } + using (StreamWriter writer = new StreamWriter(filename)) + { + writer.Write(_collectionKey); + foreach (KeyValuePair> value in _storages) + { + StringBuilder sb = new(); + sb.Append(Environment.NewLine); + // не сохраняем пустые коллекции + if (value.Value.Count == 0) + { + continue; + } + + sb.Append(value.Key); + sb.Append(_separatorForKeyValue); + sb.Append(value.Value.GetCollectionType); + sb.Append(_separatorForKeyValue); + sb.Append(value.Value.MaxCount); + sb.Append(_separatorForKeyValue); + foreach (T? item in value.Value.GetItems()) + { + string data = item?.GetDataForSave() ?? string.Empty; + if (string.IsNullOrEmpty(data)) + { + continue; + } + sb.Append(data); + sb.Append(_separatorItems); + } + writer.Write(sb); + } + } + return true; + } + + /// + /// Загрузка информации по автомобилям в хранилище из файла + /// + /// Путь и имя файла + /// true - загрузка прошла успешно, false - ошибка при загрузке данных + public bool LoadData(string filename) + { + if (!File.Exists(filename)) + { + return false; + } + using (StreamReader fs = File.OpenText(filename)) + { + string str = fs.ReadLine(); + if (str == null || str.Length == 0) + { + return false; + } + if (!str.StartsWith(_collectionKey)) + { + return false; + } + _storages.Clear(); + string strs = ""; + while ((strs = fs.ReadLine()) != null) + { + string[] record = strs.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries); + if (record.Length != 4) + { + continue; + } + CollectionType collectionType = (CollectionType)Enum.Parse(typeof(CollectionType), record[1]); + ICollectionGenericObjects? collection = StorageCollection.CreateCollection(collectionType); + if (collection == null) + { + return false; + } + collection.MaxCount = Convert.ToInt32(record[2]); + string[] set = record[3].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries); + foreach (string elem in set) + { + if (elem?.CreateDrawningArtilleryUnit() is T artilleryUnit) + { + if (collection.Insert(artilleryUnit) == -1) + { + return false; + } + } + } + _storages.Add(record[0], collection); + } + return true; + + } + } + + /// + /// Создание коллекции по типу + /// + /// + /// + private static ICollectionGenericObjects? CreateCollection(CollectionType collectionType) + { + return collectionType switch + { + CollectionType.Massive => new MassiveGenericObjects(), + CollectionType.List => new ListGenericObjects(), + _ => null, + }; + } } } diff --git a/ArtilleryUnit/ArtilleryUnit/Drawnings/DrawningArtilleryUnit.cs b/ArtilleryUnit/ArtilleryUnit/Drawnings/DrawningCruiser.cs similarity index 74% rename from ArtilleryUnit/ArtilleryUnit/Drawnings/DrawningArtilleryUnit.cs rename to ArtilleryUnit/ArtilleryUnit/Drawnings/DrawningCruiser.cs index 046c31a..ec7674e 100644 --- a/ArtilleryUnit/ArtilleryUnit/Drawnings/DrawningArtilleryUnit.cs +++ b/ArtilleryUnit/ArtilleryUnit/Drawnings/DrawningCruiser.cs @@ -19,20 +19,20 @@ public class DrawningArtilleryUnit /// private int? _pictureHeight; /// - /// Левая координата прорисовки автомобиля + /// Левая координата прорисовки крейсера /// protected int? _startPosX; /// - /// Верхняя кооридната прорисовки автомобиля + /// Верхняя кооридната прорисовки крейсера /// protected int? _startPosY; /// - /// Ширина прорисовки артиллирийской установки + /// Ширина прорисовки крейсера /// private readonly int _drawningArtilleryUnitWidth = 150; /// - /// Высота прорисовки артиллирийской установки + /// Высота прорисовки крейсера /// private readonly int _drawningArtilleryUnitHeight = 50; private readonly int _drawningEnginesWidth = 3; @@ -57,7 +57,7 @@ public class DrawningArtilleryUnit /// /// Пустой онструктор /// - private DrawningArtilleryUnit() + public DrawningArtilleryUnit() { _pictureWidth = null; _pictureHeight = null; @@ -86,6 +86,15 @@ public class DrawningArtilleryUnit _pictureHeight = drawningCarHeight; } + /// + /// конструктор + /// + /// + public DrawningArtilleryUnit(EntityArtilleryUnit entityArtilleryUnit) + { + EntityArtilleryUnit = entityArtilleryUnit; + } + /// /// Установка границ поля /// @@ -183,6 +192,7 @@ public class DrawningArtilleryUnit return false; } } + /// /// Прорисовка объекта /// @@ -194,33 +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); } } \ No newline at end of file diff --git a/ArtilleryUnit/ArtilleryUnit/Drawnings/DrawningMilitaryArtilleryUnit.cs b/ArtilleryUnit/ArtilleryUnit/Drawnings/DrawningMilitaryArtilleryUnit.cs deleted file mode 100644 index d817ccd..0000000 --- a/ArtilleryUnit/ArtilleryUnit/Drawnings/DrawningMilitaryArtilleryUnit.cs +++ /dev/null @@ -1,66 +0,0 @@ -using System.Drawing.Drawing2D; -using ProjectArtilleryUnit.Entities; - -namespace ProjectArtilleryUnit.Drawnings -{ - public class DrawningMilitaryArtilleryUnit : DrawningArtilleryUnit - { - /// - /// Конструктор - /// - /// Скорость - /// Вес - /// Основной цвет - /// Дополнительный цвет - /// Признак наличия дула - /// Признак наличия ракетной установки - /// Признак наличия люка - - public DrawningMilitaryArtilleryUnit(int speed, double weight, Color bodyColor, Color additionalColor, bool muzzle, bool gun, bool luke) - : base(150, 50) - { - EntityArtilleryUnit = new EntityMilitaryArtilleryUnit(speed, weight, bodyColor, additionalColor, muzzle, gun, luke); - } - - public override void DrawTransport(Graphics g) - { - if (EntityArtilleryUnit == null || EntityArtilleryUnit is not EntityMilitaryArtilleryUnit entityMilitaryArtilleryUnit || !_startPosX.HasValue || - !_startPosY.HasValue) - { - 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); - //внутренности танка - - 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); - } - - 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); - - - } - - if (entityMilitaryArtilleryUnit.Luke) - { - g.DrawRectangle(pen, _startPosX.Value + 60, _startPosY.Value + 4, 25, 2); - } - } - } -} diff --git a/ArtilleryUnit/ArtilleryUnit/Drawnings/DrawningMilitaryCruiser.cs b/ArtilleryUnit/ArtilleryUnit/Drawnings/DrawningMilitaryCruiser.cs new file mode 100644 index 0000000..d3a47ba --- /dev/null +++ b/ArtilleryUnit/ArtilleryUnit/Drawnings/DrawningMilitaryCruiser.cs @@ -0,0 +1,75 @@ +using System.Drawing.Drawing2D; +using ProjectArtilleryUnit.Entities; + +namespace ProjectArtilleryUnit.Drawnings +{ + public class DrawningMilitaryArtilleryUnit : DrawningArtilleryUnit + { + /// + /// Конструктор + /// + /// Скорость + /// Вес + /// Основной цвет + /// Дополнительный цвет + /// Признак наличия вертолетной площадки + /// Признак наличия шлюпок + /// Признак наличия пушки + + public DrawningMilitaryArtilleryUnit(int speed, double weight, Color bodyColor, Color additionalColor, bool muzzle, bool gun, bool luke) + : base(150, 50) + { + EntityArtilleryUnit = new EntityMilitaryArtilleryUnit(speed, weight, bodyColor, additionalColor, muzzle, gun, luke); + } + + public DrawningMilitaryArtilleryUnit(EntityArtilleryUnit entityArtilleryUnit) + { + if (entityArtilleryUnit != null) + { + EntityArtilleryUnit = entityArtilleryUnit; + } + } + + public override void DrawTransport(Graphics g) + { + if (EntityArtilleryUnit == null || EntityArtilleryUnit is not EntityMilitaryArtilleryUnit entityMilitaryArtilleryUnit || !_startPosX.HasValue || + !_startPosY.HasValue) + { + return; + } + + 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.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.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.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); + } + + } + } +} diff --git a/ArtilleryUnit/ArtilleryUnit/Drawnings/ExtentionDrawningCruiser.cs b/ArtilleryUnit/ArtilleryUnit/Drawnings/ExtentionDrawningCruiser.cs new file mode 100644 index 0000000..6b82d7f --- /dev/null +++ b/ArtilleryUnit/ArtilleryUnit/Drawnings/ExtentionDrawningCruiser.cs @@ -0,0 +1,50 @@ +using ProjectArtilleryUnit.Entities; + +namespace ProjectArtilleryUnit.Drawnings +{ + public static class ExtentionDrawningArtilleryUnit + { + /// + /// Разделитель для записи информации по объекту в файл + /// + private static readonly string _separatorForObject = ":"; + + /// + /// Создание объекта из строки + /// + /// Строка с данными для создания объекта + /// Объект + public static DrawningArtilleryUnit? CreateDrawningArtilleryUnit(this string info) + { + string[] strs = info.Split(_separatorForObject); + EntityArtilleryUnit? artilleryUnit = EntityMilitaryArtilleryUnit.CreateEntityMilitaryArtilleryUnit(strs); + if (artilleryUnit != null) + { + return new DrawningMilitaryArtilleryUnit(artilleryUnit); + } + + artilleryUnit = EntityArtilleryUnit.CreateEntityArtilleryUnit(strs); + if (artilleryUnit != null) + { + return new DrawningArtilleryUnit(artilleryUnit); + } + return null; + } + + /// + /// Получение данных для сохранения в файл + /// + /// Сохраняемый объект + /// Строка с данными по объекту + public static string GetDataForSave(this DrawningArtilleryUnit drawningCrusier) + { + string[]? array = drawningCrusier?.EntityArtilleryUnit?.GetStringRepresentation(); + if (array == null) + { + return string.Empty; + } + return string.Join(_separatorForObject, array); + } + + } +} diff --git a/ArtilleryUnit/ArtilleryUnit/Entities/EntityArtilleryUnit.cs b/ArtilleryUnit/ArtilleryUnit/Entities/EntityCruiser.cs similarity index 54% rename from ArtilleryUnit/ArtilleryUnit/Entities/EntityArtilleryUnit.cs rename to ArtilleryUnit/ArtilleryUnit/Entities/EntityCruiser.cs index a1a8376..6a7faf4 100644 --- a/ArtilleryUnit/ArtilleryUnit/Entities/EntityArtilleryUnit.cs +++ b/ArtilleryUnit/ArtilleryUnit/Entities/EntityCruiser.cs @@ -1,7 +1,7 @@ namespace ProjectArtilleryUnit.Entities; /// -/// Класс-сущность "артиллирийская установка" +/// Класс-сущность "крейсер" /// public class EntityArtilleryUnit { @@ -31,7 +31,7 @@ public class EntityArtilleryUnit public double Step => Speed * 100 / Weight; /// - /// Инициализация полей объекта-класса артиллирийской установки + /// Инициализация полей объекта-класса крейсера /// /// скорость /// вес @@ -42,4 +42,28 @@ public class EntityArtilleryUnit Weight = weight; BodyColor = bodyColor; } + + /// + /// Получение строк со значениями свойств объекта класса-сущности + /// + /// + public virtual string[] GetStringRepresentation() + { + return new[] { nameof(EntityArtilleryUnit), Speed.ToString(), Weight.ToString(), BodyColor.Name }; + } + + /// + /// Создание объекта из массива строк + /// + /// + /// + public static EntityArtilleryUnit? CreateEntityArtilleryUnit(string[] strs) + { + if (strs.Length != 4 || strs[0] != nameof(EntityArtilleryUnit)) + { + return null; + } + + return new EntityArtilleryUnit(Convert.ToInt32(strs[1]), Convert.ToDouble(strs[2]), Color.FromName(strs[3])); + } } diff --git a/ArtilleryUnit/ArtilleryUnit/Entities/EntityMilitaryArtilleryUnit.cs b/ArtilleryUnit/ArtilleryUnit/Entities/EntityMilitaryArtilleryUnit.cs deleted file mode 100644 index 462891c..0000000 --- a/ArtilleryUnit/ArtilleryUnit/Entities/EntityMilitaryArtilleryUnit.cs +++ /dev/null @@ -1,37 +0,0 @@ -namespace ProjectArtilleryUnit.Entities -{ - internal class EntityMilitaryArtilleryUnit : EntityArtilleryUnit - { - /// - /// Признак (опция) наличие дула - /// - public bool Muzzle { get; private set; } - - /// - /// Признак (опция) наличие ракетной установки - /// - public bool Gun { get; private set; } - - /// - /// Признак (опция) наличие люка - /// - public bool Luke { get; private set; } - - /// - /// Дополнительный цвет (для опциональных элементов) - /// - public Color AdditionalColor { get; private set; } - public void setAdditionalColor(Color color) - { - AdditionalColor = color; - } - - public EntityMilitaryArtilleryUnit(int speed, double weight, Color bodyColor, Color additionalColor, bool muzzle, bool gun, bool luke) : base(speed, weight, bodyColor) - { - AdditionalColor = additionalColor; - Muzzle = muzzle; - Gun = gun; - Luke = luke; - } - } -} diff --git a/ArtilleryUnit/ArtilleryUnit/Entities/EntityMilitaryCruiser.cs b/ArtilleryUnit/ArtilleryUnit/Entities/EntityMilitaryCruiser.cs new file mode 100644 index 0000000..54964b5 --- /dev/null +++ b/ArtilleryUnit/ArtilleryUnit/Entities/EntityMilitaryCruiser.cs @@ -0,0 +1,62 @@ +namespace ProjectArtilleryUnit.Entities +{ + internal class EntityMilitaryArtilleryUnit : EntityArtilleryUnit + { + /// + /// Признак (опция) наличие вертолетной площадки + /// + public bool Muzzle { get; private set; } + + /// + /// Признак (опция) наличие шлюпок + /// + public bool Gun { get; private set; } + + /// + /// Признак (опция) наличие пушки + /// + public bool Luke { get; private set; } + + /// + /// Дополнительный цвет (для опциональных элементов) + /// + public Color AdditionalColor { get; private set; } + public void setAdditionalColor(Color color) + { + AdditionalColor = color; + } + + public EntityMilitaryArtilleryUnit(int speed, double weight, Color bodyColor, Color additionalColor, bool muzzle, bool gun, bool luke) : base(speed, weight, bodyColor) + { + AdditionalColor = additionalColor; + Muzzle = muzzle; + Gun = gun; + Luke = luke; + } + + /// + /// Получение строк со значениями свойств объекта класса-сущности + /// + /// + public override string[] GetStringRepresentation() + { + return new[] { nameof(EntityArtilleryUnit), Speed.ToString(), Weight.ToString(), BodyColor.Name, AdditionalColor.Name, + Muzzle.ToString(), Gun.ToString(), Luke.ToString() }; + } + + /// + /// Создание объекта из массива строк + /// + /// + /// + public static EntityArtilleryUnit? CreateEntityMilitaryArtilleryUnit(string[] strs) + { + if (strs.Length != 8 || strs[0] != nameof(EntityArtilleryUnit)) + { + return null; + } + return new EntityMilitaryArtilleryUnit(Convert.ToInt32(strs[1]), Convert.ToDouble(strs[2]), Color.FromName(strs[3]), Color.FromName(strs[4]), + Convert.ToBoolean(strs[5]), Convert.ToBoolean(strs[6]), Convert.ToBoolean(strs[7])); + } + } +}