PIbd-14_Pruidze_I.K_Simple_.../ProjectCruiser/Entities/EntityBase.cs

50 lines
1.6 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 ProjectCruiser.Entities;
public class EntityBase
{
// свойства
public int Speed { get; private set; } // скорость
public double Weight { get; private set; } // вес
public Color MainColor { get; private set; } // основной цвет
public void setMainColor(Color clr)
{
MainColor = clr;
}
// public bool Deckhouse { get; private set; } // салон на верхней палубе
public double Step => Speed * 100 / Weight;
public int[] values = { 0, 0, 0 };
public EntityBase(int speed, double weight, Color mainc)
// (bool) deckhouse -> default TRUE now
{
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);
}
// Получение массива строк со значениями свойств
// объекта : тип (название класса), скорость, вес, осн. цвет [*]
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]));
}
}