using System; using System.Collections.Generic; namespace MCTGLib { /// /// A Recipe is a description of step and maybe some techniques, with an ingredient list to make a meal.
/// It is instantiated with a new unique id, where the first number is 1. ///
public class Recipe : BaseItem { #region Private Attributes private const int CAT_ITEM = 1; private static uint _idCreator = 0; // stand for the creation of a new id. It is incremented each time a new Recipe is instantiated. private string title = ""; #endregion #region Public Properties /// /// The title of the recipe. /// public string Title { get => title; set { title = value; if (string.IsNullOrEmpty(title)) title = $"Recipe n{this.Id}"; } } /// /// All the details about the preparation of the meal. /// public string Preparation { get; set; } #endregion #region Constructors public Recipe(string title="", string preparation="") : base(ComputeId(), "A recipe.") { Title = title; Preparation = preparation; } #endregion #region Private Methods /// /// Processi the unique identificator of an Item. The identificator is calculated to put the number representing /// the type of item before the number of its number in its type. /// private static uint ComputeId() { uint dec = 1; while ((_idCreator / (Math.Pow(10, dec)) >= 1)) dec++; uint id = (CAT_ITEM * (uint)(Math.Pow(10, dec))) + _idCreator++; Console.WriteLine("[recipe] new computed id: {0}", id); return id; } #endregion #region Public Methods public override string ToString() { return $"[ Class -Recipe- ]\n\n" + $"\t.Id - {Id}\n" + $"\t.Description - {Description}\n" + $"______\n\n"; } #endregion } }