PIbd22_NikiforovaMV_Contain.../ContainerShip/ExtentionDrawningShip.cs

48 lines
1.7 KiB
C#
Raw Normal View History

2023-12-16 11:18:38 +04:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ContainerShip.Entities;
namespace ContainerShip.DrawningObjects
{
public static class ExtentionDrawningShip
{
public static DrawningShip? CreateDrawningShip(this string info, char separatorForObject, int width, int height)
{
string[] strs = info.Split(separatorForObject);
if (strs.Length == 3)
{
return new DrawningShip(
Convert.ToInt32(strs[0]),
Convert.ToInt32(strs[1]),
Color.FromName(strs[2]), width, height);
}
if (strs.Length == 6)
{
return new DrawingContainerShip(
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 DrawningShip drawningShip, char separatorForObject)
{
var ship = drawningShip.EntityShip;
if (ship == null)
{
return string.Empty;
}
var str = $"{ship.Speed}{separatorForObject}{ship.Weight}{separatorForObject}{ship.BodyColor.Name}";
if (ship is not EntityContainerShip containerShip)
{
return str;
}
return $"{str}{separatorForObject}{containerShip.AdditionalColor.Name}{separatorForObject}{containerShip.Load}{separatorForObject}{containerShip.Crane}";
}
}
}