public VendingMachine(Beverage[] menu) { Menu = new ObservableCollection <Beverage>(menu); Stock = new IngredientsCollction(); Money = default; //load the stock with empty ingredients LoadAllStockItems(); }
//prepare to beverage based on the data known and by overrides in the derived class internal string Prepare(IngredientsCollction stock) { string res = $"Making: {Name}\n{AddIngredients(stock)}\n{Stir()}"; //reset sugar Recipe.ResetAmount(IngredientsEnum.Sugar); return(res); }
protected Beverage(string name, string image, decimal price) { Name = name; Image = image; Price = price; Recipe = new IngredientsCollction { { IngredientsEnum.Sugar, 0 } }; }
//check if the collection contains the parameter collection internal bool CanMake(IngredientsCollction recipe, out KeyValuePair <IngredientsEnum, int> missingIngredinet) { foreach (var ingredient in recipe._inerCollection) { //check if available in stock if (ingredient.Value > _inerCollection[ingredient.Key]) { missingIngredinet = new KeyValuePair <IngredientsEnum, int> (ingredient.Key, ingredient.Value - _inerCollection[ingredient.Key]); return(false); } } return(true); }
//adding all of the ingredients in the Recipe private string AddIngredients(IngredientsCollction stock) { _sb = new StringBuilder("Adding:\n"); foreach (var ingredient in Recipe) { if (ingredient.Value != 0) { //create the string _sb.AppendLine($"{ingredient.Value} {ingredient.Key}"); //use ingredient stock.UseIngredient(ingredient); } } return(_sb.ToString()); }