diff --git a/Catamaran/BoatDelegate.cs b/Catamaran/BoatDelegate.cs
index 520aa98..c4bbd0b 100644
--- a/Catamaran/BoatDelegate.cs
+++ b/Catamaran/BoatDelegate.cs
@@ -10,6 +10,6 @@ namespace Catamaran
///
/// Делегат для передачи объекта-лодки
///
- ///
+ ///
public delegate void BoatDelegate(DrawingBoat boat);
}
diff --git a/Catamaran/Catamaran.csproj b/Catamaran/Catamaran.csproj
index 3d367cc..c83a6c2 100644
--- a/Catamaran/Catamaran.csproj
+++ b/Catamaran/Catamaran.csproj
@@ -54,6 +54,7 @@
+
Form
diff --git a/Catamaran/DrawingBoat.cs b/Catamaran/DrawingBoat.cs
index c437349..bea4a55 100644
--- a/Catamaran/DrawingBoat.cs
+++ b/Catamaran/DrawingBoat.cs
@@ -127,8 +127,8 @@ namespace Catamaran
/// Скорость
/// Вес автомобиля
/// Цвет кузова
- /// Ширина отрисовки автомобиля
- /// Высота отрисовки автомобиля
+ /// Ширина отрисовки автомобиля
+ /// Высота отрисовки автомобиля
protected DrawingBoat(int speed, float weight, Color bodyColor, int
catamaranWidth, int catamaranHeight) :
this(speed, weight, bodyColor)
diff --git a/Catamaran/DrawingObjectBoat.cs b/Catamaran/DrawingObjectBoat.cs
index 01c436c..3d41ecb 100644
--- a/Catamaran/DrawingObjectBoat.cs
+++ b/Catamaran/DrawingObjectBoat.cs
@@ -33,6 +33,8 @@ namespace Catamaran
_catamaran.DrawTransport(g);
}
+ public string GetInfo() => _catamaran?.GetDataForSave();
+ public static IDrawingObject Create(string data) => new DrawingObjectBoat(data.CreateDrawingBoat());
}
}
diff --git a/Catamaran/ExtentionBoat.cs b/Catamaran/ExtentionBoat.cs
new file mode 100644
index 0000000..8759d8d
--- /dev/null
+++ b/Catamaran/ExtentionBoat.cs
@@ -0,0 +1,57 @@
+using System;
+using System.Collections.Generic;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Catamaran
+{
+ ///
+ /// Расширение для класса DrawingBoat
+ ///
+ internal static class ExtentionBoat
+ {
+ ///
+ /// Разделитель для записи информации по объекту в файл
+ ///
+ private static readonly char _separatorForObject = ':';
+ ///
+ /// Создание объекта из строки
+ ///
+ ///
+ ///
+ public static DrawingBoat CreateDrawingBoat(this string info)
+ {
+ string[] strs = info.Split(_separatorForObject);
+ if (strs.Length == 3)
+ {
+ return new DrawingBoat(Convert.ToInt32(strs[0]),
+ Convert.ToInt32(strs[1]), Color.FromName(strs[2]));
+ }
+ if (strs.Length == 6)
+ {
+ return new DrawingCatamaran(Convert.ToInt32(strs[0]),
+ Convert.ToInt32(strs[1]), Color.FromName(strs[2]),
+ Color.FromName(strs[3]), Convert.ToBoolean(strs[4]),
+ Convert.ToBoolean(strs[5]));
+ }
+ return null;
+ }
+ ///
+ /// Получение данных для сохранения в файл
+ ///
+ ///
+ ///
+ public static string GetDataForSave(this DrawingBoat DrawingBoat)
+ {
+ var Boat = DrawingBoat.Catamaran;
+ var str = $"{Boat.Speed}{_separatorForObject}{Boat.Weight}{_separatorForObject}{Boat.BodyColor.Name}";
+ if (!(Boat is EntityCatamaran Catamaran))
+ {
+ return str;
+ }
+ return $"{str}{_separatorForObject}{Catamaran.DopColor.Name}{_separatorForObject}{Catamaran.Floats}{_separatorForObject}{Catamaran.Sail}";
+ }
+ }
+}
diff --git a/Catamaran/FormBoatConfig.cs b/Catamaran/FormBoatConfig.cs
index 7f17d68..8c35bad 100644
--- a/Catamaran/FormBoatConfig.cs
+++ b/Catamaran/FormBoatConfig.cs
@@ -182,7 +182,7 @@ namespace Catamaran
}
DrawCatamaran();
- // TODO Call method from object _boat if _boat is DrawningSportCar and set dop color
+ // TODO Call method from object _boat if _boat is DrawingCatamaran and set dop color
}
///
/// Добавление машины
diff --git a/Catamaran/FormMapWithSetBoats.cs b/Catamaran/FormMapWithSetBoats.cs
index 1f0c0ef..43609a9 100644
--- a/Catamaran/FormMapWithSetBoats.cs
+++ b/Catamaran/FormMapWithSetBoats.cs
@@ -214,7 +214,7 @@ namespace Catamaran
{
var formBoatConfig = new FormBoatConfig();
formBoatConfig.AddEvent(new Action(AddBoat));
- // TODO Call method AddEvent from formCarConfig
+ // TODO Call method AddEvent from formBoatConfig
formBoatConfig.Show();
}
diff --git a/Catamaran/IDrawingObject.cs b/Catamaran/IDrawingObject.cs
index ce8d31a..2c54719 100644
--- a/Catamaran/IDrawingObject.cs
+++ b/Catamaran/IDrawingObject.cs
@@ -38,5 +38,12 @@ namespace Catamaran
(float Left, float Right, float Top, float Bottom)
GetCurrentPosition();
+ ///
+ /// Получение информации по объекту
+ ///
+ ///
+ string GetInfo();
+
+
}
}
diff --git a/Catamaran/MapWithSetBoatsGeneric.cs b/Catamaran/MapWithSetBoatsGeneric.cs
index 267d621..c2887b5 100644
--- a/Catamaran/MapWithSetBoatsGeneric.cs
+++ b/Catamaran/MapWithSetBoatsGeneric.cs
@@ -182,5 +182,32 @@ namespace Catamaran
_setBoats[i]?.DrawingObject(g);
}
}
+
+ ///
+ /// Получение данных в виде строки
+ ///
+ ///
+ ///
+ public string GetData(char separatorType, char separatorData)
+ {
+ string data = $"{_map.GetType().Name}{separatorType}";
+ foreach (var Boat in _setBoats.GetBoats())
+ {
+ data += $"{Boat.GetInfo()}{separatorData}";
+ }
+ return data;
+ }
+ ///
+ /// Загрузка списка из массива строк
+ ///
+ ///
+ public void LoadData(string[] records)
+ {
+ foreach (var rec in records)
+ {
+ _setBoats.Insert(DrawingObjectBoat.Create(rec) as T);
+ }
+ }
+
}
}