51 lines
1.7 KiB
C#
51 lines
1.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Hydroplane.Entities;
|
|
|
|
namespace Hydroplane.DrawningObjects
|
|
{
|
|
public static class ExtentionDrawningPlane
|
|
{
|
|
public static DrawningPlane? CreateDrawningPlane(this string info, char
|
|
separatorForObject, int width, int height)
|
|
{
|
|
string[] strs = info.Split(separatorForObject);
|
|
if (strs.Length == 3)
|
|
{
|
|
return new DrawningPlane(Convert.ToInt32(strs[0]),
|
|
Convert.ToInt32(strs[1]), Color.FromName(strs[2]), width, height);
|
|
}
|
|
if (strs.Length == 6)
|
|
{
|
|
return new DrawningHydroplane(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 DrawningPlane drawningPlane,
|
|
char separatorForObject)
|
|
{
|
|
var plane = drawningPlane.EntityPlane;
|
|
if (plane == null)
|
|
{
|
|
return string.Empty;
|
|
}
|
|
var str = $"{plane.Speed}{separatorForObject}{plane.Weight}{separatorForObject}{plane.BodyColor.Name}";
|
|
if (plane is not EntityHydroplane hydroplane)
|
|
{
|
|
return str;
|
|
}
|
|
return
|
|
$"{str}{separatorForObject}{hydroplane.AdditionalColor.Name}{separatorForObject}{hydroplane.Boat}{separatorForObject}{hydroplane.Bobber}";
|
|
}
|
|
}
|
|
}
|