2024-03-07 09:46:27 +04:00
|
|
|
|
namespace ProjectCruiser.Entities;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Класс-сущность "крейсер"
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class EntityCruiser
|
|
|
|
|
{
|
|
|
|
|
//свойства
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Скорость
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int Speed { get; private set; }
|
2024-05-13 12:59:51 +04:00
|
|
|
|
|
2024-03-07 09:46:27 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Вес
|
|
|
|
|
/// </summary>
|
|
|
|
|
public double Weight { get; private set; }
|
2024-05-13 12:59:51 +04:00
|
|
|
|
|
2024-03-07 09:46:27 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Основной цвет
|
|
|
|
|
/// </summary>
|
|
|
|
|
public Color BodyColor { get; private set; }
|
2024-05-13 12:59:51 +04:00
|
|
|
|
public void setBodyColor(Color color)
|
|
|
|
|
{
|
|
|
|
|
BodyColor = color;
|
|
|
|
|
}
|
2024-03-07 09:46:27 +04:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Шаг перемещения автомобиля
|
|
|
|
|
/// </summary>
|
|
|
|
|
public double Step => Speed * 100 / Weight;
|
2024-05-13 12:59:51 +04:00
|
|
|
|
|
2024-03-07 09:46:27 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Инициализация полей объекта-класса крейсера
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="speed">скорость</param>
|
|
|
|
|
/// <param name="weight">вес</param>
|
|
|
|
|
/// <param name="bodyColor">основной цвет</param>
|
|
|
|
|
public EntityCruiser(int speed, double weight, Color bodyColor)
|
|
|
|
|
{
|
|
|
|
|
Speed = speed;
|
|
|
|
|
Weight = weight;
|
|
|
|
|
BodyColor = bodyColor;
|
|
|
|
|
}
|
2024-05-13 12:59:51 +04:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Получение строк со значениями свойств объекта класса-сущности
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public virtual string[] GetStringRepresentation()
|
|
|
|
|
{
|
|
|
|
|
return new[] { nameof(EntityCruiser), Speed.ToString(), Weight.ToString(), BodyColor.Name };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Создание объекта из массива строк
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="strs"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static EntityCruiser? CreateEntityCruiser(string[] strs)
|
|
|
|
|
{
|
|
|
|
|
if (strs.Length != 4 || strs[0] != nameof(EntityCruiser))
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new EntityCruiser(Convert.ToInt32(strs[1]), Convert.ToDouble(strs[2]), Color.FromName(strs[3]));
|
|
|
|
|
}
|
2024-03-07 09:46:27 +04:00
|
|
|
|
}
|