43 lines
1.5 KiB
C#
43 lines
1.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Sailboat
|
|
{
|
|
internal static class ExtentionBoat
|
|
{
|
|
private static readonly char _separatorForObject = ':';
|
|
public static DrawingBoat CreateDrawningBoat(this string info)
|
|
{
|
|
string[] strs = info.Split(_separatorForObject);
|
|
if (strs.Length == 3)
|
|
{
|
|
return new DrawingBoat(Convert.ToInt32(strs[0]),
|
|
Convert.ToInt32(strs[1]), Color.FromName(strs[2]));
|
|
}
|
|
if (strs.Length == 6)
|
|
{
|
|
return new DrawingSailboat(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 DrawingBoat drawingBoat)
|
|
{
|
|
var boat = drawingBoat.Boat;
|
|
var str = $"{boat.Speed}{_separatorForObject}{boat.Weight}{_separatorForObject}{boat.BodyColor.Name}";
|
|
if (boat is not Sailboat sailboat)
|
|
{
|
|
return str;
|
|
}
|
|
return $"{str}{_separatorForObject}{sailboat.EdgeColor.Name}{_separatorForObject}{sailboat.Sail}{_separatorForObject}{sailboat.ExtendedBody}";
|
|
}
|
|
}
|
|
}
|
|
|