PIbd_23_Kislitsa_E.D_AirFig.../AirFighter/ExtentionDrawningAirplane.cs

56 lines
1.8 KiB
C#
Raw Normal View History

2023-12-08 22:44:38 +04:00
using Microsoft.VisualBasic.Logging;
using System;
2023-11-24 22:30:27 +04:00
using System.Collections.Generic;
using System.Linq;
2023-12-08 22:44:38 +04:00
using System.ComponentModel;
2023-11-24 22:30:27 +04:00
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}";
}
}
}