diff --git a/AirFighter/ExtentionDrawningAirplane.cs b/AirFighter/ExtentionDrawningAirplane.cs new file mode 100644 index 0000000..3b0356a --- /dev/null +++ b/AirFighter/ExtentionDrawningAirplane.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ProjectAirFighter.Entities; +using System.Drawing; + +namespace ProjectAirFighter.DrawningObjects +{ + public static class ExtentionDrawningAirplane { + public static DrawningAirplane? CreateDrawningAirplane(this string info, char separatorForObject, + int width, int height) + { + string[] strs = info.Split(separatorForObject); + if (strs.Length == 3) + { + return new DrawningAirplane(Convert.ToInt32(strs[0]), + Convert.ToInt32(strs[1]), Color.FromName(strs[2]), width, height); + } + if (strs.Length == 6) + { + return new DrawningAirFighter(Convert.ToInt32(strs[0]), + Convert.ToInt32(strs[1]), + Color.FromName(strs[2]), + Color.FromName(strs[3]), + Convert.ToBoolean(strs[4]), + Convert.ToBoolean(strs[5]), width, height); + } + return null; + } + + public static string GetDataForSave(this DrawningAirplane drawningAirplane, char separatorForObject) + { + var airplane = drawningAirplane.EntityAirplane; + if (airplane == null) + { + return string.Empty; + } + var str = $"{airplane.Speed}{separatorForObject}{airplane.Weight}{separatorForObject}{airplane.BodyColor.Name}"; + if (airplane is not EntityAirFighter airfighter) + { + return str; + } + return +$"{str}{separatorForObject}{airfighter.AdditionalColor.Name}{separatorForObject}{airfighter.Wing}{separatorForObject}{airfighter.Racket}"; + + + + } + } +} +