Начало 6 лабы

This commit is contained in:
Макс Бондаренко 2022-11-11 18:25:54 +04:00
parent 117d18566a
commit 99d1787cca

View File

@ -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}";
}
}
}