コード例 #1
0
ファイル: PillContainer.cs プロジェクト: isse-augsburg/ssharp
		/// <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++;
		}
コード例 #2
0
ファイル: Recipe.cs プロジェクト: isse-augsburg/ssharp
		/// <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();
		}
コード例 #3
0
			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);
			}
コード例 #4
0
		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;
		}