From 032bf5d2a245dcc0156b600ff415f29c55f684da Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Fri, 4 Nov 2022 18:29:36 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=20=D0=BA?= =?UTF-8?q?=D0=BB=D0=B0=D1=81=D1=81=20ExtentionLocomotive,=20=D1=80=D0=B5?= =?UTF-8?q?=D1=88=D0=B5=D0=BD=D0=B0=20=D0=BF=D1=80=D0=BE=D0=B1=D0=BB=D0=B5?= =?UTF-8?q?=D0=BC=D0=B0=20=D1=81=20=D0=B8=D0=BC=D0=B5=D0=BD=D0=B0=D0=BC?= =?UTF-8?q?=D0=B8=20=D1=86=D0=B2=D0=B5=D1=82=D0=BE=D0=B2=20=D0=B2=20FormLo?= =?UTF-8?q?comotiveConfig?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Locomotive/Locomotive/ExtentionLocomotive.cs | 48 +++++++++++++++++++ .../FormLocomotiveConfig.Designer.cs | 2 +- 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 Locomotive/Locomotive/ExtentionLocomotive.cs diff --git a/Locomotive/Locomotive/ExtentionLocomotive.cs b/Locomotive/Locomotive/ExtentionLocomotive.cs new file mode 100644 index 0000000..056e5f1 --- /dev/null +++ b/Locomotive/Locomotive/ExtentionLocomotive.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Locomotive +{ + internal static class ExtentionLocomotive + { + private static readonly char _separatorForObject = ':'; + public static string getDataForSave(this DrawningLocomotive drawningLocomotive) + { + var locomotive = drawningLocomotive.Locomotive; + var str = $"{locomotive.Speed}{_separatorForObject}{locomotive.Weight}{_separatorForObject}{locomotive.BodyColor.Name}"; + if (locomotive is not EntityWarmlyLocomotive warmlyLocomotive) + { + return str; + } + return $"{str}{_separatorForObject}{warmlyLocomotive.ExtraColor.Name}{_separatorForObject}{warmlyLocomotive.Pipe}{_separatorForObject}{warmlyLocomotive.FuelStorage}"; + } + + public static DrawningLocomotive createDrawningLocomotive(this string info) + { + string[] strs = info.Split(_separatorForObject); + if (strs.Length == 3) + { + return new DrawningLocomotive( + Convert.ToInt32(strs[0]), + Convert.ToInt32(strs[1]), + Color.FromName(strs[2]) + ); + } + if (strs.Length == 6) + { + return new DrawningWarmlyLocomotive( + 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; + } + } +} diff --git a/Locomotive/Locomotive/FormLocomotiveConfig.Designer.cs b/Locomotive/Locomotive/FormLocomotiveConfig.Designer.cs index 77cf4bf..d100b8e 100644 --- a/Locomotive/Locomotive/FormLocomotiveConfig.Designer.cs +++ b/Locomotive/Locomotive/FormLocomotiveConfig.Designer.cs @@ -159,7 +159,7 @@ // // panelGreen // - this.panelGreen.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(192)))), ((int)(((byte)(0))))); + this.panelGreen.BackColor = System.Drawing.Color.Green; this.panelGreen.Location = new System.Drawing.Point(72, 31); this.panelGreen.Name = "panelGreen"; this.panelGreen.Size = new System.Drawing.Size(43, 40);