예제 #1
0
        public bool StartGame(List <Recipe> recipes, List <int> indexes, string User)
        {
            int           count       = 0;
            double        allPoints   = 0;
            List <int>    DoneRecipes = new List <int>();
            List <string> Results     = new List <string>();
            int           test        = recipes.Count;

            if (test > 10)
            {
                test = 10;
            }
            for (int i = 0; i < test; i++)
            {
                Random rand     = new Random();
                int    index    = rand.Next(0, indexes.Count);
                Random TestType = new Random();
                int    Type     = TestType.Next(1, 4);
                if (Type == 1)
                {
                    int result = CreateTestIngred(recipes[indexes[index]]);
                    if (result == -1)
                    {
                        return(false);
                    }
                    if (result == -2)
                    {
                        break;
                    }
                    if (result == 0)
                    {
                        count     += recipes[indexes[index]].Points;
                        allPoints += recipes[indexes[index]].Points;
                        DoneRecipes.Add(recipes[indexes[index]].Id);
                        Results.Add(recipes[indexes[index]].Name + "," + recipes[indexes[index]].Points.ToString());
                    }
                    if (result == 2)
                    {
                        count     += recipes[indexes[index]].Points / 3;
                        allPoints += recipes[indexes[index]].Points;
                        DoneRecipes.Add(recipes[indexes[index]].Id);
                        Results.Add(recipes[indexes[index]].Name + "," + (recipes[indexes[index]].Points / 3).ToString());
                    }
                    if (result == 1)
                    {
                        count     += recipes[indexes[index]].Points * 2 / 3;
                        allPoints += recipes[indexes[index]].Points;
                        DoneRecipes.Add(recipes[indexes[index]].Id);
                        Results.Add(recipes[indexes[index]].Name + "," + (recipes[indexes[index]].Points * 2 / 3).ToString());
                    }
                    if (result == 3)
                    {
                        allPoints += recipes[indexes[index]].Points;
                        Results.Add(recipes[indexes[index]].Name + ",0");
                    }
                }
                if (Type == 2)
                {
                    int result = CreateTestName(recipes, indexes[index]);
                    if (result == -1)
                    {
                        return(false);
                    }
                    if (result == -2)
                    {
                        break;
                    }
                    if (result == 1)
                    {
                        count     += recipes[indexes[index]].Points;
                        allPoints += recipes[indexes[index]].Points;
                        DoneRecipes.Add(recipes[indexes[index]].Id);
                        Results.Add(recipes[indexes[index]].Name + "," + recipes[indexes[index]].Points.ToString());
                    }
                    if (result == 0)
                    {
                        allPoints += recipes[indexes[index]].Points;
                        Results.Add(recipes[indexes[index]].Name + ",0");
                    }
                }
                if (Type == 3)
                {
                    int result = CreateTestRecipe(recipes[indexes[index]]);
                    if (result == -1)
                    {
                        return(false);
                    }
                    if (result == -2)
                    {
                        break;
                    }
                    if (result == 1)
                    {
                        count     += recipes[indexes[index]].Points;
                        allPoints += recipes[indexes[index]].Points;
                        DoneRecipes.Add(recipes[indexes[index]].Id);
                        Results.Add(recipes[indexes[index]].Name + "," + recipes[indexes[index]].Points.ToString());
                    }
                    if (result == 0)
                    {
                        allPoints += recipes[indexes[index]].Points;
                        Results.Add(recipes[indexes[index]].Name + ",0");
                    }
                }
                indexes.RemoveAt(index);
            }
            ResultForm  rform       = new ResultForm(Results, allPoints, Volume);
            UserManager userManager = new UserManager();

            userManager.ChangeUserPoints(User, count, DoneRecipes);
            if (rform.ShowDialog() == DialogResult.OK)
            {
                rform.Close();
                return(true);
            }
            else
            {
                return(false);
            }
        }