コード例 #1
0
    // Gets the drink recipes from a CSV, stores in recipes List
    void GetRecipes()
    {
        // For each line in the CSV, set the drink name and the ingredients
        List <List <string> > csvResults = ReadCSV(recipeFile);

        for (int i = 0; i < csvResults.Count; i++)
        {
            Drink currentDrink = new Drink();
            bool  hasTopping   = false;
            for (int j = 0; j < csvResults[i].Count; j++)
            {
                if (j == 0)
                {
                    // Recipe name
                    currentDrink.name = csvResults[i][j];
                }
                else
                {
                    // Ingredient
                    if (!currentDrink.AddIngredient(csvResults[i][j]) && csvResults[i][j].Contains(";"))
                    {
                        string[] toppingManip = csvResults[i][j].Split(';');
                        currentDrink.AddIngredient(toppingManip[0]);
                        currentDrink.BlendToppings();
                        currentDrink.AddIngredient(toppingManip[1]);
                        hasTopping = true;
                    }
                }
            }

            if (!hasTopping)
            {
                currentDrink.BlendToppings();
            }
            recipes.Add(currentDrink);
        }
        recipes.Sort(new Drink.DrinkComp());
    }