Ejemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e) //chooses the dishes randomly
        {
            //We still need to choose how to display the info, datagrid, or table, or something else
            //I only went with a 2D array, so it's easy to see for now
            Food[,] menu = new Food[7,3];
            List<Food> cache = new List<Food>(); // for the dishes that have already been chosen


            for (int i = 0; i < menu.GetLength(0); i++) //fills up each day
            {
                menu[i, 0] = ChooseDish(menu, cache, soupList);
                menu[i, 1] = ChooseDish(menu, cache, mainDishList);
                menu[i, 2] = ChooseDish(menu, cache, dessertList);
            }
        }
Ejemplo n.º 2
0
        static Food ChooseDish(Food[,] menu,List<Food> cache, List<Food> foodList) //returns 
        {
            Food result = new Food();
            Random rng = new Random();

            for (; ; )
            {
                Food temp = foodList[rng.Next(0,foodList.Count-1)];
                if (!cache.Contains(temp)) //checks if the food has been already chosen
                {
                    result = temp;
                    cache.Add(temp);
                    break;
                }
            }

            return result;
        }