Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0e4ad75bb6 | |||
| de6700f50c |
@@ -48,7 +48,7 @@ public abstract class AbstractCompany
|
||||
_pictureWidth = picWidth;
|
||||
_pictureHeight = picHeight;
|
||||
_collection = collection;
|
||||
_collection.SetMaxCount = GetMaxCount;
|
||||
_collection.MaxCount = GetMaxCount;
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
|
||||
@@ -12,30 +12,82 @@ public class AircraftSharingService : AbstractCompany
|
||||
public AircraftSharingService(int picWidth, int picHeight, ICollectionGenericObjects<DrawningAircraft> collection) : base(picWidth, picHeight, collection)
|
||||
{
|
||||
}
|
||||
private int? _startPosX;
|
||||
private int? _startPosY;
|
||||
private int? ObjPositionX;
|
||||
private int? ObjPositionY;
|
||||
private void DrawPlace(Graphics g)
|
||||
{
|
||||
Pen pen = new(Color.Black);
|
||||
g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value, _placeSizeWidth, _placeSizeHeight);
|
||||
}
|
||||
|
||||
private void DrawPosition(Graphics g)
|
||||
{
|
||||
Pen pen = new(Color.Black);
|
||||
g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value, 2, 2);
|
||||
}
|
||||
|
||||
protected override void DrawBackGround(Graphics g)
|
||||
{
|
||||
Pen pen = new(Color.Black, 3);
|
||||
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
|
||||
_startPosX = 0;
|
||||
_startPosY = 0;
|
||||
for (int x = 0; x <= _pictureWidth; x = x + _placeSizeWidth)
|
||||
{
|
||||
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; j++)
|
||||
if ((_pictureWidth - _placeSizeWidth) > _startPosX)
|
||||
{
|
||||
g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight);
|
||||
for (int y = 0; y <= _pictureHeight; y = y + _placeSizeHeight)
|
||||
{
|
||||
if ((_pictureHeight - _placeSizeHeight) > _startPosY)
|
||||
{
|
||||
DrawPlace(g);
|
||||
_startPosY = _startPosY + _placeSizeHeight;
|
||||
}
|
||||
}
|
||||
_startPosX = _startPosX + _placeSizeWidth;
|
||||
_startPosY = 0;
|
||||
}
|
||||
g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void SetObjectPosition(Graphics g)
|
||||
{
|
||||
for(int i = 0; i < _collection?.Count; i++)
|
||||
_startPosX = 5;
|
||||
_startPosY = 5;
|
||||
int i = 0;
|
||||
|
||||
for (int x = 0; x <= _pictureWidth; x = x + _placeSizeWidth)
|
||||
{
|
||||
if ((_pictureWidth - _placeSizeWidth) > _startPosX)
|
||||
{
|
||||
DrawningAircraft airplane = _collection?.Get(i);
|
||||
if (airplane != null)
|
||||
{
|
||||
int inRow = _pictureWidth / _placeSizeWidth;
|
||||
airplane.SetPosition(((inRow - 1 - (i % inRow)) * _placeSizeWidth), ((_collection.Count / inRow - 1 - i / inRow) * _placeSizeHeight));
|
||||
airplane.DrawTransport(g);
|
||||
ObjPositionX = _startPosX;
|
||||
|
||||
for (int y = 0; y <= _pictureHeight; y = y + _placeSizeHeight)
|
||||
{
|
||||
if ((_pictureHeight - _placeSizeHeight) > _startPosY)
|
||||
{
|
||||
ObjPositionY = _startPosY;
|
||||
if (i < (_collection?.Count))
|
||||
{
|
||||
DrawningAircraft obj = _collection.Get(i);
|
||||
|
||||
if (obj != null)
|
||||
{
|
||||
obj.SetpictureSize(_pictureWidth, _pictureHeight);
|
||||
obj.SetPosition(Convert.ToInt32(ObjPositionX), Convert.ToInt32(ObjPositionY));
|
||||
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
_startPosY = _startPosY + _placeSizeHeight;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
_startPosX = _startPosX + _placeSizeWidth;
|
||||
|
||||
_startPosY = 5;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ public interface ICollectionGenericObjects<T>
|
||||
/// <summary>
|
||||
/// Установка максимального количества элементов
|
||||
/// </summary>
|
||||
int SetMaxCount { set; }
|
||||
int MaxCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Добавление объекта в коллекцию
|
||||
@@ -53,4 +53,15 @@ public interface ICollectionGenericObjects<T>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns>Объект</returns>
|
||||
T? Get(int position);
|
||||
|
||||
/// <summary>
|
||||
/// Получение типа коллекции
|
||||
/// </summary>
|
||||
CollectionType GetCollectionType { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Получение объектов коллекции по одному
|
||||
/// </summary>
|
||||
/// <returns>Поэлементый вывод элементов коллекции</returns>
|
||||
IEnumerable<T?> GetItems();
|
||||
}
|
||||
|
||||
@@ -11,13 +11,13 @@ namespace ProectMilitaryAircraft.CollectionGenericObjects;
|
||||
/// Параметризованный набор объектов
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Параметр : ограничение - ссылочный тип</typeparam>
|
||||
public class ListgenericObjects<T>
|
||||
public class ListGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
where T : class
|
||||
{
|
||||
/// <summary>
|
||||
/// Список объектов, которые храниим
|
||||
/// </summary>
|
||||
private readonly List<T>? _collection;
|
||||
/// Список объектов, которые храним
|
||||
/// </summary>
|
||||
private readonly List<T?> _collection;
|
||||
|
||||
/// <summary>
|
||||
/// Максимально допустимое число объектов в списке
|
||||
@@ -26,93 +26,72 @@ public class ListgenericObjects<T>
|
||||
|
||||
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;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
public ListgenericObjects(int count)
|
||||
public ListGenericObjects()
|
||||
{
|
||||
_maxCount = count;
|
||||
_collection = new();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Получение объекта из набора позиции
|
||||
/// </summary>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public T? this[int position]
|
||||
public T? Get(int position)
|
||||
{
|
||||
get
|
||||
{
|
||||
if (position < 0 || position >= _maxCount)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return _collection?[position];
|
||||
}
|
||||
if (position < 0 || position >= Count) return null;
|
||||
return _collection[position];
|
||||
|
||||
set
|
||||
{
|
||||
if (!(position >= 0 && position < Count && _collection?.Count < _maxCount))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_collection?.Insert(position, value);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Insert(T obj)
|
||||
{
|
||||
if (_collection?.Count == _maxCount)
|
||||
if (Count != _maxCount)
|
||||
{
|
||||
return false;
|
||||
_collection.Add(obj);
|
||||
return true;
|
||||
}
|
||||
|
||||
Insert(obj, 0);
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool Insert(T obj, int position)
|
||||
{
|
||||
if (_collection?.Count == _maxCount)
|
||||
if (position > 0 && position <= _maxCount && Count != _maxCount)
|
||||
{
|
||||
return false;
|
||||
_collection.Insert(position, obj);
|
||||
return true;
|
||||
}
|
||||
|
||||
Insert(obj, 0);
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool Remove(int position)
|
||||
{
|
||||
if (position < 0 || position >= Count)
|
||||
if (_collection[position] != null)
|
||||
{
|
||||
return false;
|
||||
_collection.RemoveAt(position);
|
||||
return true;
|
||||
}
|
||||
|
||||
_collection?.RemoveAt(position);
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Проход по списку
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public IEnumerable<T?> GetTheAirplanes(int? maxTheAirplanes = null)
|
||||
public IEnumerable<T?> GetItems()
|
||||
{
|
||||
for (int i = 0; i < _collection?.Count; ++i)
|
||||
for (int i = 0; i < _collection.Count; ++i)
|
||||
{
|
||||
yield return _collection?[i];
|
||||
if (maxTheAirplanes.HasValue && i == maxTheAirplanes.Value)
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
yield return _collection[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using ProectMilitaryAircraft.Draw;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@@ -11,75 +12,119 @@ namespace ProectMilitaryAircraft.CollectionGenericObjects
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Параметр : Ограничение - ссылочный тип</typeparam>
|
||||
public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
where T : class
|
||||
where T : DrawningAircraft
|
||||
{
|
||||
/// <summary>
|
||||
/// Массив объектов, которые храним
|
||||
/// </summary>
|
||||
private T?[] _massive;
|
||||
public int Count => _massive.Length;
|
||||
private T?[] _collection;
|
||||
|
||||
public int SetMaxCount { set { if (value > 0) { _massive = new T?[value]; } } }
|
||||
public int Count => _collection.Length;
|
||||
|
||||
public int MaxCount {
|
||||
get
|
||||
{
|
||||
return _collection.Length;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value > 0)
|
||||
{
|
||||
if (_collection.Length > 0)
|
||||
{
|
||||
Array.Resize(ref _collection, value);
|
||||
}
|
||||
else
|
||||
{
|
||||
_collection = new T?[value];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public CollectionType GetCollectionType => CollectionType.Massive;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
public MassiveGenericObjects()
|
||||
{
|
||||
_massive = Array.Empty<T>();
|
||||
_collection = Array.Empty<T?>();
|
||||
}
|
||||
|
||||
public T? Get(int position)
|
||||
{
|
||||
if (position < 0 || position >= Count) return null;
|
||||
return _massive[position];
|
||||
if (_collection[position] != null)
|
||||
{
|
||||
return _collection[position];
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Insert(T obj)
|
||||
{
|
||||
int index = 0;
|
||||
while (_massive[index] != null)
|
||||
for (int i = 0; i < _collection.Length; i++)
|
||||
{
|
||||
index++;
|
||||
if (index == Count) { return true; } // false?
|
||||
if (_collection[i] == null)
|
||||
{
|
||||
_collection[i] = obj;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
while (index != 0)
|
||||
{
|
||||
_massive[index] = _massive[index - 1];
|
||||
index--;
|
||||
}
|
||||
_massive[0] = obj;
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool Insert(T obj, int position)
|
||||
{
|
||||
if (position < 0 || position >= Count)
|
||||
if (_collection[position] == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (_massive[position] == null)
|
||||
{
|
||||
_massive[position] = obj;
|
||||
_collection[position] = obj;
|
||||
return true;
|
||||
}
|
||||
int index = position;
|
||||
while (_massive[index] != null) index++;
|
||||
if (index == Count) return false;
|
||||
for (int i = index; i > position; i--)
|
||||
if (_collection[position] != null)
|
||||
{
|
||||
_massive[i] = _massive[i - 1];
|
||||
for (int i = position; i < _collection.Length; i++)
|
||||
{
|
||||
if (_collection[i] == null)
|
||||
{
|
||||
_collection[i] = obj;
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
for (int i = position; i <= 0; i--)
|
||||
{
|
||||
if (_collection[i] == null)
|
||||
{
|
||||
_collection[i] = obj;
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
_massive[position] = obj;
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool Remove(int position)
|
||||
{
|
||||
if (position < 0 || position >= Count) return false;
|
||||
_massive[position] = null;
|
||||
return true;
|
||||
if (_collection[position] != null)
|
||||
{
|
||||
_collection[position] = null;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public IEnumerable<T?> GetItems()
|
||||
{
|
||||
for (int i = 0; i < _collection.Length; ++i)
|
||||
{
|
||||
yield return _collection[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using ProectMilitaryAircraft.MovementStrategy;
|
||||
using ProectMilitaryAircraft.Draw;
|
||||
using ProectMilitaryAircraft.MovementStrategy;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -8,7 +9,7 @@ using System.Threading.Tasks;
|
||||
namespace ProectMilitaryAircraft.CollectionGenericObjects;
|
||||
|
||||
public class StorageCollection<T>
|
||||
where T : class
|
||||
where T : DrawningAircraft
|
||||
{
|
||||
readonly Dictionary<string, ICollectionGenericObjects<T>> _storages;
|
||||
|
||||
@@ -19,6 +20,21 @@ public class StorageCollection<T>
|
||||
_storages = new Dictionary<string, ICollectionGenericObjects<T>>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ключевое слово, с которого должен начинаться файл
|
||||
/// </summary>
|
||||
private readonly string _collectionKey = "CollectionsStorage";
|
||||
|
||||
/// <summary>
|
||||
/// Разделитель для записи ключа и значения элемента словаря
|
||||
/// </summary>
|
||||
private readonly string _separatorForKeyValue = "|";
|
||||
|
||||
/// <summary>
|
||||
/// Разделитель для записей коллекции данных в файл
|
||||
/// </summary>
|
||||
private readonly string _separatorItems = ";";
|
||||
|
||||
public void AddCollection (string name, CollectionType collectionType)
|
||||
{
|
||||
if (name != null && !_storages.ContainsKey(name))
|
||||
@@ -30,7 +46,7 @@ public class StorageCollection<T>
|
||||
}
|
||||
if (collectionType == CollectionType.List)
|
||||
{
|
||||
_storages.Add(name, new MassiveGenericObjects<T>());
|
||||
_storages.Add(name, new ListGenericObjects<T>());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -57,4 +73,145 @@ public class StorageCollection<T>
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Сохранение информации по автомобилям в хранилище в файл
|
||||
/// </summary>
|
||||
/// <param name="filename">Путь и имя файла</param>
|
||||
/// <returns>true - сохранение прошло успешно, false - ошибка при сохранении данных</returns>
|
||||
public bool SaveData(string filename)
|
||||
{
|
||||
if (_storages.Count == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (File.Exists(filename))
|
||||
{
|
||||
File.Delete(filename);
|
||||
}
|
||||
|
||||
StringBuilder sb = new();
|
||||
|
||||
sb.Append(_collectionKey);
|
||||
foreach (KeyValuePair<string, ICollectionGenericObjects<T>> value in _storages)
|
||||
{
|
||||
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.Count);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
using FileStream fs = new(filename, FileMode.Create);
|
||||
byte[] info = new UTF8Encoding(true).GetBytes(sb.ToString());
|
||||
fs.Write(info, 0, info.Length);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Загрузка информации по автомобилям в хранилище из файла
|
||||
/// </summary>
|
||||
/// <param name="filename">Путь и имя файла</param>
|
||||
/// <returns>true - загрузка прошла успешно, false - ошибка при загрузке данных</returns>
|
||||
public bool LoadData(string filename)
|
||||
{
|
||||
if (!File.Exists(filename))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
string bufferTextFromFile = "";
|
||||
using (FileStream fs = new(filename, FileMode.Open))
|
||||
{
|
||||
byte[] b = new byte[fs.Length];
|
||||
UTF8Encoding temp = new(true);
|
||||
while (fs.Read(b, 0, b.Length) > 0)
|
||||
{
|
||||
bufferTextFromFile += temp.GetString(b);
|
||||
}
|
||||
}
|
||||
|
||||
string[] strs = bufferTextFromFile.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (strs == null || strs.Length == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!strs[0].Equals(_collectionKey))
|
||||
{
|
||||
//если нет такой записи, то это не те данные
|
||||
return false;
|
||||
}
|
||||
|
||||
_storages.Clear();
|
||||
foreach (string data in strs)
|
||||
{
|
||||
string[] record = data.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (record.Length != 4)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
CollectionType collectionType = (CollectionType)Enum.Parse(typeof(CollectionType), record[1]);
|
||||
ICollectionGenericObjects<T>? collection = StorageCollection<T>.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?.CreateDrawningCar() is T car)
|
||||
{
|
||||
if (!collection.Insert(car))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_storages.Add(record[0], collection);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Создание коллекции по типу
|
||||
/// </summary>
|
||||
/// <param name="collectionType"></param>
|
||||
/// <returns></returns>
|
||||
private static ICollectionGenericObjects<T>? CreateCollection(CollectionType collectionType)
|
||||
{
|
||||
return collectionType switch
|
||||
{
|
||||
CollectionType.Massive => new MassiveGenericObjects<T>(),
|
||||
CollectionType.List => new ListGenericObjects<T>(),
|
||||
_ => null,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ public class DrawningAircraft
|
||||
/// Верхняя координа прорисовки самолета
|
||||
/// </summary>
|
||||
protected int? _startPosY;
|
||||
public DrawningAircraft aircraft;
|
||||
|
||||
/// <summary>
|
||||
/// Ширина прорисовки самолета
|
||||
@@ -68,14 +69,14 @@ public class DrawningAircraft
|
||||
/// <summary>
|
||||
/// Пустой конструктор
|
||||
/// </summary>
|
||||
private DrawningAircraft()
|
||||
public DrawningAircraft()
|
||||
{
|
||||
_pictureWidth = null;
|
||||
_pictureHeight = null;
|
||||
_startPosX = null;
|
||||
_startPosY = null;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
@@ -90,7 +91,7 @@ public class DrawningAircraft
|
||||
return;
|
||||
}
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
_pictureHeight = height;
|
||||
EntityAircraft = new EntityAircraft(speed, weight, bodyColor);
|
||||
}
|
||||
|
||||
@@ -112,6 +113,18 @@ public class DrawningAircraft
|
||||
_drawingMilitaryAircraftHeight = drawingMilitaryAircraftHeight;
|
||||
EntityAircraft = new EntityAircraft(speed, weight, bodyColor);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор для Drawning
|
||||
/// </summary>
|
||||
/// <param name="speed"></param>
|
||||
/// <param name="weight"></param>
|
||||
/// <param name="bodyColor"></param>
|
||||
public DrawningAircraft(EntityAircraft entityAircraft)
|
||||
{
|
||||
EntityAircraft = entityAircraft;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Установка границ поля
|
||||
/// </summary>
|
||||
@@ -138,8 +151,12 @@ public class DrawningAircraft
|
||||
{
|
||||
return;
|
||||
}
|
||||
//TODO если при установке объекта в эти координаты, он будет "выходить" за границы формы
|
||||
// то надо изменить координаты, чтобы он оставался в этих границах
|
||||
|
||||
if (x > _pictureWidth || x < 0 || y > _pictureHeight || y < 0)
|
||||
{
|
||||
x = 0;
|
||||
y = 0;
|
||||
}
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
}
|
||||
@@ -169,24 +186,21 @@ public class DrawningAircraft
|
||||
return true;
|
||||
//Вправо
|
||||
case DirectionType.Right:
|
||||
#pragma warning disable CS8629 // Тип значения, допускающего NULL, может быть NULL.
|
||||
if (_startPosX.Value + EntityAircraft.Step <= _pictureWidth.Value)
|
||||
|
||||
if (_startPosX.Value + _drawningMilitaryAircraftWidth + EntityAircraft.Step < _pictureWidth)
|
||||
{
|
||||
if (_startPosX + 98 <= _pictureWidth)
|
||||
_startPosX += (int)EntityAircraft.Step;
|
||||
_startPosX += (int)EntityAircraft.Step;
|
||||
}
|
||||
#pragma warning restore CS8629 // Тип значения, допускающего NULL, может быть NULL.
|
||||
|
||||
return true;
|
||||
|
||||
//Влево
|
||||
case DirectionType.Down:
|
||||
#pragma warning disable CS8629 // Тип значения, допускающего NULL, может быть NULL.
|
||||
if (_startPosY.Value + EntityAircraft.Step <= _pictureHeight.Value)
|
||||
|
||||
if (_startPosY.Value + _drawingMilitaryAircraftHeight + EntityAircraft.Step < _pictureHeight)
|
||||
{
|
||||
if (_startPosY + 90 <= _pictureHeight)
|
||||
_startPosY += (int)EntityAircraft.Step;
|
||||
_startPosY += (int)EntityAircraft.Step;
|
||||
}
|
||||
#pragma warning restore CS8629 // Тип значения, допускающего NULL, может быть NULL.
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
|
||||
@@ -15,6 +15,8 @@ namespace ProectMilitaryAircraft.Draw;
|
||||
/// </summary>
|
||||
public class DrawningMilitaryAircraft : DrawningAircraft
|
||||
{
|
||||
private DrawningAircraft aircraft;
|
||||
|
||||
/// <summary>
|
||||
/// Констуктор
|
||||
/// </summary>
|
||||
@@ -34,6 +36,25 @@ public class DrawningMilitaryAircraft : DrawningAircraft
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор для DrawningAircraft2
|
||||
/// </summary>
|
||||
/// <param name="speed"></param>
|
||||
/// <param name="weight"></param>
|
||||
/// <param name="bodyColor"></param>
|
||||
/// <param name="additionalColor"></param>
|
||||
/// <param name="pin"></param>
|
||||
/// <param name="rokets"></param>
|
||||
/// <param name="symbolism"></param>
|
||||
public DrawningMilitaryAircraft(EntityAircraft entityAircraft)
|
||||
{
|
||||
if (entityAircraft != null)
|
||||
{
|
||||
EntityAircraft = entityAircraft;
|
||||
}
|
||||
}
|
||||
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityAircraft is not EntityMilitaryAircraft airCraft || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
@@ -44,33 +65,6 @@ public class DrawningMilitaryAircraft : DrawningAircraft
|
||||
Pen pen = new(Color.Black);
|
||||
Brush abr = new SolidBrush(airCraft.AdditionalColor);
|
||||
|
||||
Brush br = new SolidBrush(airCraft.BodyColor);
|
||||
|
||||
//крыло
|
||||
g.FillRectangle(br, _startPosX.Value + 40, _startPosY.Value, 10, 80);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 40, _startPosY.Value, 10, 80);
|
||||
|
||||
//хвост
|
||||
g.FillRectangle(br, _startPosX.Value + 5, _startPosY.Value + 27, 10, 5);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 5, _startPosY.Value + 27, 10, 5);
|
||||
g.FillRectangle(br, _startPosX.Value + 5, _startPosY.Value + 47, 10, 5);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 5, _startPosY.Value + 47, 10, 5);
|
||||
|
||||
//Границы Самолета
|
||||
|
||||
g.FillRectangle(br, _startPosX.Value + 10, _startPosY.Value + 30, 50, 20);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 30, 50, 20);
|
||||
|
||||
//Хвост (центр)
|
||||
g.FillRectangle(br, _startPosX.Value + 2, _startPosY.Value + 37, 10, 5);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 2, _startPosY.Value + 37, 10, 5);
|
||||
|
||||
//Кабина
|
||||
g.DrawLine(pen, _startPosX.Value + 60, _startPosY.Value + 40, _startPosX.Value + 60, _startPosY.Value + 25);
|
||||
g.DrawLine(pen, _startPosX.Value + 60, _startPosY.Value + 25, _startPosX.Value + 80, _startPosY.Value + 40);
|
||||
g.DrawLine(pen, _startPosX.Value + 80, _startPosY.Value + 40, _startPosX.Value + 60, _startPosY.Value + 55);
|
||||
g.DrawLine(pen, _startPosX.Value + 60, _startPosY.Value + 50, _startPosX.Value + 60, _startPosY.Value + 55);
|
||||
|
||||
base.DrawTransport(g);
|
||||
|
||||
//Ракеты
|
||||
@@ -116,7 +110,7 @@ public class DrawningMilitaryAircraft : DrawningAircraft
|
||||
//Носовая часть
|
||||
g.FillEllipse(abr, _startPosX.Value + 78, _startPosY.Value + 37, 10, 5);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
using ProectMilitaryAircraft.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProectMilitaryAircraft.Draw;
|
||||
|
||||
/// <summary>
|
||||
/// Расширение для класса EntityCar
|
||||
/// </summary>
|
||||
public static class ExtensionDrawningAircraft
|
||||
{
|
||||
/// <summary>
|
||||
/// Разделитель для записи информации по объекту в файл
|
||||
/// </summary>
|
||||
private static readonly string _separatorForObject = ":";
|
||||
|
||||
/// <summary>
|
||||
/// Создание объекта из строки
|
||||
/// </summary>
|
||||
/// <param name="info">Строка с данными для создания объекта</param>
|
||||
/// <returns>Объект</returns>
|
||||
public static DrawningAircraft? CreateDrawningCar(this string info)
|
||||
{
|
||||
string[] strs = info.Split(_separatorForObject);
|
||||
EntityAircraft? aircraft = EntityMilitaryAircraft.CreateEntityMilitaryAircraft(strs);
|
||||
if (aircraft != null)
|
||||
{
|
||||
return new DrawningMilitaryAircraft(aircraft);
|
||||
}
|
||||
|
||||
aircraft = EntityAircraft.CreateEntityAircraft(strs);
|
||||
if (aircraft != null)
|
||||
{
|
||||
return new DrawningAircraft(aircraft);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получение данных для сохранения в файл
|
||||
/// </summary>
|
||||
/// <param name="drawningAircraft">Сохраняемый объект</param>
|
||||
/// <returns>Строка с данными по объекту</returns>
|
||||
public static string GetDataForSave(this DrawningAircraft drawningAircraft)
|
||||
{
|
||||
string[]? array = drawningAircraft?.EntityAircraft?.GetStringRepresentation();
|
||||
|
||||
if (array == null)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
return string.Join(_separatorForObject, array);
|
||||
}
|
||||
}
|
||||
@@ -45,4 +45,27 @@ public class EntityAircraft
|
||||
BodyColor = bodyColor;
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение строк со значениями свойств объекта класса-сущности
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public virtual string[] GetStringRepresentation()
|
||||
{
|
||||
return new[] { nameof(EntityAircraft), Speed.ToString(), Weight.ToString(), BodyColor.Name };
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Создание объекта из массива строк
|
||||
/// </summary>
|
||||
/// <param name="strs"></param>
|
||||
/// <returns></returns>
|
||||
public static EntityAircraft? CreateEntityAircraft(string[] strs)
|
||||
{
|
||||
if (strs.Length != 4 || strs[0] != nameof(EntityAircraft))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new EntityAircraft(Convert.ToInt32(strs[1]), Convert.ToDouble(strs[2]), Color.FromName(strs[3]));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,4 +43,27 @@ public class EntityMilitaryAircraft : EntityAircraft
|
||||
Rokets = rokets;
|
||||
Symbolism = symbolism;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получение строк со значениями свойств объекта класса-сущности
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public override string[] GetStringRepresentation()
|
||||
{
|
||||
return new[] { nameof(EntityMilitaryAircraft), Speed.ToString(), Weight.ToString(), BodyColor.Name, AdditionalColor.Name, Pin.ToString(), Rokets.ToString(),Symbolism.ToString() };
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Создание объекта из массива строк
|
||||
/// </summary>
|
||||
/// <param name="strs"></param>
|
||||
/// <returns></returns>
|
||||
public static EntityMilitaryAircraft? CreateEntityMilitaryAircraft(string[] strs)
|
||||
{
|
||||
if (strs.Length != 8 || strs[0] != nameof(EntityMilitaryAircraft))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new EntityMilitaryAircraft(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]));
|
||||
}
|
||||
}
|
||||
@@ -46,10 +46,17 @@
|
||||
labelCollectionName = new Label();
|
||||
comboBoxSelectorCompany = new ComboBox();
|
||||
pictureBox = new PictureBox();
|
||||
menuStrip = new MenuStrip();
|
||||
файлToolStripMenuItem = new ToolStripMenuItem();
|
||||
saveToolStripMenuItem = new ToolStripMenuItem();
|
||||
loadToolStripMenuItem = new ToolStripMenuItem();
|
||||
saveFileDialog = new SaveFileDialog();
|
||||
openFileDialog = new OpenFileDialog();
|
||||
groupBoxTools.SuspendLayout();
|
||||
panelCompanyTools.SuspendLayout();
|
||||
panelStorage.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
|
||||
menuStrip.SuspendLayout();
|
||||
SuspendLayout();
|
||||
//
|
||||
// groupBoxTools
|
||||
@@ -59,9 +66,9 @@
|
||||
groupBoxTools.Controls.Add(panelStorage);
|
||||
groupBoxTools.Controls.Add(comboBoxSelectorCompany);
|
||||
groupBoxTools.Dock = DockStyle.Right;
|
||||
groupBoxTools.Location = new Point(607, 0);
|
||||
groupBoxTools.Location = new Point(607, 24);
|
||||
groupBoxTools.Name = "groupBoxTools";
|
||||
groupBoxTools.Size = new Size(194, 563);
|
||||
groupBoxTools.Size = new Size(194, 560);
|
||||
groupBoxTools.TabIndex = 0;
|
||||
groupBoxTools.TabStop = false;
|
||||
groupBoxTools.Text = " Инструменты";
|
||||
@@ -239,19 +246,61 @@
|
||||
// pictureBox
|
||||
//
|
||||
pictureBox.Dock = DockStyle.Fill;
|
||||
pictureBox.Location = new Point(0, 0);
|
||||
pictureBox.Location = new Point(0, 24);
|
||||
pictureBox.Name = "pictureBox";
|
||||
pictureBox.Size = new Size(607, 563);
|
||||
pictureBox.Size = new Size(607, 560);
|
||||
pictureBox.TabIndex = 1;
|
||||
pictureBox.TabStop = false;
|
||||
//
|
||||
// menuStrip
|
||||
//
|
||||
menuStrip.Items.AddRange(new ToolStripItem[] { файлToolStripMenuItem });
|
||||
menuStrip.Location = new Point(0, 0);
|
||||
menuStrip.Name = "menuStrip";
|
||||
menuStrip.Size = new Size(801, 24);
|
||||
menuStrip.TabIndex = 2;
|
||||
menuStrip.Text = "menuStrip";
|
||||
//
|
||||
// файлToolStripMenuItem
|
||||
//
|
||||
файлToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { saveToolStripMenuItem, loadToolStripMenuItem });
|
||||
файлToolStripMenuItem.Name = "файлToolStripMenuItem";
|
||||
файлToolStripMenuItem.Size = new Size(48, 20);
|
||||
файлToolStripMenuItem.Text = "Файл";
|
||||
//
|
||||
// saveToolStripMenuItem
|
||||
//
|
||||
saveToolStripMenuItem.Name = "saveToolStripMenuItem";
|
||||
saveToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.S;
|
||||
saveToolStripMenuItem.Size = new Size(181, 22);
|
||||
saveToolStripMenuItem.Text = "Сохранение";
|
||||
saveToolStripMenuItem.Click += SaveToolStripMenuItem_Click;
|
||||
//
|
||||
// loadToolStripMenuItem
|
||||
//
|
||||
loadToolStripMenuItem.Name = "loadToolStripMenuItem";
|
||||
loadToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.L;
|
||||
loadToolStripMenuItem.Size = new Size(181, 22);
|
||||
loadToolStripMenuItem.Text = "Загрузка";
|
||||
loadToolStripMenuItem.Click += LoadToolStripMenuItem_Click;
|
||||
//
|
||||
// saveFileDialog
|
||||
//
|
||||
saveFileDialog.Filter = "txt file | *.txt";
|
||||
//
|
||||
// openFileDialog
|
||||
//
|
||||
openFileDialog.Filter = "txt file | *.txt";
|
||||
//
|
||||
// FormAircraftCollection
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(801, 563);
|
||||
ClientSize = new Size(801, 584);
|
||||
Controls.Add(pictureBox);
|
||||
Controls.Add(groupBoxTools);
|
||||
Controls.Add(menuStrip);
|
||||
MainMenuStrip = menuStrip;
|
||||
Name = "FormAircraftCollection";
|
||||
Text = "Коллекция самолетов";
|
||||
groupBoxTools.ResumeLayout(false);
|
||||
@@ -260,7 +309,10 @@
|
||||
panelStorage.ResumeLayout(false);
|
||||
panelStorage.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
|
||||
menuStrip.ResumeLayout(false);
|
||||
menuStrip.PerformLayout();
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -283,5 +335,11 @@
|
||||
private Button buttonCreateCompany;
|
||||
private Button buttonCollectionDel;
|
||||
private Panel panelCompanyTools;
|
||||
private MenuStrip menuStrip;
|
||||
private ToolStripMenuItem файлToolStripMenuItem;
|
||||
private ToolStripMenuItem saveToolStripMenuItem;
|
||||
private ToolStripMenuItem loadToolStripMenuItem;
|
||||
private SaveFileDialog saveFileDialog;
|
||||
private OpenFileDialog openFileDialog;
|
||||
}
|
||||
}
|
||||
@@ -35,7 +35,7 @@ public partial class FormAircraftCollection : Form
|
||||
public FormAircraftCollection()
|
||||
{
|
||||
InitializeComponent();
|
||||
_storageCollection = new();
|
||||
_storageCollection = new();
|
||||
}
|
||||
/// <summary>
|
||||
/// Выбор компании
|
||||
@@ -44,7 +44,7 @@ public partial class FormAircraftCollection : Form
|
||||
/// <param name="e"></param>
|
||||
private void ComboBoxSelectorCompany_SelectedValueChanged(object sender, EventArgs e)
|
||||
{
|
||||
panelCompanyTools.Enabled = false;
|
||||
panelCompanyTools.Enabled = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -76,14 +76,13 @@ public partial class FormAircraftCollection : Form
|
||||
|
||||
if (_company + aircraft)
|
||||
{
|
||||
|
||||
MessageBox.Show("не удалось добавить объект");
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBox.Image = _company.Show();
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBox.Image = _company.Show();
|
||||
MessageBox.Show("не удалось добавить объект");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -181,7 +180,7 @@ public partial class FormAircraftCollection : Form
|
||||
{
|
||||
collectionType = CollectionType.Massive;
|
||||
}
|
||||
else if (radioButtonList.Checked)
|
||||
else if (radioButtonList.Checked)
|
||||
{
|
||||
collectionType = CollectionType.List;
|
||||
}
|
||||
@@ -213,7 +212,7 @@ public partial class FormAircraftCollection : Form
|
||||
private void RefreshListBoxItems()
|
||||
{
|
||||
listBoxCollection.Items.Clear();
|
||||
for (int i =0; i < _storageCollection.Keys?.Count; i++)
|
||||
for (int i = 0; i < _storageCollection.Keys?.Count; i++)
|
||||
{
|
||||
string? colName = _storageCollection.Keys?[i];
|
||||
if (!string.IsNullOrEmpty(colName))
|
||||
@@ -236,7 +235,7 @@ public partial class FormAircraftCollection : Form
|
||||
return;
|
||||
}
|
||||
|
||||
ICollectionGenericObjects<DrawningAircraft>? collection = _storageCollection[listBoxCollection.SelectedItem.ToString()?? string.Empty];
|
||||
ICollectionGenericObjects<DrawningAircraft>? collection = _storageCollection[listBoxCollection.SelectedItem.ToString() ?? string.Empty];
|
||||
if (collection == null)
|
||||
{
|
||||
MessageBox.Show("Коллкция не проиницилизирована");
|
||||
@@ -246,11 +245,53 @@ public partial class FormAircraftCollection : Form
|
||||
switch (comboBoxSelectorCompany.Text)
|
||||
{
|
||||
case "Хранилище":
|
||||
_company = new AircraftSharingService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects<DrawningAircraft>());
|
||||
_company = new AircraftSharingService(pictureBox.Width, pictureBox.Height, collection);
|
||||
pictureBox.Image = _company.Show();
|
||||
break;
|
||||
}
|
||||
|
||||
panelCompanyTools.Enabled = true;
|
||||
RefreshListBoxItems();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Обработка нажатия на "Сохранение"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void SaveToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (_storageCollection.SaveData(saveFileDialog.FileName))
|
||||
{
|
||||
MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не сохранилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Обработка нажатия на "Загрузка"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void LoadToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (_storageCollection.LoadData(openFileDialog.FileName))
|
||||
{
|
||||
MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
RefreshListBoxItems();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не загрузилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,4 +117,16 @@
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="menuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>16, 5</value>
|
||||
</metadata>
|
||||
<metadata name="saveFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>125, 5</value>
|
||||
</metadata>
|
||||
<metadata name="openFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>260, 5</value>
|
||||
</metadata>
|
||||
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>48</value>
|
||||
</metadata>
|
||||
</root>
|
||||
Reference in New Issue
Block a user