Добавлен класс расширение ExtensionDrawingPlane

This commit is contained in:
Никита Потапов 2023-11-20 17:36:21 +04:00
parent cd74aa1932
commit 87c5a98333
2 changed files with 57 additions and 0 deletions

View File

@ -0,0 +1,53 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectStormtrooper
{
public static class ExtensionDrawingPlane
{
/// <summary>
/// Создание объекта из строки
/// </summary>
public static DrawingPlane? CreateDrawingPlane(this string info, char separatorForObject, int width, int height)
{
string[] strs = info.Split(separatorForObject);
if (strs.Length == 3)
{
return new DrawingPlane(Convert.ToInt32(strs[0]), Convert.ToInt32(strs[1]), Color.FromName(strs[2]), width, height);
}
if (strs.Length == 7)
{
return new DrawingStormtrooper(
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;
}
/// <summary>
/// Получение данных для сохранения в файл
/// </summary>
public static string GetDataForSave(this DrawingPlane 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 EntityStormtrooper stormtrooper)
{
return str;
}
return $"{str}{separatorForObject}{stormtrooper.AdditionalColor.Name}{separatorForObject}{stormtrooper.Rockets}{separatorForObject}{stormtrooper.Bombs}";
}
}
}

View File

@ -138,5 +138,9 @@ namespace ProjectStormtrooper
i++;
}
}
/// <summary>
/// Получение объектов коллекции
/// </summary>
public IEnumerable<T?> GetPlanes => _collection.GetPlanes();
}
}