/// <summary> /// Adds an ingredient to the container. /// </summary> /// <param name="ingredient"></param> public void AddIngredient(Ingredient ingredient) { if (_statePrefixLength >= Recipe.RequiredCapabilities.Length) throw new InvalidOperationException("PillContainer is already fully processed."); if (!ingredient.Equals(Recipe.RequiredCapabilities[_statePrefixLength])) throw new InvalidOperationException("Added the wrong ingredient to PillContainer."); _statePrefixLength++; }
/// <summary> /// Creates a new recipe with the specified sequence of ingredients. /// </summary> /// <param name="ingredients">The sequence of ingredients to add to the containers.</param> /// <param name="amount">The number of containers to produce for this recipe.</param> public Recipe(Ingredient[] ingredients, uint amount) { _activeContainers = new List<PillContainer>((int)amount); Amount = amount; RequiredCapabilities = new Capability[] { new ProduceCapability() } .Concat(ingredients) .Concat(new[] { new ConsumeCapability() }) .ToArray(); }
public virtual void Dispense(PillContainer container, Ingredient ingredient) { if (ingredient.Type != IngredientType) throw new InvalidOperationException("Incorrect ingredient requested"); if (Amount < ingredient.Amount) throw new InvalidOperationException($"Insufficient amount available of ingredient {ingredient.Type}"); Amount -= ingredient.Amount; container.AddIngredient(ingredient); }
private Ingredient ReadIngredient(string input, ref int currentPosition) { ReadSpace(input, ref currentPosition); string typeName = ReadUntil(input, ref currentPosition, '('); currentPosition++; string amount = ReadUntil(input, ref currentPosition, ')'); currentPosition++; var type = (IngredientType)Enum.Parse(typeof(IngredientType), typeName + "Particulate"); var ingredient = new Ingredient(type, uint.Parse(amount)); ReadSpace(input, ref currentPosition); return ingredient; }