This commit is contained in:
Daniya_Youdakova 2022-12-24 22:48:42 +04:00
parent 6d56d78be5
commit 9d91262f3c
5 changed files with 58 additions and 8 deletions

View File

@ -14,14 +14,6 @@ dopColor, bool flightDeck, bool hangarDeck, bool route) :
{ {
AircraftCarrier = new EntityModernAircraftCarrier(speed, weight, bodyColor, dopColor, flightDeck, hangarDeck, route); AircraftCarrier = new EntityModernAircraftCarrier(speed, weight, bodyColor, dopColor, flightDeck, hangarDeck, route);
} }
public void ReturnColor(Color returnColor)
{
if (AircraftCarrier is not EntityModernAircraftCarrier modernAircraftCarrier)
{
return;
}
modernAircraftCarrier.DopColor = returnColor;
}
public override void DrawTransport(Graphics g) public override void DrawTransport(Graphics g)
{ {
if (AircraftCarrier is not EntityModernAircraftCarrier modernAircraftCarrier) if (AircraftCarrier is not EntityModernAircraftCarrier modernAircraftCarrier)

View File

@ -30,5 +30,8 @@ namespace AircraftCarrier
{ {
_aircraftcarrier.DrawTransport(g); _aircraftcarrier.DrawTransport(g);
} }
public string GetInfo() => _aircraftcarrier?.AircraftCarrier.ToString();
public static IDrawningObject Create(string data) => new DrawningObjectAircraftCarrier(data.CreateDrawningAircraftCarrier());
} }
} }

View File

@ -8,6 +8,7 @@ namespace AircraftCarrier
{ {
public class EntityAircraftCarrier public class EntityAircraftCarrier
{ {
private static readonly char _separatorForObject = ':';
public int Speed { get; private set; } public int Speed { get; private set; }
public float Weight { get; private set; } public float Weight { get; private set; }
public Color BodyColor { get; set; } public Color BodyColor { get; set; }
@ -19,5 +20,10 @@ namespace AircraftCarrier
Weight = weight <= 0 ? rnd.Next(40, 70) : weight; Weight = weight <= 0 ? rnd.Next(40, 70) : weight;
BodyColor = bodyColor; BodyColor = bodyColor;
} }
public override string ToString()
{
var str = $"{Speed}{_separatorForObject}{Weight}{_separatorForObject}{BodyColor.Name}";
return str;
}
} }
} }

View File

@ -4,11 +4,13 @@ using System.Linq;
using System.Net.NetworkInformation; using System.Net.NetworkInformation;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using static System.Reflection.Metadata.BlobBuilder;
namespace AircraftCarrier namespace AircraftCarrier
{ {
internal class EntityModernAircraftCarrier : EntityAircraftCarrier internal class EntityModernAircraftCarrier : EntityAircraftCarrier
{ {
private static readonly char _separatorForObject = ':';
public Color DopColor { get; set; } public Color DopColor { get; set; }
public bool FlightDeck { get; private set; } public bool FlightDeck { get; private set; }
public bool HangarDeck { get; private set; } public bool HangarDeck { get; private set; }
@ -20,5 +22,10 @@ namespace AircraftCarrier
HangarDeck = hangarDeck; HangarDeck = hangarDeck;
Route = route; Route = route;
} }
public override string ToString()
{
var str = base.ToString();
return $"{str}{_separatorForObject}{DopColor.Name}{_separatorForObject}{FlightDeck}{_separatorForObject}{HangarDeck}{_separatorForObject}{Route}";
}
} }
} }

View File

@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AircraftCarrier
{
internal static class ExtentionAircraftCarrier
{
private static readonly char _separatorForObject = ':';
public static DrawningAircraftCarrier CreateDrawningAircraftCarrier(this string info)
{
string[] strs = info.Split(_separatorForObject);
if (strs.Length == 3)
{
return new DrawningAircraftCarrier(Convert.ToInt32(strs[0]),
Convert.ToInt32(strs[1]), Color.FromName(strs[2]));
}
if (strs.Length == 7)
{
return new DrawningModernAircraftCarrier(Convert.ToInt32(strs[0]),
Convert.ToInt32(strs[1]), Color.FromName(strs[2]),
Color.FromName(strs[3]), Convert.ToBoolean(strs[4]),
Convert.ToBoolean(strs[5]), Convert.ToBoolean(strs[6]));
}
return null;
}
public static string GetDataForSave(this DrawningAircraftCarrier drawningAircraftCarrier)
{
var aircraftcarrier = drawningAircraftCarrier.AircraftCarrier;
var str =
$"{aircraftcarrier.Speed}{_separatorForObject}{aircraftcarrier.Weight}{_separatorForObject}{aircraftcarrier.BodyColor.Name}";
if (aircraftcarrier is not EntityModernAircraftCarrier modernAircraftCarrier)
{
return str;
}
return
$"{str}{_separatorForObject}{modernAircraftCarrier.DopColor.Name}{_separatorForObject}{modernAircraftCarrier.FlightDeck}{_separatorForObject}{modernAircraftCarrier.HangarDeck}{_separatorForObject}{modernAircraftCarrier.Route}";
}
}
}