From 87c5a983332d9eeb5e1bdcd99797c6de9137301d Mon Sep 17 00:00:00 2001 From: "ns.potapov" Date: Mon, 20 Nov 2023 17:36:21 +0400 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=20=D1=80=D0=B0=D1=81?= =?UTF-8?q?=D1=88=D0=B8=D1=80=D0=B5=D0=BD=D0=B8=D0=B5=20ExtensionDrawingPl?= =?UTF-8?q?ane?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ExtensionDrawingPlane.cs | 53 +++++++++++++++++++ .../PlanesGenericCollection.cs | 4 ++ 2 files changed, 57 insertions(+) create mode 100644 ProjectStormtrooper/ProjectStormtrooper/ExtensionDrawingPlane.cs diff --git a/ProjectStormtrooper/ProjectStormtrooper/ExtensionDrawingPlane.cs b/ProjectStormtrooper/ProjectStormtrooper/ExtensionDrawingPlane.cs new file mode 100644 index 0000000..ee04ab0 --- /dev/null +++ b/ProjectStormtrooper/ProjectStormtrooper/ExtensionDrawingPlane.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectStormtrooper +{ + public static class ExtensionDrawingPlane + { + /// + /// Создание объекта из строки + /// + public static DrawingPlane? CreateDrawingPlane(this string info, char separatorForObject, int width, int height) + { + string[] strs = info.Split(separatorForObject); + if (strs.Length == 3) + { + return new DrawingPlane(Convert.ToInt32(strs[0]), Convert.ToInt32(strs[1]), Color.FromName(strs[2]), width, height); + } + if (strs.Length == 7) + { + return new DrawingStormtrooper( + 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 DrawingPlane drawningPlane, char separatorForObject) + { + var plane = drawningPlane.EntityPlane; + if (plane == null) + { + return string.Empty; + } + var str = $"{plane.Speed}{separatorForObject}{plane.Weight}{separatorForObject}{plane.BodyColor.Name}"; + if (plane is not EntityStormtrooper stormtrooper) + { + return str; + } + return $"{str}{separatorForObject}{stormtrooper.AdditionalColor.Name}{separatorForObject}{stormtrooper.Rockets}{separatorForObject}{stormtrooper.Bombs}"; + } + } +} diff --git a/ProjectStormtrooper/ProjectStormtrooper/PlanesGenericCollection.cs b/ProjectStormtrooper/ProjectStormtrooper/PlanesGenericCollection.cs index 3a7f871..a2afcc5 100644 --- a/ProjectStormtrooper/ProjectStormtrooper/PlanesGenericCollection.cs +++ b/ProjectStormtrooper/ProjectStormtrooper/PlanesGenericCollection.cs @@ -138,5 +138,9 @@ namespace ProjectStormtrooper i++; } } + /// + /// Получение объектов коллекции + /// + public IEnumerable GetPlanes => _collection.GetPlanes(); } }