diff --git a/AircraftCarrier/AircraftCarrier/MapWithSetAircraftCarriersGeneric.cs b/AircraftCarrier/AircraftCarrier/MapWithSetAircraftCarriersGeneric.cs
index 3798b59..a53a240 100644
--- a/AircraftCarrier/AircraftCarrier/MapWithSetAircraftCarriersGeneric.cs
+++ b/AircraftCarrier/AircraftCarrier/MapWithSetAircraftCarriersGeneric.cs
@@ -111,6 +111,26 @@ namespace AircraftCarrier
}
return new(_pictureWidth, _pictureHeight);
}
+ public string GetData(char separatorType, char separatorData)
+ {
+ string data = $"{_map.GetType().Name}{separatorType}";
+ foreach (var aircraftcarrier in _setAircraftCarriers.GetAircraftCarriers())
+ {
+ data += $"{aircraftcarrier.GetInfo()}{separatorData}";
+ }
+ return data;
+ }
+ ///
+ /// Загрузка списка из массива строк
+ ///
+ ///
+ public void LoadData(string[] records)
+ {
+ foreach (var rec in records)
+ {
+ _setAircraftCarriers.Insert(DrawningObjectAircraftCarrier.Create(rec) as T);
+ }
+ }
///
/// "Взбалтываем" набор, чтобы все элементы оказались в начале
///
@@ -164,10 +184,8 @@ namespace AircraftCarrier
{
int yNumOfPlaces = _pictureHeight / _placeSizeHeight;
int xNumOfPlaces = _pictureWidth / _placeSizeWidth;
-
int rowNum = yNumOfPlaces - 1;
int columnNum = 0;
-
for (int i = 0; i < _setAircraftCarriers.Count; i++)
{
if (_setAircraftCarriers[i] != null)
diff --git a/AircraftCarrier/AircraftCarrier/MapsCollection.cs b/AircraftCarrier/AircraftCarrier/MapsCollection.cs
index c400950..e396e6d 100644
--- a/AircraftCarrier/AircraftCarrier/MapsCollection.cs
+++ b/AircraftCarrier/AircraftCarrier/MapsCollection.cs
@@ -11,7 +11,7 @@ namespace AircraftCarrier
///
/// Словарь (хранилище) с картами
///
- readonly Dictionary> _mapStorages;
///
/// Возвращение списка названий карт
@@ -30,10 +30,11 @@ namespace AircraftCarrier
///
///
///
+ private readonly char separatorDict = '|';
+ private readonly char separatorData = ';';
public MapsCollection(int pictureWidth, int pictureHeight)
{
- _mapStorages = new Dictionary>();
+ _mapStorages = new Dictionary>();
_pictureWidth = pictureWidth;
_pictureHeight = pictureHeight;
}
@@ -63,7 +64,7 @@ namespace AircraftCarrier
///
///
///
- public MapWithSetAircraftCarriersGeneric this[string
+ public MapWithSetAircraftCarriersGeneric this[string
ind]
{
get
@@ -72,7 +73,7 @@ namespace AircraftCarrier
return mapWithSetAircraftCarriersGeneric;
}
}
- public MapWithSetAircraftCarriersGeneric this[int index]
+ public MapWithSetAircraftCarriersGeneric this[int index]
{
get
{
@@ -88,5 +89,66 @@ namespace AircraftCarrier
}
}
}
+ ///
+ /// Сохранение информации по автомобилям в хранилище в файл
+ ///
+ /// Путь и имя файла
+ ///
+ public bool SaveData(string filename)
+ {
+ if (File.Exists(filename))
+ {
+ File.Delete(filename);
+ }
+ using (StreamWriter sw = new(filename))
+ {
+ sw.Write($"MapsCollection{Environment.NewLine}");
+ foreach (var storage in _mapStorages)
+ {
+ sw.Write($"{storage.Key}{separatorDict}{storage.Value.GetData(separatorDict, separatorData)}{Environment.NewLine}");
+ }
+ }
+ return true;
+ }
+ ///
+ /// Загрузка нформации по автомобилям на парковках из файла
+ ///
+ ///
+ ///
+ public bool LoadData(string filename)
+ {
+ if (!File.Exists(filename))
+ {
+ return false;
+ }
+ using (StreamReader sr = new(filename))
+ {
+ string str = "";
+ if ((str = sr.ReadLine()) == null || !str.Contains("MapsCollection"))
+ {
+ //если нет такой записи, то это не те данные
+ return false;
+ }
+ //очищаем записи
+ _mapStorages.Clear();
+ while ((str = sr.ReadLine()) != null)
+ {
+ var elem = str.Split(separatorDict);
+ AbstractMap map = null;
+ switch (elem[1])
+ {
+ case "SimpleMap":
+ map = new SimpleMap();
+ break;
+ case "HardMap":
+ map = new ComplexMap();
+ break;
+ }
+ _mapStorages.Add(elem[0], new MapWithSetAircraftCarriersGeneric(_pictureWidth, _pictureHeight, map));
+ _mapStorages[elem[0]].LoadData(elem[2].Split(separatorData, StringSplitOptions.RemoveEmptyEntries));
+ }
+ }
+ return true;
+ }
}
}
\ No newline at end of file
diff --git a/AircraftCarrier/AircraftCarrier/SetAircraftCarriersGeneric.cs b/AircraftCarrier/AircraftCarrier/SetAircraftCarriersGeneric.cs
index b0e5bb6..b454a25 100644
--- a/AircraftCarrier/AircraftCarrier/SetAircraftCarriersGeneric.cs
+++ b/AircraftCarrier/AircraftCarrier/SetAircraftCarriersGeneric.cs
@@ -55,6 +55,7 @@ namespace AircraftCarrier
_places.Insert(position, AircraftCarrier);
return position;
}
+
///
/// Удаление объекта из набора с конкретной позиции
///
@@ -75,7 +76,6 @@ namespace AircraftCarrier
///
///
///
-
public T this[int position]
{
get
@@ -86,14 +86,15 @@ namespace AircraftCarrier
{
Insert(value, position);
}
+
}
- public IEnumerable GetCars()
+ public IEnumerable GetAircraftCarriers()
{
- foreach (var car in _places)
+ foreach (var aircraftcarrier in _places)
{
- if (car != null)
+ if (aircraftcarrier != null)
{
- yield return car;
+ yield return aircraftcarrier;
}
else
{
@@ -101,6 +102,5 @@ namespace AircraftCarrier
}
}
}
-
}
}
\ No newline at end of file