PIBD14-BOYKO-M.S.SuperEasyS.../ProjectElectroTrans/Entities/EntityTrans.cs
2024-04-10 21:03:23 +04:00

73 lines
2.0 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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]));
}
}