From 065dd3cc409526e2ca098cc9273fc73b89022268 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B5=D0=BB=D1=8C=D0=BD=D0=B8=D0=BA=D0=BE=D0=B2=20?= =?UTF-8?q?=D0=98=D0=B3=D0=BE=D1=80=D1=8C?= Date: Tue, 20 Dec 2022 18:40:39 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B1=D0=B0=D0=B7=D0=B0=20+=20=D0=B4=D0=BE?= =?UTF-8?q?=D0=BF=20=D0=BE=D1=82=D1=80=D0=B8=D1=81=D0=BE=D0=B2=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DrawningEllipseOrnament.cs | 4 +++ .../DrawningRectOrnament.cs | 4 +++ .../LocomotivesAdvanced/DrawningWheels.cs | 4 +++ .../ExtentionLocomotive.cs | 28 ++++++++++++++----- .../IDrawningAdditionalElements.cs | 2 +- 5 files changed, 34 insertions(+), 8 deletions(-) diff --git a/LocomotivesAdvanced/LocomotivesAdvanced/DrawningEllipseOrnament.cs b/LocomotivesAdvanced/LocomotivesAdvanced/DrawningEllipseOrnament.cs index d3633d4..e3580b2 100644 --- a/LocomotivesAdvanced/LocomotivesAdvanced/DrawningEllipseOrnament.cs +++ b/LocomotivesAdvanced/LocomotivesAdvanced/DrawningEllipseOrnament.cs @@ -6,6 +6,10 @@ public int WheelsNum { + get + { + return (int)wheelsNumber; + } set { if (value < 2 || value > 4) diff --git a/LocomotivesAdvanced/LocomotivesAdvanced/DrawningRectOrnament.cs b/LocomotivesAdvanced/LocomotivesAdvanced/DrawningRectOrnament.cs index e6189ea..7a8ee24 100644 --- a/LocomotivesAdvanced/LocomotivesAdvanced/DrawningRectOrnament.cs +++ b/LocomotivesAdvanced/LocomotivesAdvanced/DrawningRectOrnament.cs @@ -6,6 +6,10 @@ public int WheelsNum { + get + { + return (int)wheelsNumber; + } set { if (value < 2 || value > 4) diff --git a/LocomotivesAdvanced/LocomotivesAdvanced/DrawningWheels.cs b/LocomotivesAdvanced/LocomotivesAdvanced/DrawningWheels.cs index 552ed41..32aee4d 100644 --- a/LocomotivesAdvanced/LocomotivesAdvanced/DrawningWheels.cs +++ b/LocomotivesAdvanced/LocomotivesAdvanced/DrawningWheels.cs @@ -6,6 +6,10 @@ public int WheelsNum { + get + { + return (int)wheelsNumber; + } set { if (value < 2 || value > 4) diff --git a/LocomotivesAdvanced/LocomotivesAdvanced/ExtentionLocomotive.cs b/LocomotivesAdvanced/LocomotivesAdvanced/ExtentionLocomotive.cs index cafbc25..849dfaf 100644 --- a/LocomotivesAdvanced/LocomotivesAdvanced/ExtentionLocomotive.cs +++ b/LocomotivesAdvanced/LocomotivesAdvanced/ExtentionLocomotive.cs @@ -17,7 +17,7 @@ public static string GetDataForSave(this DrawningLocomotive drawningLocomotive) { var locomotive = drawningLocomotive.Locomotive; - var str = $"{locomotive.Speed}{_separatorForObject}{locomotive.Weight}{_separatorForObject}{locomotive.BodyColor.Name}"; + var str = $"{locomotive.Speed}{_separatorForObject}{locomotive.Weight}{_separatorForObject}{locomotive.BodyColor.Name}{_separatorForObject}{drawningLocomotive.AdditionalElements.WheelsNum}{_separatorForObject}{drawningLocomotive.AdditionalElements.GetType().Name}"; if (locomotive is not EntityWarmlyLocomotive warmlyLocomotive) { return str; @@ -32,19 +32,33 @@ public static DrawningLocomotive CreateDrawningLocomotive(this string info) { string[] strs = info.Split(_separatorForObject); - if (strs.Length == 3) + DrawningLocomotive recreatedLocomotive = null; + if (strs.Length == 5) { - return new DrawningLocomotive(Convert.ToInt32(strs[0]), Convert.ToInt32(strs[1]), Color.FromName(strs[2])); + recreatedLocomotive = new DrawningLocomotive(Convert.ToInt32(strs[0]), Convert.ToInt32(strs[1]), Color.FromName(strs[2])); } - if (strs.Length == 6) + if (strs.Length == 8) { - return new DrawningWarmlyLocomotive + recreatedLocomotive = new DrawningWarmlyLocomotive ( Convert.ToInt32(strs[0]), Convert.ToInt32(strs[1]), Color.FromName(strs[2]), 160, 85, - Color.FromName(strs[3]), Convert.ToBoolean(strs[4]), Convert.ToBoolean(strs[5]) + Color.FromName(strs[5]), Convert.ToBoolean(strs[6]), Convert.ToBoolean(strs[7]) ); } - return null; + switch (strs[4]) + { + case "DrawningWheels": + recreatedLocomotive.AdditionalElements = new DrawningWheels(); + break; + case "DrawningRectOrnament": + recreatedLocomotive.AdditionalElements = new DrawningRectOrnament(); + break; + case "DrawningEllipseOrnament": + recreatedLocomotive.AdditionalElements = new DrawningEllipseOrnament(); + break; + } + recreatedLocomotive.AdditionalElements.WheelsNum = Convert.ToInt32(strs[3]); + return recreatedLocomotive; } } } diff --git a/LocomotivesAdvanced/LocomotivesAdvanced/IDrawningAdditionalElements.cs b/LocomotivesAdvanced/LocomotivesAdvanced/IDrawningAdditionalElements.cs index 968e2f7..f0a6c3a 100644 --- a/LocomotivesAdvanced/LocomotivesAdvanced/IDrawningAdditionalElements.cs +++ b/LocomotivesAdvanced/LocomotivesAdvanced/IDrawningAdditionalElements.cs @@ -8,7 +8,7 @@ /// /// Свойство получения количества колёс /// - public int WheelsNum { set; } + public int WheelsNum { get; set; } /// /// Отрисовка колёс ///