73 lines
2.0 KiB
C#
73 lines
2.0 KiB
C#
namespace ProjectElectroTrans.Entities;
|
||
|
||
/// <summary>
|
||
/// Класс-сущность "Поезд"
|
||
/// </summary>
|
||
public class EntityTrans
|
||
{
|
||
/// <summary>
|
||
/// Скорость
|
||
/// </summary>
|
||
public int Speed { get; private set; }
|
||
/// <summary>
|
||
/// Вес
|
||
/// </summary>
|
||
public double Weight { get; private set; }
|
||
/// <summary>
|
||
/// Основной цвет
|
||
/// </summary>
|
||
public Color BodyColor { get; private set; }
|
||
/// <summary>
|
||
/// Шаг перемещения автомобиля
|
||
/// </summary>
|
||
|
||
/// <summary>
|
||
/// Основной цвет
|
||
/// </summary>
|
||
/// <param name="color"></param>
|
||
public void setBodyColor(Color color)
|
||
{
|
||
BodyColor = color;
|
||
}
|
||
|
||
public double Step => Speed * 100 / Weight;
|
||
/// <summary>
|
||
/// Конструктор сущности
|
||
/// </summary>
|
||
/// <param name="speed">Скорость</param>
|
||
/// <param name="weight">Вес автомобиля</param>
|
||
/// <param name="bodyColor">Основной цвет</param>
|
||
public EntityTrans(int speed, double weight, Color bodyColor)
|
||
{
|
||
Speed = speed;
|
||
Weight = weight;
|
||
BodyColor = bodyColor;
|
||
}
|
||
|
||
/// <summary>
|
||
/// Получение строк со значениями свойств объекта класса-сущности
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public virtual string[] GetStringRepresentation()
|
||
{
|
||
return new[] { nameof(EntityTrans), Speed.ToString(),
|
||
Weight.ToString(), BodyColor.Name };
|
||
}
|
||
/// <summary>
|
||
/// Создание объекта из массива строк
|
||
/// </summary>
|
||
/// <param name="strs"></param>
|
||
/// <returns></returns>
|
||
public static EntityTrans? CreateEntityTrans(string[] strs)
|
||
{
|
||
if (strs.Length != 4 || strs[0] != nameof(EntityTrans))
|
||
{
|
||
return null;
|
||
}
|
||
return new EntityTrans(Convert.ToInt32(strs[1]),
|
||
Convert.ToDouble(strs[2]), Color.FromName(strs[3]));
|
||
}
|
||
|
||
|
||
}
|