54 lines
1.7 KiB
C#
54 lines
1.7 KiB
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
using ProjectAirFighter.Entities;
|
|||
|
using System.Drawing;
|
|||
|
|
|||
|
namespace ProjectAirFighter.DrawningObjects
|
|||
|
{
|
|||
|
public static class ExtentionDrawningAirplane {
|
|||
|
public static DrawningAirplane? CreateDrawningAirplane(this string info, char separatorForObject,
|
|||
|
int width, int height)
|
|||
|
{
|
|||
|
string[] strs = info.Split(separatorForObject);
|
|||
|
if (strs.Length == 3)
|
|||
|
{
|
|||
|
return new DrawningAirplane(Convert.ToInt32(strs[0]),
|
|||
|
Convert.ToInt32(strs[1]), Color.FromName(strs[2]), width, height);
|
|||
|
}
|
|||
|
if (strs.Length == 6)
|
|||
|
{
|
|||
|
return new DrawningAirFighter(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 DrawningAirplane drawningAirplane, char separatorForObject)
|
|||
|
{
|
|||
|
var airplane = drawningAirplane.EntityAirplane;
|
|||
|
if (airplane == null)
|
|||
|
{
|
|||
|
return string.Empty;
|
|||
|
}
|
|||
|
var str = $"{airplane.Speed}{separatorForObject}{airplane.Weight}{separatorForObject}{airplane.BodyColor.Name}";
|
|||
|
if (airplane is not EntityAirFighter airfighter)
|
|||
|
{
|
|||
|
return str;
|
|||
|
}
|
|||
|
return
|
|||
|
$"{str}{separatorForObject}{airfighter.AdditionalColor.Name}{separatorForObject}{airfighter.Wing}{separatorForObject}{airfighter.Racket}";
|
|||
|
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|