예제 #1
0
 public Kitchen(Dictionary<String, Recipe> recipes, Recipe mainrecipe,
     Container[] mbowls, Container[] bdishes)
 {
     this.recipes = recipes;
     //start with at least 1 mixing bowl.
     int maxbowl = 0, maxdish = -1;
     recipe = mainrecipe;
     foreach (Method m in recipe.getMethods())
     {
         if (m.bakingdish != null && m.bakingdish > maxdish)
             maxdish = m.bakingdish;
         if (m.mixingbowl != null && m.mixingbowl > maxbowl)
             maxbowl = m.mixingbowl;
     }
     mixingbowls = new Container[mbowls == null ? maxbowl + 1 : Math.Max(maxbowl + 1, mbowls.Length)];
     bakingdishes = new Container[bdishes == null ? maxdish + 1 : Math.Max(maxdish + 1, bdishes.Length)];
     for (int i = 0; i < mixingbowls.Length; i++)
         mixingbowls[i] = new Container();
     for (int i = 0; i < bakingdishes.Length; i++)
         bakingdishes[i] = new Container();
     if (mbowls != null)
     {
         for (int i = 0; i < mbowls.Length; i++)
         {
             mixingbowls[i] = new Container(mbowls[i]);
         }
     }
     if (bdishes != null)
     {
         for (int i = 0; i < bdishes.Length; i++)
         {
             bakingdishes[i] = new Container(bdishes[i]);
         }
     }
 }
예제 #2
0
        public Chef(String filename)
        {
            recipes = new Dictionary<string, Recipe>();
            //System.out.print("Reading recipe(s) from '"+filename+"'.. ");
            file = File.Open(filename, FileMode.OpenOrCreate);
            scan = new StreamReader(file);
            String lines = scan.ReadToEnd();
            String[] linees = Regex.Split(lines, "\n\n");
            int progress = 0;
            Recipe r = null;
            while (progress < linees.Length)
            {
                String line = linees[progress];
                if (line.StartsWith("Ingredients"))
                {
                    if (progress > 3)
                        throw new ChefException(global::BesiegeScriptingMod.Chef.ChefException.STRUCTURAL, "Read unexpected " + progressToExpected(2) + ". Expecting " + progressToExpected(progress));
                    progress = 3;
                    r.setIngredients(line);
                }
                else if (line.StartsWith("Cooking time"))
                {
                    if (progress > 4)
                        throw new ChefException(global::BesiegeScriptingMod.Chef.ChefException.STRUCTURAL,
                            "Read unexpected " + progressToExpected(3) + ". Expecting " + progressToExpected(progress));
                    progress = 4;
                    r.setCookingTime(line);
                }
                else if (line.StartsWith("Pre-heat oven"))
                {
                    if (progress > 5)
                        throw new ChefException(global::BesiegeScriptingMod.Chef.ChefException.STRUCTURAL,
                            "Read unexpected " + progressToExpected(4) + ". Expecting " + progressToExpected(progress));
                    progress = 5;
                    r.setOvenTemp(line);
                }
                else if (line.StartsWith("Method"))
                {
                    if (progress > 5)
                        throw new ChefException(global::BesiegeScriptingMod.Chef.ChefException.STRUCTURAL,
                            "Read unexpected " + progressToExpected(5) + ". Expecting " + progressToExpected(progress));
                    progress = 6;
                    r.setMethod(line);
                }
                else if (line.StartsWith("Serves"))
                {
                    if (progress != 6)
                        throw new ChefException(global::BesiegeScriptingMod.Chef.ChefException.STRUCTURAL,
                            "Read unexpected " + progressToExpected(6) + ". Expecting " + progressToExpected(progress));
                    progress = 0;
                    r.setServes(line);
                }
                else
                {
                    if (progress == 0 || progress >= 6)
                    {
                        r = new Recipe(line);
                        if (mainrecipe == null)
                            mainrecipe = r;
                        progress = 1;
                        recipes.Add(parseTitle(line), r);
                    }
                    else if (progress == 1)
                    {
                        progress = 2;
                        r.setComments(line);
                    }
                    else
                    {
                        throw new ChefException(global::BesiegeScriptingMod.Chef.ChefException.STRUCTURAL,
                            "Read unexpected comments/title. Expecting " + progressToExpected(progress) + " Hint:" +
                            structHint(progress));
                    }
                }
            }
            if (mainrecipe == null)
                throw new ChefException(global::BesiegeScriptingMod.Chef.ChefException.STRUCTURAL, "Recipe empty or title missing!");

            bake();
            //System.out.println("Done!");
        }