PIBD-14_Khalikova.A.R_Storm.../ProjectStormtrooper/Entities/EntityStormtrooper.cs

69 lines
2.4 KiB
C#
Raw 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 ProjectStormtrooper.Entities;
/// <summary>
/// Класс-сущность "Штурмовик"
/// </summary>
public class EntityStormtrooper: EntityStormtrooperBase
{
public Color AdditionalColor { get; private set; }
public void SetAdditionalColor(Color additionalColor)
{
AdditionalColor = additionalColor;
}
/// <summary>
/// Признак (опция) наличия ракет
/// </summary>
public bool Rockets { get; private set; }
/// <summary>
/// Признак (опция) наличия бомб
/// </summary>
public bool Bombs { get; private set; }
/// <summary>
/// Инициализация полей объекта-класса штурмовик
/// </summary>
/// <param name="speed">Скорость</param>
/// <param name="weight">Вес </param>
/// <param name="bodyColor">Основной цвет</param>
/// <param name="additionalColor">Дополнительный цвет</param>
/// <param name="rockets">Признак наличия ракет</param>
/// <param name="bombs">Признак наличия бомб</param>
public EntityStormtrooper(int speed, double weight, Color bodyColor, Color additionalColor, bool rockets, bool bombs):base(speed, weight, bodyColor)
{
AdditionalColor = additionalColor;
Rockets = rockets;
Bombs = bombs;
}
/// <summary>
/// Получение строк со значениями свойств объекта класса-сущности
/// </summary>
/// <returns></returns>
public override string[] GetStringRepresentation()
{
return new[] { nameof(EntityStormtrooper), Speed.ToString(), Weight.ToString(), BodyColor.Name, AdditionalColor.Name, Bombs.ToString(), Rockets.ToString() };
}
/// <summary>
/// Создание объекта из массива строк
/// </summary>
/// <param name="strs"></param>
/// <returns></returns>
public static EntityStormtrooper? CreateEntityStormtrooper(string[] strs)
{
if (strs.Length != 7 || strs[0] != nameof(EntityStormtrooper))
{
return null;
}
return new EntityStormtrooper(Convert.ToInt32(strs[1]), Convert.ToDouble(strs[2]), Color.FromName(strs[3]), Color.FromName(strs[4]), Convert.ToBoolean(strs[5]), Convert.ToBoolean(strs[6]));
}
}