diff --git a/WarmlyShip/WarmlyShip/ExtentionShip.cs b/WarmlyShip/WarmlyShip/ExtentionShip.cs new file mode 100644 index 0000000..84c237c --- /dev/null +++ b/WarmlyShip/WarmlyShip/ExtentionShip.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WarmlyShip +{ + internal static class ExtentionShip + { + + private static readonly char _separatorForObject = ':'; + + public static DrawingWarmlyShip CreateDrawningCar(this string info) + { + string[] strs = info.Split(_separatorForObject); + if (strs.Length == 3) + { + return new DrawingWarmlyShip(Convert.ToInt32(strs[0]), Convert.ToInt32(strs[1]), Color.FromName(strs[2])); + } + if (strs.Length == 6) + { + return new DrawningMotorShip(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 DrawingWarmlyShip warmlyShip) + { + var ship = warmlyShip.warmlyShip; + var str = $"{ship.Speed}{_separatorForObject}{ship.Weight}{_separatorForObject}{ship.BodyColor.Name}"; + if (ship is not EntityMotorShip motorShip) + { + return str; + } + return $"{str}{_separatorForObject}{motorShip.DopColor.Name}{_separatorForObject}{motorShip.Tubes}{_separatorForObject}{motorShip.Cistern}"; + } + } +}