This commit is contained in:
VictoriaPresnyakova 2022-11-20 20:46:00 +04:00
parent ca7d484111
commit ed9281b1a9
9 changed files with 99 additions and 5 deletions

View File

@ -10,6 +10,6 @@ namespace Catamaran
/// <summary>
/// Делегат для передачи объекта-лодки
/// </summary>
/// <param name="car"></param>
/// <param name="Boat"></param>
public delegate void BoatDelegate(DrawingBoat boat);
}

View File

@ -54,6 +54,7 @@
<Compile Include="Direction.cs" />
<Compile Include="DrawingBoat.cs" />
<Compile Include="EntityBoat.cs" />
<Compile Include="ExtentionBoat.cs" />
<Compile Include="FormBoat.cs">
<SubType>Form</SubType>
</Compile>

View File

@ -127,8 +127,8 @@ namespace Catamaran
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес автомобиля</param>
/// <param name="bodyColor">Цвет кузова</param>
/// <param name="carWidth">Ширина отрисовки автомобиля</param>
/// <param name="carHeight">Высота отрисовки автомобиля</param>
/// <param name="BoatWidth">Ширина отрисовки автомобиля</param>
/// <param name="BoatHeight">Высота отрисовки автомобиля</param>
protected DrawingBoat(int speed, float weight, Color bodyColor, int
catamaranWidth, int catamaranHeight) :
this(speed, weight, bodyColor)

View File

@ -33,6 +33,8 @@ namespace Catamaran
_catamaran.DrawTransport(g);
}
public string GetInfo() => _catamaran?.GetDataForSave();
public static IDrawingObject Create(string data) => new DrawingObjectBoat(data.CreateDrawingBoat());
}
}

View File

@ -0,0 +1,57 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Catamaran
{
/// <summary>
/// Расширение для класса DrawingBoat
/// </summary>
internal static class ExtentionBoat
{
/// <summary>
/// Разделитель для записи информации по объекту в файл
/// </summary>
private static readonly char _separatorForObject = ':';
/// <summary>
/// Создание объекта из строки
/// </summary>
/// <param name="info"></param>
/// <returns></returns>
public static DrawingBoat CreateDrawingBoat(this string info)
{
string[] strs = info.Split(_separatorForObject);
if (strs.Length == 3)
{
return new DrawingBoat(Convert.ToInt32(strs[0]),
Convert.ToInt32(strs[1]), Color.FromName(strs[2]));
}
if (strs.Length == 6)
{
return new DrawingCatamaran(Convert.ToInt32(strs[0]),
Convert.ToInt32(strs[1]), Color.FromName(strs[2]),
Color.FromName(strs[3]), Convert.ToBoolean(strs[4]),
Convert.ToBoolean(strs[5]));
}
return null;
}
/// <summary>
/// Получение данных для сохранения в файл
/// </summary>
/// <param name="DrawingBoat"></param>
/// <returns></returns>
public static string GetDataForSave(this DrawingBoat DrawingBoat)
{
var Boat = DrawingBoat.Catamaran;
var str = $"{Boat.Speed}{_separatorForObject}{Boat.Weight}{_separatorForObject}{Boat.BodyColor.Name}";
if (!(Boat is EntityCatamaran Catamaran))
{
return str;
}
return $"{str}{_separatorForObject}{Catamaran.DopColor.Name}{_separatorForObject}{Catamaran.Floats}{_separatorForObject}{Catamaran.Sail}";
}
}
}

View File

@ -182,7 +182,7 @@ namespace Catamaran
}
DrawCatamaran();
// TODO Call method from object _boat if _boat is DrawningSportCar and set dop color
// TODO Call method from object _boat if _boat is DrawingCatamaran and set dop color
}
/// <summary>
/// Добавление машины

View File

@ -214,7 +214,7 @@ namespace Catamaran
{
var formBoatConfig = new FormBoatConfig();
formBoatConfig.AddEvent(new Action<DrawingBoat>(AddBoat));
// TODO Call method AddEvent from formCarConfig
// TODO Call method AddEvent from formBoatConfig
formBoatConfig.Show();
}

View File

@ -38,5 +38,12 @@ namespace Catamaran
(float Left, float Right, float Top, float Bottom)
GetCurrentPosition();
/// <summary>
/// Получение информации по объекту
/// </summary>
/// <returns></returns>
string GetInfo();
}
}

View File

@ -182,5 +182,32 @@ namespace Catamaran
_setBoats[i]?.DrawingObject(g);
}
}
/// <summary>
/// Получение данных в виде строки
/// </summary>
/// <param name="sep"></param>
/// <returns></returns>
public string GetData(char separatorType, char separatorData)
{
string data = $"{_map.GetType().Name}{separatorType}";
foreach (var Boat in _setBoats.GetBoats())
{
data += $"{Boat.GetInfo()}{separatorData}";
}
return data;
}
/// <summary>
/// Загрузка списка из массива строк
/// </summary>
/// <param name="records"></param>
public void LoadData(string[] records)
{
foreach (var rec in records)
{
_setBoats.Insert(DrawingObjectBoat.Create(rec) as T);
}
}
}
}