2024-06-12 19:21:59 +04:00
|
|
|
|
namespace ProjectCruiser.Entities;
|
2024-06-12 14:29:35 +04:00
|
|
|
|
|
|
|
|
|
public class EntityBase
|
|
|
|
|
{
|
|
|
|
|
// свойства
|
|
|
|
|
public int Speed { get; private set; } // скорость
|
|
|
|
|
public double Weight { get; private set; } // вес
|
|
|
|
|
public Color MainColor { get; private set; } // основной цвет
|
2024-06-12 19:21:59 +04:00
|
|
|
|
|
2024-06-15 09:53:32 +04:00
|
|
|
|
public void setMainColor(Color clr)
|
|
|
|
|
{
|
|
|
|
|
MainColor = clr;
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-12 16:25:55 +04:00
|
|
|
|
// public bool Deckhouse { get; private set; } // салон на верхней палубе
|
2024-06-12 14:29:35 +04:00
|
|
|
|
public double Step => Speed * 100 / Weight;
|
|
|
|
|
|
|
|
|
|
public int[] values = { 0, 0, 0 };
|
|
|
|
|
|
2024-06-12 19:21:59 +04:00
|
|
|
|
public EntityBase(int speed, double weight, Color mainc)
|
|
|
|
|
// (bool) deckhouse -> default TRUE now
|
2024-06-12 14:29:35 +04:00
|
|
|
|
{
|
|
|
|
|
Random rn = new();
|
|
|
|
|
Speed = speed;
|
|
|
|
|
Weight = weight;
|
|
|
|
|
MainColor = mainc;
|
|
|
|
|
values[0] = rn.Next(1, 4);
|
|
|
|
|
values[1] = rn.Next(5, 10);
|
|
|
|
|
values[2] = rn.Next(1, 3);
|
|
|
|
|
}
|
2024-06-15 13:28:42 +04:00
|
|
|
|
|
|
|
|
|
// Получение массива строк со значениями свойств
|
|
|
|
|
// объекта : тип (название класса), скорость, вес, осн. цвет [*]
|
|
|
|
|
public virtual string[] GetStringRepresentation()
|
|
|
|
|
{
|
|
|
|
|
return new[] { nameof(EntityBase), Speed.ToString(),
|
|
|
|
|
Weight.ToString(), MainColor.Name };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// decoding string to object
|
|
|
|
|
public static EntityBase? CreateEntity(string[] parameters)
|
|
|
|
|
{
|
|
|
|
|
if (parameters.Length != 4 || parameters.Length == 0 ||
|
|
|
|
|
parameters[0] != "EntityBase") return null;
|
|
|
|
|
|
|
|
|
|
return new EntityBase(Convert.ToInt32(parameters[1]),
|
|
|
|
|
Convert.ToDouble(parameters[2]), Color.FromName(parameters[3]));
|
|
|
|
|
}
|
2024-06-12 14:29:35 +04:00
|
|
|
|
}
|